View unanswered posts | View active topics It is currently Thu Jul 31, 2014 11:48 pm






Reply to topic  [ 4 posts ] 
Why my NXT robot keeps turning around? 
Author Message
Rookie

Joined: Wed Oct 24, 2012 2:51 pm
Posts: 8
Post 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.


Wed Oct 24, 2012 3:08 pm
Profile
Site Admin
Site Admin

Joined: Thu May 24, 2012 12:15 pm
Posts: 558
Post 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.

_________________
Check out our Blog! And our Facebook page!
Need help? Take a look at our Wiki and our Forums.

I just met you,
And this is crazy,
But here's my code now,
So fix it, maybe?
~ Carly Rae Jepsen parody


Wed Oct 24, 2012 3:28 pm
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post 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.


Wed Oct 24, 2012 7:06 pm
Profile
Rookie

Joined: Wed Oct 24, 2012 2:51 pm
Posts: 8
Post 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!


Thu Oct 25, 2012 4:15 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 4 posts ] 

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.