View unanswered posts | View active topics It is currently Fri Sep 18, 2020 7:04 pm

Reply to topic  [ 4 posts ] 
Measuring Rotation 
Author Message

Joined: Mon Oct 01, 2007 11:56 am
Posts: 7
Location: England
Post Measuring Rotation
Hi again,

I've been looking for a way to work out how many rotations the motor has done in say a 1 second period. But all I can find is things about motor encoders? If someone could provide a basic program, I would be most grateful.

Thanks in advance,

Oliver Q

Sat Oct 06, 2007 7:21 am
Profile WWW
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Hi Oliver

Motor encoders are rotation sensors that are built right into each NXT motor. These sensors return the distance the motor has moved since you last reset the encoder.

When you turn the motor, it will register 1 full rotation as 360 encoder ticks.

Heres a program I made for you, it shows you how you can read where the encoder is at, reset the encoder and do different things when the motor gets to a specific encoder spot.

Hope this helps
Scott B-)

task main()

nMotorEncoder[motorA] = 0;
nMotorEncoder[motorB] = 0;
//reset the encoders to 0//
motor[motorA] = 50;
motor[motorB] = 50;

while (true)
nxtDisplayTextLine(2,"Enc A=%d", nMotorEncoder[motorA]);
nxtDisplayTextLine(3,"Enc B=%d", nMotorEncoder[motorB]);
//read and display the encoder values on screen as motors turn//

if (nMotorEncoder[motorA]==360)
nMotorEncoder[motorA] = 0; //reset the encoder to 0 when it gets to 360, one full rotation//

if (nMotorEncoder[motorB]>500)
motor[motorB] = 0; //stop when encoder ticks is greater than 500//


Mmmm Legos B-)

My Robot Projects:

Last edited by starwarslegokid on Sat Oct 13, 2007 3:23 pm, edited 1 time in total.

Sun Oct 07, 2007 8:06 pm
Profile WWW

Joined: Fri Feb 09, 2007 9:21 am
Posts: 616
To do what you want.

Read and save in a variable the motor encoder count.
Wait for the duration you desire
Using the saved encoder count find the difference between the end and start counts from before and after the time period.

Sat Oct 13, 2007 1:39 am

Joined: Mon Oct 01, 2007 11:56 am
Posts: 7
Location: England
Thank you both for your suggestions - they have been used! :D

Sat Oct 13, 2007 4:25 am
Profile WWW
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.