View unanswered posts | View active topics It is currently Sun May 20, 2018 11:34 pm

 Page 1 of 1 [ 11 posts ]
 Print view Previous topic | Next topic
How to make a robot turn on the spot?
Author Message
Rookie

Joined: Fri Oct 28, 2011 11:50 am
Posts: 32
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
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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
Rookie

Joined: Fri Oct 28, 2011 11:50 am
Posts: 32
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
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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
Rookie

Joined: Fri Oct 28, 2011 11:50 am
Posts: 32
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
Guru

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

Tue Nov 08, 2011 5:47 am
Rookie

Joined: Fri Oct 28, 2011 11:50 am
Posts: 32
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
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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
Rookie

Joined: Fri Oct 28, 2011 11:50 am
Posts: 32
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
Guru

Joined: Sun Nov 15, 2009 5:46 am
Posts: 1523
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
Rookie

Joined: Fri Oct 28, 2011 11:50 am
Posts: 32
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
Display posts from previous:  Sort by
 Page 1 of 1 [ 11 posts ]

#### Who is online

Users browsing this forum: No registered users and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.