Re: Help with NQC code
Posted: 26 Feb 2013, 00:46
Is your robot following the center of the black line? If the motors are not perfectly matched, I think the robot
might go off the black line either to the left or right. I don't know which side the A and C motors are on, but it
looks like your code:
while(true)
{
if(SENSOR_2 > THRESHOLD)
{OnRev(OUT_C);
OnFwd(OUT_A);
until(SENSOR_2 <=THRESHOLD);}
will only return the robot to the black line if it goes off one side, unless I'm missing something. As mentioned in earlier
reply at the <http://connectankush.blogspot.com/2010/ ... lower.html>, I've also had success following the edge of the line,
rather than the center, although I use a slightly different algorithm. I use the smooth follow program at
http://www.nxtprograms.com/NXT2/line_fo ... steps.html, that I translated into NXC.
Unless you always run the robot in the same light conditions, try adding a little code at the start of the program
to have your robot scan over the black, white, green, etc. before starting down the black line. I get different results
in the evening, than during the day with natural light coming through the window. Another option is to build a light
shield around the light sensor.
A couple of other things to consider. When your robot hits an obstacle, is the sensor still over the black line,
or does the bump rotate the robot, so it is to the left or right of the black line? So maybe the sensor sees the
black when it starts turning or maybe not. How soon should it start looking for black when turning? Some techniques
I use when "teaching" a robot to turn or rotate over some pattern on the mat is 1. just hold the robot and move it
along manually, and observe what the light sensor is over. And 2. when trying a program, stand directly over the robot,
as it tries to execute a turn and again observe what the light sensor is over. And 3. get your head right down on the
floor or mat, and watch the red light dot as the robot turns. If you tried these, then you're a step ahead of me. If not,
maybe they'll help.
might go off the black line either to the left or right. I don't know which side the A and C motors are on, but it
looks like your code:
while(true)
{
if(SENSOR_2 > THRESHOLD)
{OnRev(OUT_C);
OnFwd(OUT_A);
until(SENSOR_2 <=THRESHOLD);}
will only return the robot to the black line if it goes off one side, unless I'm missing something. As mentioned in earlier
reply at the <http://connectankush.blogspot.com/2010/ ... lower.html>, I've also had success following the edge of the line,
rather than the center, although I use a slightly different algorithm. I use the smooth follow program at
http://www.nxtprograms.com/NXT2/line_fo ... steps.html, that I translated into NXC.
Unless you always run the robot in the same light conditions, try adding a little code at the start of the program
to have your robot scan over the black, white, green, etc. before starting down the black line. I get different results
in the evening, than during the day with natural light coming through the window. Another option is to build a light
shield around the light sensor.
A couple of other things to consider. When your robot hits an obstacle, is the sensor still over the black line,
or does the bump rotate the robot, so it is to the left or right of the black line? So maybe the sensor sees the
black when it starts turning or maybe not. How soon should it start looking for black when turning? Some techniques
I use when "teaching" a robot to turn or rotate over some pattern on the mat is 1. just hold the robot and move it
along manually, and observe what the light sensor is over. And 2. when trying a program, stand directly over the robot,
as it tries to execute a turn and again observe what the light sensor is over. And 3. get your head right down on the
floor or mat, and watch the red light dot as the robot turns. If you tried these, then you're a step ahead of me. If not,
maybe they'll help.