2014.06.15 Important Note: I discovered that the usage of the function pwm.setservo() it is not adeguate to control the motor in a loop. it everytime set the pwm to zero than it set the new value. the result is a loss of speed (and so power ) of the motor. I just start to use the pwm.add_channel_pulse() instead and it solve the problem.
Here the link for download the files motor.py and qpi_test1.py used to pilot motor M0.
The module qpi_test1.py is the basic user interface.
The module motor.py implements the object “motor” that manages the angular speed of the motor and the hardware interface between raspberry pi and the ESC.
the angular speed is defined in % instead of absolute value:
- to keep motor object independent from real used motor
- to keep motor object independent from real used battery (remember that motor speed is a function of the voltage).
Motor parameters are:
- current angular speed
- Min and Max angular speed (WMax,WMin)
- The speed that balances the gravity (hovering) (Wh). This value can vary according to different factors , like altitude, air temperature, humidity, qpi weight.So it is necessary to tune this value every new flight increasing the throttle upto equilibrium than save this value and reuse it when necessary (for example after a roll).
- the pin where I connect ESC on rpi GPIO. here the circuit diagram.
- The motor Kv. Right now not used but it could be used in future to estimate real angular speed or the power consumption.
- debug mode, boolean that define the debug mode
- simulation mode,boolean that activate the PWM (=TRUE di default)
- mass,Right now not used but it could be used in future to create hte phisics model of the quadcopter.
If you want to pilot the motor it is necessary to remember 2 things:
- The used ESC could request a startup procedure ( See ESC)
- Set myMotor.simulation=FALSE
The I/O interface is based on RPIO Library.(See sw installation)
By default it works at 50 HZ ( a pulse every 20 ms ).
The pulse width is the command to the motor.
With a pulse width of 1ms =1000us , the motor stops.
With a pulse width of 2ms =2000us , the motore rotates at maximum speed.
The increment can be of 10us.So the pulse width PW:
PW=(1 + (self.__RPM / 100)) * 1000
(with self.pin=18, it means GPIO18, and physical pin 12)
def __init__(self, name, pin, kv=1000, WMin=0, WMax=100, debug=True, simulation=True)
def setWLimits(self, WMin, WMax):
set the W limits for each motor
Save Wh = current W%
Sets current W =Wh
returns current Wh
Run the procedure to init the PWM
Stop PWM signal