View unanswered posts | View active topics It is currently Sun Apr 22, 2018 4:23 pm






Reply to topic  [ 1 post ] 
issues using multiple sensors-beginner 
Author Message
Rookie

Joined: Sat Nov 14, 2015 8:09 pm
Posts: 1
Post 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);

}


Sat Nov 14, 2015 8:26 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 1 post ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.