line follower with mutex and three sensors, obstacle avoid
Posted: 31 Mar 2014, 09:40
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);
}
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);
}