Encoder Autonomous not working


#1

Hey,
I am trying to program (VCS) an autonomous that is based on sensors. I am using the integrated encoders in the V5 smart motors. (I’ve taking out the vital part and put it in a new code, so ignore that it is running in the main bracket. I have checked in which direction the encoder value goes (it goes up):


#include "robot-config.h"
          

int main() {
    DL.spin(vex::directionType::fwd,100,vex::percentUnits::pct);
    DR.spin(vex::directionType::fwd,100,vex::percentUnits::pct);
    while(DL.rotation(vex::rotationUnits::deg) < 360){}
    DL.stop(vex::brakeType::brake);
    DR.spin(vex::brakeType::brake);
}

However, it doesn’t seem to be working. The robot just keeps on driving forwards. I am pretty sure my code is at fault since I am basing it off of the way I used to do it on robotc. I have also tried to diagnose the problem by displaying the encoder values on the brain screen, and it works fine. Any help on what I need to change would be appreciated.


#2

On v5 there is an easier way to do this
I would recommend you look at the api here http://help.vexcodingstudio.com/#cpp/namespacevex/classvex_1_1motor/rotateFor.

This should be


DL.startRotateFor(360,vex::rotationUnitsdeg,100,vex::velocityUnits::pct);
DR.rotateFor(360,vex::rotationUnitsdeg,100,vex::velocityUnits::pct);


#3

@DanDanrevolution
Thank you for your reply. I will test out the new code next time I have a chance to.