View unanswered posts | View active topics It is currently Thu Jun 21, 2018 7:20 pm

 Page 1 of 1 [ 3 posts ]
 Print view Previous topic | Next topic
turn specified degrees function not behaving right
Author Message
Rookie

Joined: Sun Mar 02, 2008 9:41 am
Posts: 25
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.

Regards,
giannis

Sun Apr 13, 2008 8:21 pm
Rookie

Joined: Thu Jan 17, 2008 8:38 am
Posts: 8
Location: UK
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
Rookie

Joined: Sun Mar 02, 2008 9:41 am
Posts: 25
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
Display posts from previous:  Sort by
 Page 1 of 1 [ 3 posts ]

Who is online

Users browsing this forum: No registered users and 2 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ ROBOTC Applications    ROBOTC for LEGO MINDSTORMS       Third-party sensors    ROBOTC for CORTEX & PIC    ROBOTC for VEX IQ    ROBOTC for Arduino    Robot Virtual Worlds    Multi-Robot Communications    Issues and Bugs Competitions & Partners    Mini Urban Challenge    CS2N Robot Virtual Worlds Competitions       VEX Skyrise Competition 2014-2015       VEX Toss Up 2013-2014       FTC Block Party! 2013-2014    Competitions using VEX - BEST, TSA, VEX, and RoboFest!    FTC Programming    RoboCup Junior and Other ROBOT Competitions Virtual Brick Robotics Discussions    General Discussions    Project Discussions Off-Topic ROBOTC Forum & ROBOTC.net Suggestions/Feedback    ROBOTC Forums Suggestions/Comments    ROBOTC.net Suggestions/Comments       NXT Programming: Tips for Beginning with ROBOTC       VEX Programming: Tips for Beginning with ROBOTC    2013 Robotics Summer Of Learning       VEX Toss Up Programming Challenge       FTC Ring It Up! Programming Challenge    International Forums       Spanish Forums          ROBOTC for MINDSTORMS          ROBOTC for VEX       French Forums          ROBOTC pour Mindstorms          ROBOTC pour IFI VEX       Japanese Forums （日本語のフォーラム）       German Forums    2015 Spring Carnival Event    PLTW (Project Lead The Way)    Robotics Merit Badge    2014 Robotics Academy Summer of Learning