View unanswered posts | View active topics It is currently Tue Sep 23, 2014 12:37 pm






Reply to topic  [ 3 posts ] 
turn specified degrees function not behaving right 
Author Message
Rookie

Joined: Sun Mar 02, 2008 9:41 am
Posts: 25
Post turn specified degrees function not behaving right
Hi,

I have constructed this function which should turn the robot a specified number of degrees:


Code:
void rotate(float angle) {
   haltMotors();
   float axisCMPerDegree    = axisCircumference / 360;
   float distanceToTravel    = axisCMPerDegree * angle;
   float ticks                    = distanceToTravel / cmPerTick;

  if (angle > 0 /*&& directionAltered == 0*/) {

      while(nMotorEncoder[motorB] > (ticks * -1) || nMotorEncoder[motorA] < ticks) {
      motor[motorA] = 50; // right.forward();
      motor[motorB] = -50;// left.backward();
      }
  }
  else if (angle < 0 /*&& directionAltered == 1*/) {

      while(nMotorEncoder[motorA] > ticks  || nMotorEncoder[motorB] < (ticks * -1)) {
      motor[motorA] = -50;//right.backward();
      motor[motorB] = 50; //left.forward();
        }
  }
  haltMotors();
 }


The problem with this function is that it does not behave the same when the angle variable is negative or positive.

By that I mean that if i tell the function to turn 90 degrees it will turn 90, but if i tell the function to turn -90 (the opposite direction) it will turn -85. So if there is a loss of precision is not inthe same when the value of angle is positive or negative.

Could someone know why please?

Regards,
giannis


Sun Apr 13, 2008 8:21 pm
Profile
Rookie

Joined: Thu Jan 17, 2008 8:38 am
Posts: 8
Location: UK
Post Turning
I do not know if it is relevant in your case, but you should set the Encoders for both motors to zero before you start. Any non-zero initial values will produce unwanted results.

IMHO, however, a better approach would be to synch motors A and B with a synchRatio of -100. Then set the Motor encoder target for A to 'ticks' and set motor power to 50 * sgn(angle).


Tue Apr 15, 2008 7:32 am
Profile
Rookie

Joined: Sun Mar 02, 2008 9:41 am
Posts: 25
Post Re: Turning
TC wrote:
I do not know if it is relevant in your case, but you should set the Encoders for both motors to zero before you start. Any non-zero initial values will produce unwanted results.

IMHO, however, a better approach would be to synch motors A and B with a synchRatio of -100. Then set the Motor encoder target for A to 'ticks' and set motor power to 50 * sgn(angle).


Hi,

Thanks for your reply. I am resetting the encoders before I call the function.

I will try synchronizing the motors and see.

Thanks again,
giannis


Tue Apr 15, 2008 8:25 am
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 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.