Encoder Autonomous not working

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.

On v5 there is an easier way to do this
I would recommend you look at the api here VCS API Reference.

This should be


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

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

I tried the code and it works! I have another question: How do I make the motors turn backwards? It seems everything that I try doesn’t work.

Switch to negative targets instead of those positive 360s.