hello
i want to build a robot that,
when you clap
robot starts moving
if light sensor sees dark
turn right
if light sensor sees light
turn left
if ultra sonic sensor sees object
avoid object
when you clap
robot stops moving
this is my pseudo code(im still practicing this)
this is my full code so far, it kind of works
im using some examples from the nxc guide, which has helped but getting the robot to do what i want is tricky
any help would be great!!!
thanks
#define THRESHOLDLIGHT 40
#define THRESHOLDSOUND 40
#define MIC SENSOR_2
#define NEAR 15
mutex moveMutex;
task light_sensor()
{
}
task ultra_sonic()
{
OnFwd(OUT_AC, 70);
while(SensorUS(IN_1) > NEAR);
{
Acquire(moveMutex);
Off(OUT_AC);
OnRev(OUT_C,100);
Wait(800);
Release(moveMutex);
}
}
task on_off()
{
Off(OUT_AC);
until(MIC > THRESHOLDSOUND);
while(true)
{
if (Sensor(IN_3) > THRESHOLDLIGHT)
{
Acquire(moveMutex);
OnRev(OUT_C, 50);
Wait(100);
until(Sensor(IN_3) <=THRESHOLDLIGHT);
OnFwd(OUT_AC, 50);
Release(moveMutex);
}
}
until(MIC > THRESHOLDSOUND);
Off(OUT_AC);
Wait(300);
}
task main()
{
SetSensorLight(IN_3);
SetSensorSound(IN_2);
SetSensorLowspeed(IN_1);
Precedes(on_off, light_sensor, ultra_sonic);
}
line follower with mutex and three sensors, obstacle avoid
-
- Posts: 7
- Joined: 07 Mar 2014, 23:29
-
- Posts: 100
- Joined: 27 Dec 2010, 19:10
Re: line follower with mutex and three sensors, obstacle avoid
The proportional line follower at <http://www.nxtprograms.com/NXT2/line_fo ... steps.html> has
worked very well for me. This is an NXT-G program but I adapted it to NXC. My program is here
<https://sourceforge.net/apps/phpbb/mind ... ?f=4&t=680>, Kemmel - Combining Line
Following and Formula 1, with date 08 Apr 2011, 16:53. You may be able to get some ideas from it.
The zip file attached to that message has a description file and a readme file that give some details of the
program and mat. I used the ultrasonic sensor also, but only to slow down and stop if an object was in from
of the robot, not to try to avoid it. A suggestion: what is black or white or shades of gray vary with height
of sensor above mat, and ambient light in the room. I always have the robot rotate back and forth across
the black line several times to see what is the min, max, and mid of what it senses, before it starts
traveling along the line.
The book "Creating Cool Mindstorms NXT Robots' by Benedettelli is very good for NXC ideas. For his turtle
robot, he uses the sound sensor in what seems like what you want to do.
Also, I used a different set of instructions for managing tasks, that may give you some ideas.
Howard
worked very well for me. This is an NXT-G program but I adapted it to NXC. My program is here
<https://sourceforge.net/apps/phpbb/mind ... ?f=4&t=680>, Kemmel - Combining Line
Following and Formula 1, with date 08 Apr 2011, 16:53. You may be able to get some ideas from it.
The zip file attached to that message has a description file and a readme file that give some details of the
program and mat. I used the ultrasonic sensor also, but only to slow down and stop if an object was in from
of the robot, not to try to avoid it. A suggestion: what is black or white or shades of gray vary with height
of sensor above mat, and ambient light in the room. I always have the robot rotate back and forth across
the black line several times to see what is the min, max, and mid of what it senses, before it starts
traveling along the line.
The book "Creating Cool Mindstorms NXT Robots' by Benedettelli is very good for NXC ideas. For his turtle
robot, he uses the sound sensor in what seems like what you want to do.
Also, I used a different set of instructions for managing tasks, that may give you some ideas.
Howard
-
- Posts: 7
- Joined: 07 Mar 2014, 23:29
Re: line follower with mutex and three sensors, obstacle avoid
thanks for that howard!
i think that i will try to program the robot without using mutex. i have read about "nested" statements? "if()" and "else()". i managed to get the robot to move around the outside of a square it will go both ways around the square with little programming. this part will be the "else()", the "if()" will be the ultra sonic sensor checking for objects. if it doesnt find something it will go to "else()". if it does find something, it will reverse left and then carry on.
ill post what i manage to complete for others.
i think that i will try to program the robot without using mutex. i have read about "nested" statements? "if()" and "else()". i managed to get the robot to move around the outside of a square it will go both ways around the square with little programming. this part will be the "else()", the "if()" will be the ultra sonic sensor checking for objects. if it doesnt find something it will go to "else()". if it does find something, it will reverse left and then carry on.
ill post what i manage to complete for others.
Who is online
Users browsing this forum: No registered users and 5 guests