View unanswered posts | View active topics It is currently Mon Jun 27, 2016 11:02 am

 Page 1 of 1 [ 5 posts ]
 Print view Previous topic | Next topic
Calculating Rotation using Encoders
Author Message
Rookie

Joined: Sat Oct 04, 2008 2:30 pm
Posts: 7
Calculating Rotation using Encoders
Hi,

1.) I need some info on how to calculate angles using the built-in encoders in the Lego NXT Mindstorms Robot. I've tried all the major search engines but unfortunately nothing came up that was suitable for the beginner roboticist. I'm basically trying to get the robot to turn x degrees but have no idea how to get it to do this. I know I've got to use the encoders to do this but once again I'm clueless as to how to use it. I've managed to get a sample program to display its values on the screen but have no idea what units thats in (Its definitely not degrees).

2.) The NXT comes with a sample program that actually tells you on the screen how many degrees the wheel is turned by when you manually turn a wheel attached to a motor. I can't seem to find the source code for this program anywhere. If anyone could point me in the right direction for that too, it'd be much appreciated (Its not in RobotC's directory of sample codes).

Any links on where to go to get such info or the info itself is much appreciated.

- JD.

Sun Oct 26, 2008 6:57 pm
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Re: Calculating Rotation using Encoders
hi,
have a look at the "project discussions" sub-forum. I posted a code for a navigation robot some months ago with commands for turning among many other things. The only things you have to know is the diameter of the wheels and the length of the axis (track width). The rest is bloody maths.
HTH!

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}

Sun Oct 26, 2008 7:07 pm
Rookie

Joined: Sat Oct 04, 2008 2:30 pm
Posts: 7
Re: Calculating Rotation using Encoders
It did help. Thanks a bunch. I've got a new dilemna now though. This ones more logical than technical but would it be possible to get a tribot to move in a circle if it was given just a radius?

Mon Oct 27, 2008 7:01 pm
Guru

Joined: Sat Mar 01, 2008 12:52 pm
Posts: 1030
Re: Calculating Rotation using Encoders
yes, surely there's a way - everything goes.
I didn't need the code so far, but the diameter of the circle can be calculated through the relation between the driven stretches (speed, arc of circles) of the external (faster) wheel vs. the slower wheel.

Just 2 examples:

if the slower wheel=0 (stop), it's position is the center of the driven circle, and the radius of the driven circle is as large as the axis (track width),
if the slower wheel moves half as fast as the faster one, the radius of the driven circle is twice as large as the axis (track width),
a.s.o.
HTH!

_________________
regards,
HaWe aka Ford
#define S sqrt(t+2*i*i)<2
#define F(a,b) for(a=0;a<b;++a)
float x,y,r,i,s,j,t,n;task main(){F(y,64){F(x,99){r=i=t=0;s=x/33-2;j=y/32-1;F(n,50&S){t=r*r-i*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}

Tue Oct 28, 2008 7:28 am
Site Admin

Joined: Wed Mar 05, 2008 8:14 am
Posts: 3654
Location: Rotterdam, The Netherlands
Re: Calculating Rotation using Encoders
Hey JD,

I had a similar issue trying to get my robot to turn an exact 90 degrees without the use of a real compass. So instead I use a digital compass, one that uses the wheels' encoders to calculate how much I've turned. The program which I have attached has a task that keeps track of this. You can then read the value of the position and turn your motor until your target position has been reached. Just read through the code, it is not nearly finished yet, but I am sure you get the gist of it.

You can calculate the degreesPerTurn variable as follows:

distance between the two wheels * 2 * pi
----------------------------------------- * 360
diameter of wheels * pi

you can simplify that to:

distance between the two wheels * 2
------------------------------------ * 360
diameter of wheels

For a robot with a distance of 15 cm between the two wheels and using the standard 56mm wheels that come with the NXT set, you get:
((150 * 2 ) / 56 ) * 360 ~= 1929

If you have questions regarding my code, let me know.

Regards,
Xander

Edit: although the filename says "linefollower", it's really the skeleton of a maze solving robot.

 Attachments: LineFollower.zip [3.63 KiB] Downloaded 206 times

_________________
| Professional Conduit of Reasonableness
| (Title bestowed upon on the 8th day of November, 2013)
| My Blog: I'd Rather Be Building Robots
| ROBOTC 3rd Party Driver Suite: [Project Page]
Tue Oct 28, 2008 8:57 am
Display posts from previous:  Sort by
 Page 1 of 1 [ 5 posts ]

#### Who is online

Users browsing this forum: No registered users and 1 guest

 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.