ROBOTC.net forums
http://www.robotc.net/forums/

issues using multiple sensors-beginner
http://www.robotc.net/forums/viewtopic.php?f=15&t=12496
Page 1 of 1

Author:  roper710 [ Sat Nov 14, 2015 8:26 pm ]
Post subject:  issues using multiple sensors-beginner

Trying to write a line following code with obstacle avoidance, navigate circumference of obstacle, then refind line and continue on. I am a beginner. I am having problems with 2 sensors wanting to acquire control of motors. I included my attempt at writing the code. The original had 3 separate tasks, one for each sensor. I kept trying to tweak it and this is what it looks like now. It's for school project. Any help would be greatly appreciated!

#define EYE SENSOR_3
#define LEFT OUT_C
#define RIGHT OUT_A

#define TOO_DARK 45
#define TOO_BRIGHT 60
#define NEAR 10
#define TOO_NEAR 10
#define TOO_FAR 20
mutex moveMutex;



task linefollower()
{
SetSensorLight(IN_3);
Acquire(moveMutex);
OnFwd(OUT_AC, 60);
Release(moveMutex);
while(true)
{
NumOut(0, LCD_LINE1, EYE);
if(EYE <= TOO_DARK)
{
Acquire(moveMutex);
Off(LEFT);
OnFwd(RIGHT, 60);
Release(moveMutex);
}
else if(EYE >= TOO_BRIGHT)
{
Acquire(moveMutex);
Off(RIGHT);
OnFwd(LEFT, 60);
Release(moveMutex);
}
//checking on green
else if (EYE > TOO_DARK && EYE < TOO_BRIGHT)
{

Wait(80); // Wait a short time to determine if on green block
// as opposed to white line
if (EYE > TOO_DARK && EYE < TOO_BRIGHT)
{
Acquire(moveMutex);
Off(OUT_AC);
Release(moveMutex);
}
}


}
}

task checksensor()
{
SetSensorTouch(IN_4);
SetSensorLowspeed(IN_1);
while(true)
{
if(SENSOR_4==1)
{
Acquire(moveMutex);
OnRev(OUT_AC, 40);
Wait(250);
OnFwd(RIGHT, 50);
Wait(500);
Release(moveMutex);
}
if (SensorUS(IN_1)>=TOO_FAR)
{
Acquire(moveMutex);
OnFwd(LEFT, 75);
Wait(250);
Off(OUT_AC);
Release(moveMutex);
}
else if (SensorUS(IN_1)<=TOO_NEAR)
{
Acquire(moveMutex);
OnFwd(RIGHT, 75);
Wait(250);
Off(OUT_AC);
Release(moveMutex);
}
}
}

task main()
{
Precedes(linefollower, checksensor);

}

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/