Page 2 of 2

Re: Help with NQC code

Posted: 26 Feb 2013, 00:46
by tabbycatrobots
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.

Re: Help with NQC code

Posted: 26 Feb 2013, 02:13
by tabbycatrobots
Does the bumper sensor hit the obstacle before the light sensor crosses the intersection? Can you
change the design of the robot so this happens? E.g. put a long feeler out the front of the robot.
Or can you modify the test track, at the intersection so the black line that the robot is following
as it enters the intersection, is continuous, and has white on both sides, even at the intersection,
and the black line leading from the intersection is detached from the intersection? Just some
thoughts on what the light sensor might see, if the robot doesn't track exactly straight through
the intersection.

Re: Help with NQC code

Posted: 26 Feb 2013, 14:40
by hassenplug
aleynov wrote:Here's the best I can think of with what I want the robot to do.
code in words

Code: Select all

while the light sensor is at 39 or below, power motors A and C;
when it bumps the first obstacle and x == 0, rotate clockwise until light sensor is at 39 or below, back to powering motors A and C;
when it bumps the second obstacle and x == 1 (having already hit an obstacle making x == 1), rotate counter-clockwise until light sensor is at 39 or below, back to powering motors A and C;
when it bumps the third obstacle and x == 2 (hitting the last obstacle made x == 2), rotate counter-clockwise until light sensor is at 39 or below. back to powering motors A and C;
when it bumps the fourth obstacle and x == 3, rotate clockwise until light sensor is at 39 or below, and power motors A and C;
when it bumps the fifth obstacle and x == 4, rotate clockwise until light sensor is at 39 or below and power motors A and C;
when the light sensor reads the green pad, (i believe it read 36) terminate the program.
This is a very good start. As tabbycatrobots pointed out, you don't specify what to do if the robot is NOT on the line.

You don't need two tasks for this. In fact, you should be able to put it all in one loop, and start all of your lines above with IF...
while(true)
if on line, drive forward
if off line...
if bump & x=00...
if bump & x==1...
...
end loop

So, you just need to figure out what to do when the robot is off the line.

Steve

Re: Help with NQC code

Posted: 28 Feb 2013, 01:42
by aleynov
Thank you all so much. I figured out the code today and it works, only problem is it didn't stop on the green pad. I appreciate the help!