Arduino Forum

Topics => Robotics => Topic started by: Rixterz on May 29, 2013, 04:16 pm

Title: Helicopter - autopilot
Post by: Rixterz on May 29, 2013, 04:16 pm
Hello

I am making a project where my helicopter gradually starts up it's 4 motors as an autopilot feature, but i do not know how to slowly increase the speed from 0 to speed X (whatever speed it hovers at).

The helicopter looks like this from above:

                motor
                    |
                    |
motor -----arduino-----motor
                    |
                    |
                 motor

I only got my arduino yesterday so i really need help on these little things before my project can truly begin.

Thanks in advance- any functions that you can think of would be useful :)
Title: Re: Helicopter - autopilot
Post by: johnwasser on May 29, 2013, 04:37 pm
Speed control is usually done with analogWrite().

Increasing slowly from 0 is usually done with a loop:
Code: [Select]

for (int speed = 0; speed <= HOVER_SPEED; speed++) {
    analogWrite(Motor1Pin, speed);
    analogWrite(Motor2Pin, speed);
    analogWrite(Motor3Pin, speed);
    analogWrite(Motor4Pin, speed);
    delay(RampUpDelay);  // The higher the number the slower the ramp
}
Title: Re: Helicopter - autopilot
Post by: Rixterz on Jul 20, 2013, 04:31 pm
Thanks very much :)
Title: Re: Helicopter - autopilot
Post by: AWOL on Jul 21, 2013, 08:57 pm
Quote
Increasing slowly from 0 is usually done with a loop:
...but if you want to do other stuff, like looking at gyros or accelerometers, you're probably best not using for loops, and doing the work of the loop  explicitly as part of a state machine.
Title: Re: Helicopter - autopilot
Post by: GunnerCAF on Jul 22, 2013, 06:18 am
I am working on a single motor airplane, and I am not using delays.  This is the function I am using to ramp up and down the motor speed:

Code: [Select]

/* ========================== MOTOR POWER ==========================
/ GWS ICS-300E
/ note: min power = 70, full power = 120
/ This ramps up or down the power settings for smooth power changes
*/
void motorPower() {
 if (millis() >= motorTimer) {                // check motor timer
   motorTimer = millis() + 30;                // set next timer
   if ((motorTarget + mv) > motorVal) {       // if target speed is greater than current setting
     motorVal++;                              // increment motor power setting
   }
   if ((motorTarget + mv) < motorVal) {       // if target speed is less than current setting
     motorVal--;                              // deincrement motor power setting
   }
   motorVal= constrain((motorVal), 60, 130);  // limit motor values
   motorServo.write(motorVal);                // adjust power to new value
 }
}


motorTimer = Every 30 ms the speed continues the ramp up or ramp down.
motorTarget = This is my target motor speed
motorVal = Current motor speed
mv = This is a value from my radio control so I can override the autopilot if needed.

Maybe you can get some ideas from this for your project.  

Good luck,

Dave