Is there a Pros function that tells a motor to run for a set amount of time?

For the autonomous round I want to start by manually programming the autonomous round without PIDs and I was wondering if there was a PROS function that would tell a motor how long it should run for.

1 Like

That would consist of three commands:

motor.move(127); // start
pros::delay(1000); // 1 sec
motor.move(0); // stop
3 Likes

There are two main ways you could go about this. One is using OkapiLib, and the other is making a custom custom function.

For that function, you would want it to move the motor a certain distance, and then lock the program so it doesn’t continue until the motors move to that distance. It would look something like the below code, which is a slightly modified version from the move_absolute example code from the PROS documentation site.

//Our function
void moveDist(double pos){
  //Reset the encoder so previous movements don't affect us
  motor.tare_position();
  //Moves the inputed units forward
  motor.move_absolute(pos, 100); 
  //Block the program so it does not continue until we reach our wanted position.
  //As its pretty much impossible to actually hit the exact position due to physical constants, we look to see if the robot is within a range instead.
  while (!((motor.get_position() < (pos + 5)) && (motor.get_position() > (pos - 5)))) {
    pros::delay(2);
  } 
}

1 Like