View unanswered posts | View active topics It is currently Sat Aug 24, 2019 3:49 pm

 Page 1 of 1 [ 1 post ]
 Print view Previous topic | Next topic
Blocked encoder
Author Message
Rookie

Joined: Fri Aug 07, 2015 11:02 am
Posts: 6
Blocked encoder
Hello,

I have written a function for a turn with acceleration at the start of the turn and decceleration at the end.
The code is:
 Code:void Turn(float turn){   int speed;   int tmp=0;   turn = turn*constant;                                    //the turn in degrees is multiplied with a constant to get the number of desired encoder turns   resetMotorEncoder(left);                                       //encoders of both motors are reset   resetMotorEncoder(right);   setMotorSync(left, right, 0, 0);                                 //left(master) and right(slave) motors are synchronised   /*acceleration*/   while(abs(tmp) < (int)abs(turn)/2){                              //motor accelerates until motor encoder reaches half of the desired turn      speed = sqrt(2*a*abs(tmp))+minPower;                           //it accelerates using this formula for speed of the motor      if(speed>maxSpeed){                                       //if the calculated speed is above the maximum         speed=maxSpeed;                                       //it is reset to maximum      }      if(turn<0){                                             //the motors get the speed, depending on the desired direction of the turn         setMotorSync(left, right, 100, speed);      }      else{         setMotorSync(left, right, -100, speed);      }      delay(1);      tmp=getMotorEncoder(left);                                 //the value of the master encoder is read   }   /*deceleration*/   while(abs(tmp) < (int)abs(turn)){                              //the other half it decelerates      speed = sqrt(2*a*(abs(turn)-abs(tmp)))+minPower;                  //it accelerates using this formula for speed of the motor      if(speed>maxSpeed){                                       //if the calculated speed is above the maximum         speed=maxSpeed;                                       //it is reset to maximum      }      if(turn<0){                                             //the motors get the speed, depending on the desired direction of the turn         setMotorSync(left, right, 100, speed);      }      else{         setMotorSync(left, right, -100, speed);      }      delay(1);      tmp=getMotorEncoder(left);                                 //the value of the master encoder is read                  }   setMotorSync(left, right, 0, 0);                                 //for the end of the turn, the motors are turned off}

Most of the time it is working great. But sometimes (more or less randomly) it gets stuck. It appeares as if something was wrong with the condition in while statement or the encoder is malfunctioning.
The master (even if I switch the roles of master and slave) encoder/wheel gets blocked, meaning the encoder value remains the same. The other motor keeps spinning. If I then manually turn the master wheel just a little bit, it goes on without the problem.
I have noticed that the error gets worse the longer the brick is unplugged, but still indicates full battery. Therefore I was wondering if that could be the cause of the problem or did I miss something else.

Fri Mar 11, 2016 6:04 pm
Display posts from previous:  Sort by
 Page 1 of 1 [ 1 post ]

#### 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