SW Dev 1: motor.py

This is the first post dedicated to the sw development.On page  Python you can find the different sw versions and the description of the used classes.

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:

  1. to keep motor object independent from real used motor
  2. to keep motor object independent from real used battery (remember that motor spped is a function of teh voltage).

Motor parameters are:

  • current angular speed (RPM)
  • Min and Max angular speed (RPMMax,RPMMin)
  • The speed that balances the gravity (hovering)  (RPMEquil). 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 mow 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)

If you want to pilot the motor it is necessary to remember 2 things:

  1. The used ESC could request a startup procedure ( See ESC)
  2. Set  myMotor.simulation=FALSE

The I/O interface is based on RPIO Library.

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

self.__IO.set_servo(self.pin,PW)

(with   self.pin=18,  it means  GPIO18, and physical pin 12)

Link:

http://pythonhosted.org/RPIO/pwm_py.html

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s