hey this is umar here and i really needed some help because i have my exam tommorow. i was assigned to make a robot. ad to program it as some of may you know( i hope) the NXC language (i think its called that) to program the Mindstorms nxt brick. if some can help me i only have limited knowledge, i need to make this robot stay away from this color yellow and stay in black , i will be given a a small rink or arean painted black (as big as a air hockey table) and rest painted yellow. there will also be another robot that will try to catch my robot so i have to make my robot escape for about 90 secs. i have written some code if some of you can help that would be great.[description of my robot: its both sensors are on the front( light sensor facing ab to the ground and the distance one facing straight forwarf) the two motors are on the front wheels and one tire on the back. and here is my code so far.

#include "NXCDefs.h"

mutex moveMutex;
#define dist  60
#define extranear  10
int tries = 0;




inline void scan_front()
{
  
  SetSensorLowspeed(IN_1);
  



if (SensorUS(IN_1) > dist)
{

    OnFwd(OUT_AB, 75);
	tries = 0;
}	

if (SensorUS(IN_1) < dist){

Off(OUT_AB);
RotateMotor(OUT_A, 80, 300);
tries++;


}

if(SensorUS(IN_1) < extranear)

{
Off(OUT_AB);

RotateMotor(OUT_A, 80, 720);


}


if(tries >= 3 ){
Off(OUT_AB);
 OnFwd(OUT_AB, 75);
}




}






task main()
{
 

while (true){


scan_front();




}



}

*Update: the tries thing i did doesnt seem to work.

Recommended Answers

All 2 Replies

You have got a good assignment .Do not mix 2 operation , first code "stay away" from other robot and then try to avoid color , there may be situtation like robot cannot avoid color to stay away from the other robot.

can you guys help me with the coding a bit, im not asking the whole thing but can you make me the escape snipet and give me advice for the rest, if possible that would be great. thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.