View unanswered posts | View active topics It is currently Tue Sep 02, 2014 5:17 pm






Reply to topic  [ 2 posts ] 
Distance and Turning in Robot C 
Author Message
Rookie

Joined: Fri May 02, 2008 8:06 pm
Posts: 2
Post 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


Sat May 17, 2008 4:15 pm
Profile
Moderator
Moderator
User avatar

Joined: Wed Jan 31, 2007 3:39 am
Posts: 299
Location: San Diego, California. USA
Post 
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//
}
}

_________________
Mmmm Legos B-)

My Robot Projects:
http://www.freewebs.com/robotprojects/


Sat May 17, 2008 6:45 pm
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 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.