
Page 1 of 1

[ 5 posts ] 

Calculating Rotation using Encoders
Author 
Message 
The_JD
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 builtin 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 


Ford Prefect
Guru
Joined: Sat Mar 01, 2008 12:52 pm Posts: 1030

Re: Calculating Rotation using Encoders
hi, have a look at the "project discussions" subforum. 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/332;j=y/321;F(n,50&S){t=r*ri*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}

Sun Oct 26, 2008 7:07 pm 


The_JD
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 


Ford Prefect
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/332;j=y/321;F(n,50&S){t=r*ri*i;i=2*r*i+j;r=t+s;}if(S){PutPixel(x,y);}}}while(1)}

Tue Oct 28, 2008 7:28 am 


mightor
Site Admin
Joined: Wed Mar 05, 2008 8:14 am Posts: 3589 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.
_________________ 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 



Page 1 of 1

[ 5 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

