View unanswered posts | View active topics It is currently Sun Oct 25, 2020 4:45 am

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

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;

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



Sat May 17, 2008 4:15 pm
User avatar

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

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:

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.