PROS Auton run all 4 wheelbase motors at once

Quick question. In PROS, how do I get all 4 wheelbase motors to spin at the same time (not one starting after the other one finishes) and then stop them all at the same time?

Screen Shot 2021-03-05 at 11.37.50 PM

I know in VexCode there’s startRotateFor (starts the motor and moves onto the next line) and rotateFor (waits for rotation to finish) so how should I do this in PROS?

https://pros.cs.purdue.edu/v5/api/cpp/motors.html#move-relative
PROS V5 has an API reference website, and they also provide example code on how to do just that. The TL;DR of the example code is you just utilize while loops to block the code until the motor has reached a certain position. I don’t believe move_relative naturally causes the code to yield, meaning that code you posted should cause every motor to move at once.

2 Likes

Here’s a simple (and unrefined) driving function you could experiment with. As is evident by the manually created blocking clause, move relative is not blocking (it will do what you wanted).

void drivestraight(int tickdistance, int speed, bool block)
{
  double reference = LBM.get_position();
  LFM.move_relative(tickdistance, speed);
  LBM.move_relative(tickdistance, speed);
  RFM.move_relative(tickdistance, speed);
  RBM.move_relative(tickdistance, speed);

  if (block)
  {
    while ( !( ((reference+tickdistance-5) < LBM.get_position()) && (LBM.get_position() < (reference+tickdistance+5)) ) )
    {
      pros::delay(2);
    }
  }

}
3 Likes

As the PROS V5 Motors C++ API states, move_relative “simply sets the target for the motor, it does not block program execution until the movement finishes.” Basically, move_relative behaves the same as VexCode’s startRotateFor

2 Likes