How to make program run with time/Autonomous Error

I use sleep commands after codes to make them run for that many milliseconds. Does anyone have a different way of doing it? Mine looks like:

TrayLift.spin(vex::directionType::fwd); intakes.spin(vex::directionType::rev); vex::task::sleep(2800); TrayLift.spin(vex::directionType::rev); vex::task::sleep(800);

1 Like

Is there an issue with task::sleep? I’ve never really encountered a reason for a new time element.

Well sometimes when I run my program, it doesn’t run correctly and seems to mix up the order of my programs. I have no idea how to fix it, so I’m starting with changing my technique to see if that helps

1 Like

Also, the longer programs seem to mess up more often

can you give some examples? Sounds like an interesting problem.

At our first tournament, we ran the program (7 cube) before a match, and it worked fine. We went to the match and used it, but it drove straight into the other teams side, disqualifying us for autonomous. The next practice I thought I figured it out. I re-downloaded the program before every run, and it seemed to work. Then, last tournament, the problem happened again but luckily off field. I had even re-downloaded it and everything!

I don’t know anything about how your auton is supposed to work but if you don’t figure it out an idea would be to add kill timers so that you don’t disqualify yourself

3 Likes

Thanks for your help. Do you know how to write one in VEXcode text? Would an if statement work? if drivetrain runs for more than certain amount of seconds then stop autonomous?

You should be using the encoders built into the motor for controlling how long a motor should spin instead of task::sleep().

2 Likes

Thats what I suspected. How do I program that?

I tend to use motor.rotateFor(). I’m not sure if there is a better way or not.

What do you put in for all of those?

  Drivetrain.rotateFor(directionType dir, double rotation, rotationUnits units) 

Direction Type is either fwd or rev, just like in motor.spin(). Rotation is the number of units moved, and rotationUnits is the unit to move in. I use deg (degrees), but any of the three listed on the vcs documentation can be used: https://help.vexcodingstudio.com/#cpp/namespacevex/rotationUnits.

It says I need to put in a parenthesis but when I do more errors show up

 Drivetrain.rotateFor(fwd dir, deg units) 

Is “Drivetrain” a motor?

Heres an example of what I use for my drive train:

    // Causes the robot to drive fowards x degrees at y velocity..
    void forward(int velocity, int degrees)
    {
      // Sets the velocity of the drive train motors.
      setVelocity(velocity);

      DriveFR.rotateFor(degrees, deg, false);
      DriveBR.rotateFor(degrees, deg, false);
      DriveFL.rotateFor(degrees, deg, false);
      DriveBL.rotateFor(degrees, deg, true);
    }

Documentation: https://help.vexcodingstudio.com/#cpp/namespacevex/classvex_1_1motor/rotateFor

1 Like