Coding problem with motor speed

Hi guys! I’m new to vex this year and I’m unfamiliar to VEXcode. I know some of the basics but not exactly what everything does. Currently, I’m using this code to tile my cube tray:
cubeTilt.spin(vex::directionType::fwd, 0.5, vex::velocityUnits::pct);

however, it keeps accelerating as I continue to hold the button, so I’ve had to dial it down to 0.5 percent to manage it. Does anyone know a way to make the motors just spin at a constant velocity?

we’d have to see the rest of your code. This indicates it always spins at .5%.

This is inside the user control section:

if(cubeTiltFwd) {
cubeTilt.spin(vex::directionType::fwd, 0.5, vex::velocityUnits::pct);
}
else if(cubeTiltRev) {
cubeTilt.spin(vex::directionType::rev, 0.5, vex::velocityUnits::pct);
}
//if neither pressed, then stop
else {
cubeTilt.stop(brakeType(brake));
}

cubeTiltFwd + cubeTileRev are declared as: const auto

Forgive me if I’m wrong, but isn’t .5% very very small? like not moving small.

yes, and it starts out not moving at all, but then keeps speeding up as long as the button is pressed

can you show us your cubeTiltfwd and rev.

const auto cubeTiltFwd = Controller1.ButtonR1.pressing();
const auto cubeTiltRev = Controller1.ButtonR2.pressing();

Change ‘const auto’ to ‘bool’. It definitely sounds like that is the problem and I’m not too sure how ‘const auto’ would work.

Or just type out Controller.ButtonR1.pressing() i don’t see the point in the const auto thing. i see no problems with the rest of your statements.

1 Like

that kind of worked… It seems better but i still feel like its accelerating

you can always use rpm instead of pct. This should* keep the motor at that set rpm. your code is practically identical to the code for my intakes so I’m not sure whats wrong here.

its possible that the load it has to push is changing as it tilts further up (lever advantage)

yes this is possible which is why rpm could be better for same speed control.

I know what the problem is
the velocity makes it increace by .5
if u have this code it should work just fine:
Drivetrain.drive(fwd, (Controller1.Axis3.value() + Controller1.Axis3.value())/2, velocityUnits::pct);

Drivetrain.drive(reverse, (Controller1.Axis1.value() - Controller1.Axis1.value())/2, velocityUnits::pct);

The problem was a broken motor encoder. The motor couldn’t tell how fast it was going and automatically went from whatever speed we told it to 100%. Fixed by replacing the motor. Thanks, all!