ROBOTC.net forums
http://www.robotc.net/forums/

Measuring Rotation
http://www.robotc.net/forums/viewtopic.php?f=1&t=269
Page 1 of 1

Author:  quirkey [ Sat Oct 06, 2007 7:21 am ]
Post subject:  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

Author:  starwarslegokid [ Sun Oct 07, 2007 8:06 pm ]
Post subject: 

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)
{
PlayTone(2000,1);
nMotorEncoder[motorA] = 0; //reset the encoder to 0 when it gets to 360, one full rotation//
}

if (nMotorEncoder[motorB]>500)
{
PlayTone(1500,1);
motor[motorB] = 0; //stop when encoder ticks is greater than 500//
}

}
}

Author:  Dick Swan [ Sat Oct 13, 2007 1:39 am ]
Post subject: 

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.

Author:  quirkey [ Sat Oct 13, 2007 4:25 am ]
Post subject: 

Thank you both for your suggestions - they have been used! :D

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/