Chief Delphi

Chief Delphi (http://www.chiefdelphi.com/forums/index.php)
-   C/C++ (http://www.chiefdelphi.com/forums/forumdisplay.php?f=183)
-   -   Ramping up motor tied to a button (http://www.chiefdelphi.com/forums/showthread.php?t=113631)

nickpaterni 16-02-2013 10:16

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)
{
arm->TurnOn(Power);
Power += MOTOR_RAMP_UP_AMT;
}

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

Alan Anderson 17-02-2013 00:30

Re: Ramping up motor tied to a button
 
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?

BradAMiller 17-02-2013 13:36

Re: Ramping up motor tied to a button
 
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.

Brad

nickpaterni 17-02-2013 13:50

Re: Ramping up motor tied to a button
 
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.

Thanks
Nick


All times are GMT -5. The time now is 18:18.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi