Some Questions with our code

We are having a issue with a function we are trying to write.

We are trying to have this function run but have the option to also move our robot while the command is running

This is the function that we have written and the void for the “traytiltdontwait”

if (Controller1.ButtonY.pressing()){
  traytiltdontwait (9.5, 100);

void traytiltdontwait (double rotation, double velocity) {
TrayTilt.rotateFor(rotation, rotationUnits::rev, velocity, velocityUnits::pct, false);

Any suggestions on how to do this?

It looks like you are not actually using RobotC as your topic choice suggests but are using Robot Mesh Studio C++ or VEXcode V5 Text.

The answer for either is going to be the same: don’t use a blocking function. rotateFor is blocking. That is, nothing else can happen in that task until it completes. Luckily, there is startRotateFor. It tells the motor to do the same thing as rotateFor, but does not block.

While a startRotateFor is running (also a rotateFor, but you’d have to be in another task to see this) the motor’s isSpinning method will return true (and isDone will return false). So you can change your button code to also check for this “is a command running” state with the && operator:

if (Controller1.ButtonY.pressing() && TrayTilt.isDone()) {

This is just one of a few ways to accomplish this.

1 Like