ROBOTC.net forumshttp://www.robotc.net/forums/ Why my NXT robot keeps turning around?http://www.robotc.net/forums/viewtopic.php?f=1&t=5027 Page 1 of 1

 Author: half_pirate [ Wed Oct 24, 2012 3:08 pm ] Post subject: Why my NXT robot keeps turning around? Hello.Newbie here.I'm coding my NXT robot to follow a black line. The race track consists of black line and white surface only fyi.I read in my darkest and lightest values first by moving the robot's light sensor onto dark then white surfaces. Then calculated for threshold. And when the robot goes it eventually goes off the black line? I tested it many times and normally the robot follows the line fine at first until halfway, it went off the line and just kept spinning around?What am I missing here?Please help.

 Author: JohnWatson [ Wed Oct 24, 2012 3:28 pm ] Post subject: Re: Why my NXT robot keeps turning around? Please post your code using the [code] blocks so we can help debug it; there are many possible reasons why the robot is spinning in circles, and if we can eliminate the code side of things it will go a long way to finding out what the issue it.

Author:  MHTS [ Wed Oct 24, 2012 7:06 pm ]
Post subject:  Re: Why my NXT robot keeps turning around?

 half_pirate wrote:Hello.Newbie here.I'm coding my NXT robot to follow a black line. The race track consists of black line and white surface only fyi.I read in my darkest and lightest values first by moving the robot's light sensor onto dark then white surfaces. Then calculated for threshold. And when the robot goes it eventually goes off the black line? I tested it many times and normally the robot follows the line fine at first until halfway, it went off the line and just kept spinning around?What am I missing here?Please help.

It is usually related to tuning. For a typical algorithm where your code would do one of the three things: go straight when on threshold, go left when below threshold, go right when above threshold, your code may look something like this:
 Code:while (true){    int lightReading = SensorValue[lightSensor];    if (lightReading < LIGHT_THRESHOLD)    {        motor[leftMotor] = BASE_SPEED - SPEED_DIFF;        motor[rightMotor] = BASE_SPEED + SPEED_DIFF;    }    else if (lightReading > LIGHT_THRESHOLD)    {        motor[leftMotor] = BASE_SPEED + SPEED_DIFF;        motor[rightMotor] = BASE_SPEED - SPEED_DIFF;    }    else    {        motor[leftMotor] = BASE_SPEED;        motor[rightMotor] = BASE_SPEED;    }    wait1Msec(100);}

It is important to tune BASE_SPEED and SPEED_DIFF. If BASE_SPEED is too fast, you will lose the line on a curve. SPEED_DIFF determines how fast you react when losing the line. Regardless, the above algorithm will zigzag around the edge of the line, not following it very smoothly. You may want to try PID control as you have posted on the other thread.

 Author: half_pirate [ Thu Oct 25, 2012 4:15 am ] Post subject: Re: Why my NXT robot keeps turning around? Thanks for replying. I can't really show my code as I'm having an assignment on this because if I do I'm worried that someone from my class would copy out my code and could end up plagiarism. Don't want to risk that.I'm gonna work on PID control now. Thanks!

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