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






Reply to topic  [ 4 posts ] 
Turning using encoders 
Author Message
Rookie

Joined: Tue Jun 18, 2013 6:04 pm
Posts: 29
Post Turning using encoders
Referencing Wednesday's class, since there was no wait programmed when making a turn using the encoders, how does the robot know how far to turn?
Chris


Sun Jun 23, 2013 6:10 pm
Profile
Moderator
Moderator

Joined: Mon Oct 04, 2010 2:18 pm
Posts: 196
Post Re: Turning using encoders
The robot will know how far to turn using the encoder values, just as if it was going straight. Take a look at the code below:
Code:
task main ()
{
//Clear the encoders
   nMotorEncoder[motorB] = 0;
   nMotorEncoder[motorC] = 0;

   while(nMotorEncoder[motorB] < 150)//turn left until encoder value reaches 150
   {
      motor[motorB] = 20;
      motor[motorC] = -20;   

   }

   motor[motorB] = 50; //move forward
   motor[motorC] = 50;
   wait1Msec(4000);
}


The condition inside of our while loop is motorB reaching an encoder count of 150. As long as that condition is correct,
the robot will make a point turn left. As soon as the condition is no longer true, the loop breaks and the robot moves forward.

The robot moves proportionally, so if at an encoder count of 150, the robot makes a 45 degree turn, you can double your encoder
value and it should make a 90 degree turn. Experiment with it, and see what happens.


Sun Jun 23, 2013 7:28 pm
Profile
Rookie

Joined: Tue Jun 18, 2013 6:04 pm
Posts: 29
Post Re: Turning using encoders
Hi Parkway,
Thanks for responding. Please excuse my thickheadedness, but how does 150 = a 45 degree turn?


Sun Jun 23, 2013 9:07 pm
Profile
Moderator
Moderator

Joined: Mon Oct 04, 2010 2:18 pm
Posts: 196
Post Re: Turning using encoders
No problem. Remember, encoder values are degrees that the wheel is rotating. 45 degrees is the amount that the robot is turning. Try to think of it in these terms: in a left point turn, the left wheel is going backwards and the right wheel is moving forwards. You can go here to see a picture of what I mean:

http://www.robotc.net/support/nxt/MindstormsWebHelp/index.htm#page=robot_algebra/robot_movements/Robot%20Movements.htm

So, what you are really trying to figure out is "How many encoder counts (degrees) does my right wheel need rotate in order for my robot to make a 45 degree, left turn?"'

Keep in mind, I'm not saying that is the correct amount of encoder counts. You may have to play around with the values until you find the correct ones. I hope that clears it up for you.


Sun Jun 23, 2013 9:31 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 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

Search for:
Jump to:  
cron



Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.