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

Distance and Turning in Robot C
http://www.robotc.net/forums/viewtopic.php?f=1&t=560
Page 1 of 1

Author:  rail33 [ Sat May 17, 2008 4:15 pm ]
Post subject:  Distance and Turning in Robot C

I'm new to programming and new to RobotC.

In programming turns, I'm using "movement duration" instead of a specific degree of turn. Here's an example of how I'm programming a turn:

nSyncedMotors = synchBC;
nSyncedTurnRatio = -100;
motor[motorB] = 50;
wait1Msec(335);

How can I program turns using degrees instead of motor duration?

Thanks,

rail33

Author:  starwarslegokid [ Sat May 17, 2008 6:45 pm ]
Post subject: 

Hi rail33,

To do this you have to use the built in rotation sensor in the motor, called the encoder. Here is some sample code that shows you how to set up a motor encoder target, let me know if this helps B-).

Scott B-)

Code:
task main()
{
nMotorEncoder[motorA] = 0; // reset encoder to 0 position
nMotorEncoderTarget[motorA]=1000; //where you want to move to
motor[motorA] = 100; //move at full speed

while (nMotorRunState[motorA] != runStateIdle) //will do whats in brackets untill it gets to its target//
{
nxtDisplayTextLine(2,"Enc A=%d", nMotorEncoder[motorA]); //display encoder on the nxt screen//
}
}

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