View unanswered posts | View active topics It is currently Tue Oct 20, 2020 12:04 am

 Page 1 of 1 [ 2 posts ]
 Print view Previous topic | Next topic
IME clearing issue
Author Message
Rookie

Joined: Wed May 27, 2015 1:59 pm
Posts: 1
IME clearing issue
Here is a bit of code from our functions header file.

 Code://Error margin calculationint difference = abs(nMotorEncoder[RD]) - abs(nMotorEncoder[LD]);//Timed braking for movementsvoid pause(){   wait1Msec(200);}//Move Forward (Distance)void forward[code][/code]_enc(int distanceInDegrees){   //Clear encoders   nMotorEncoder[RD] = 0;   nMotorEncoder[LD] = 0;   {      while(abs(difference) >= 2 && abs(nMotorEncoder[RD]) > abs(nMotorEncoder[LD]) && abs(nMotorEncoder[RD]) < distanceInDegrees)         //Slow down right side to adjust for error      {         motor[RD] = -50;         motor[LD] = 42;      }      while(abs(difference) >= 2 && abs(nMotorEncoder[RD]) < abs(nMotorEncoder[LD]) && abs(nMotorEncoder[RD]) < distanceInDegrees)         //Slow down left side to adjust for error      {         motor[RD] = -50;         motor[LD] = 38;      }      while(abs(difference) < 2 && abs(nMotorEncoder[RD]) < distanceInDegrees)         //Drive both sides equally      {         motor[RD] = -50;         motor[LD] = 40;      }   }   //Braking motion to minimize drift   motor[RD] = 40;   motor[LD] = -30;   pause();   motor[RD] = 0;   motor[LD] = 0;}

When running the autonomous mode (Forward and turn left) the robot only does the braking motion and does not move forward and turn left the correct distance. The functions clear the encoders before moving, it can be seen in the sensors window as it happens. If I clear the encoders manually using the virtual competition control the autonomous functions as intended. What could I do to fix this so the encoders are zeroed correctly through the code?

_________________
Mentor of team 9571D from Southern Illinois, USA

Wed May 27, 2015 2:11 pm
Moderator

Joined: Tue May 19, 2015 3:07 pm
Posts: 91
Re: IME clearing issue
 Code://Error margin calculationint difference = abs(nMotorEncoder[RD]) - abs(nMotorEncoder[LD]);}

So this line only is run once in the program. That means that if you run this program with all encoder values at 0 than the only while loop that will be executed is the third one. What you want to do is update the difference value continuously.

 Code:while(abs(difference) >= 2 && abs(nMotorEncoder[RD]) > abs(nMotorEncoder[LD]) && abs(nMotorEncoder[RD]) < distanceInDegrees)         //Slow down right side to adjust for error      {         motor[RD] = -50;         motor[LD] = 42;      }      while(abs(difference) >= 2 && abs(nMotorEncoder[RD]) < abs(nMotorEncoder[LD]) && abs(nMotorEncoder[RD]) < distanceInDegrees)         //Slow down left side to adjust for error      {         motor[RD] = -50;         motor[LD] = 38;      }      while(abs(difference) < 2 && abs(nMotorEncoder[RD]) < distanceInDegrees)         //Drive both sides equally      {         motor[RD] = -50;         motor[LD] = 40;      }

It also appears that you have a bracket that opens right before the first while loop for no reason and then closes after all the while loops. The use of this chain of while loops means that if the robot is on the third while loop it will never go back to the first one. Here I made a few small changes to the code so that the robot will always be able to correct and so that the difference variable updates every cycle.

 Code://Error margin calculationint difference = abs(nMotorEncoder[RD]) - abs(nMotorEncoder[LD]);//Timed braking for movementsvoid pause(){   wait1Msec(200);}//Move Forward (Distance)void forward(int distanceInDegrees){   //Clear encoders   nMotorEncoder[RD] = 0;   nMotorEncoder[LD] = 0;   int threshold=5;//ticks off from goal that accepts as close enough   while(abs(nMotorEncoder[RD]-distanceInDegrees)= 2 && abs(nMotorEncoder[RD]) > abs(nMotorEncoder[LD]) && abs(nMotorEncoder[RD]) < distanceInDegrees)         //Slow down right side to adjust for error      {         motor[RD] = -50;         motor[LD] = 42;      }      if(abs(difference) >= 2 && abs(nMotorEncoder[RD]) < abs(nMotorEncoder[LD]) && abs(nMotorEncoder[RD]) < distanceInDegrees)         //Slow down left side to adjust for error      {         motor[RD] = -50;         motor[LD] = 38;      }      if(abs(difference) < 2 && abs(nMotorEncoder[RD]) < distanceInDegrees)         //Drive both sides equally      {         motor[RD] = -50;         motor[LD] = 40;      }   }   //Braking motion to minimize drift   motor[RD] = 40;   motor[LD] = -30;   pause();   motor[RD] = 0;   motor[LD] = 0;}

Does that make sense or do you want me to explain in more detail.

Wed May 27, 2015 4:54 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 2 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