View unanswered posts | View active topics It is currently Wed Jul 09, 2014 9:51 pm






Reply to topic  [ 11 posts ] 
How to make a robot turn on the spot? 
Author Message
Rookie

Joined: Fri Oct 28, 2011 11:50 am
Posts: 32
Post How to make a robot turn on the spot?
Hi,

I tried to control a robot to perform a 90 degree turn to left and right using the following codes:

void move(int left_power, int right_power, int duration)
{
motor[leftMotor] = left_power;
motor[rightMotor] = right_power;
wait1Msec(duration);
}

void turn(int degree, int power)
{
float duration = (float)(degree)/360.0*time_to_turn_full_round*1000.0;

if (duration < 0.0)
duration = -duration;

if (degree < 0)
move(power, -power, duration)
else
move(-power, power, duration);
}

void turnLeft()
{
turn(-90, 100);
}

void turnRight()
{
turn(90, 100);
}

It works perfectly for turning left - doing a 90 degrees left turn on the spot.

However, it executed a curve (thus moving away from its original spot) when turning right rather than turning right 90 degrees on the spot.

What could have gone wrong?
- coding is not correct?
- different motor power? (It was a brand new NXT 2.0)
- different amount of frictional contact?


Sun Nov 06, 2011 6:32 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: How to make a robot turn on the spot?
First are you sure you are turning in the right direction?
Code:
if (degree < 0)
  move(power, -power, duration)
else
  move(-power, power, duration);

If degree is negative, it should turn left. But from the code above, it seems turning right (left wheel forward and right wheel reverse).
Regardless, your algorithm is basically dead reckoning. Dead reckoning is not accurate. It can be affected by motors not being identical, the friction on different wheels, the battery power level etc. Refer to the following thread for detail discussion on this issue.
http://www.robotc.net/forums/viewtopic.php?f=52&t=3152


Sun Nov 06, 2011 3:26 pm
Profile
Rookie

Joined: Fri Oct 28, 2011 11:50 am
Posts: 32
Post Re: How to make a robot turn on the spot?
Hi,

I am just trying to program a simple sumo robot to do basic movement like going forward, backward, left/right turn, turning in certain degrees. Any pointers?

I am also interested to learn more about dead reckoning. How can I do it? Anybody has any available libraries or routines? What sensors are needed?

Thanks.

Regards.


Tue Nov 08, 2011 2:46 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: How to make a robot turn on the spot?
Here are some very good basic tutorials on what you want to do.
http://www.robotc.net/teachingmindstorm ... dindex.htm


Tue Nov 08, 2011 4:29 am
Profile
Rookie

Joined: Fri Oct 28, 2011 11:50 am
Posts: 32
Post Re: How to make a robot turn on the spot?
Thanks.

I have gone through most of the materials there. But I don't think the site have all the answers to my questions.


Tue Nov 08, 2011 5:45 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: How to make a robot turn on the spot?
What other answers are you seeking?


Tue Nov 08, 2011 5:47 am
Profile
Rookie

Joined: Fri Oct 28, 2011 11:50 am
Posts: 32
Post Re: How to make a robot turn on the spot?
Please see my first post. My questions are

What could have gone wrong?
- coding is not correct? [I think it is okay/correct]
- different motor power? (It was a brand new NXT 2.0) [I have PID enabled so somehow I expect some deviation but not a lot]
- different amount of frictional contact? [This is my prime suspect. I need to do more testing]


Tue Nov 08, 2011 6:07 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: How to make a robot turn on the spot?
I have fixed some problems in your code but I am not sure it is the root of your problem.
Code:
void move(int left_power, int right_power, int duration)
{
    motor[leftMotor] = left_power;
    motor[rightMotor] = right_power;
    wait1Msec(duration);
}

void turn(int degree, int power)
{
    int duration = abs(degree)*time_to_turn_full_round_in_msec/360;

    if (degree < 0)
    {
        // turning left
        move(-power, power, duration)
    }
    else
    {
        // turning right
        move(power, -power, duration);
    }
}

void turnLeft()
{
    turn(-90, 100);
}

void turnRight()
{
    turn(90, 100);
}


Tue Nov 08, 2011 6:19 am
Profile
Rookie

Joined: Fri Oct 28, 2011 11:50 am
Posts: 32
Post Re: How to make a robot turn on the spot?
With all respect and thanks, I don't think that's the problem.

I intended
- time_to_turn_full_round to be in seconds
- and duration in msec

hence

float duration = (float)(degree)/360.0*time_to_turn_full_round*1000.0;


Tue Nov 08, 2011 6:24 am
Profile
Guru
User avatar

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1347
Post Re: How to make a robot turn on the spot?
The problem is your duration in the move() function is typed integer. If you insist to have full turn time in seconds, you could:
Code:
int duration = degree*time_to_turn_full_round*1000/360;

This will avoid using floating point. Regardless, this doesn't fix the problem you described.
For a more accurate turn, you may want to use the encoders as feedback. For example, using the speed regulation support in RobotC just like what the tutorial videos talked about.


Tue Nov 08, 2011 6:37 am
Profile
Rookie

Joined: Fri Oct 28, 2011 11:50 am
Posts: 32
Post Re: How to make a robot turn on the spot?
Got my boy to make the robot again. This time it worked almost perfectly. So I think it is due to the construction or different amount of frictional contact after all.

Anyway, thanks all for the replies.


Wed Nov 09, 2011 11:49 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 11 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.