Ramping up motor tied to a button

Currently, we have a command tied to a button that will activate a motor, but we want to be able to gradually get that motor up to 100%. The code so far looks like:

void RaiseArm::Execute() {
while(Power < 1)

the command is called in OI via a WhileHeld(). Is there a better way to do this?

The loop you wrote has no delays. It’s going to get to full power almost instantaneously. How long do you want the motor to take to ramp up?

I assume you accidentally forgot to show us the line where Power is set to 0 before starting the loop?

That makes sense, but as Alan pointed out, the code will run every 20ms, so either don’t increment it every pass or make the constant small to take that into account. If you know how fast it should ramp, and you know that happens every 20ms, it should be easy to come up with a constant value.

Also, be sure to reinitialize the value in the initialize() method.


Thanks for the replies, my lead student programmer figured that out after staring at the code for a while, and came to the same conclusion you guys did. It is working with a delay and by resetting the initial value when the button is released. All is working well.