|
Page 1 of 1
|
[ 4 posts ] |
|
Author |
Message |
quirkey
Rookie
Joined: Mon Oct 01, 2007 11:56 am Posts: 7 Location: England
|
 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 |
|
 |
starwarslegokid
Moderator
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)
{
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//
}
}
}
_________________Mmmm Legos B-) My Robot Projects: http://www.freewebs.com/robotprojects/
Last edited by starwarslegokid on Sat Oct 13, 2007 3:23 pm, edited 1 time in total.
|
Sun Oct 07, 2007 8:06 pm |
|
 |
Dick Swan
Creator
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 |
|
 |
quirkey
Rookie
Joined: Mon Oct 01, 2007 11:56 am Posts: 7 Location: England
|
Thank you both for your suggestions - they have been used! 
|
Sat Oct 13, 2007 4:25 am |
|
|
|
Page 1 of 1
|
[ 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
|
|