Running python on the crazyflie2

Firmware/software/electronics/mechanics
Da_Blitz
Beginner
Posts: 3
Joined: Fri Dec 19, 2014 3:48 pm

Running python on the crazyflie2

Post by Da_Blitz »

After noticing the crazyflie 2 had near identical hardware to the http://micropyton.org boards i spent some time porting micropython to run on the board as soon as i received it. Luckily this was easier than i thought and apart from one minor difference i hardware (usb vbus sensing line not being wire up) there were no problems encountered.

Some extra work needs to be completed before its fully usable (eg drivers for the accelerometer/gyro) and some nice wrappers around things such as the motoro control needs to be put in place however if you want to experiment it is in a usable state

Steps to build firmware:
* check out crazyflie2 branch at https://github.com/exec-all/micropython/ with the command

Code: Select all

git clone -b crazyflie2 https://github.com/exec-all/micropython/
* cd into the 'stmhal' dir in the repo
* build the firmware with

Code: Select all

BOARD=CRAZYFLIE2 make
* Put the crazyflie2 into dfu flash mode by removing battery power and usb cables then holding the power button and plugging in a usb cable
* the crazyflie2 will blink a blue led slowly then rapidly, once it is flashing rapidly release the button
* ensure 'dfu-util' is avalible on your machine to flash the firmware
* flash the firmware by running the following command:

Code: Select all

dfu-util -a 0 -D build-CRAZYFLIE2/firmware.dfu
once the board is reset the device will show up as a usb flash drive/serial port combo. connecting a terminal emulator t (/dev/ttyACM0 in linux) to the serial device will give you an interactive prompt where you can execute code like that shown below to play with the copter

Code: Select all

import pyb
for i in range(400000):
    pyb.LED((i%4)+1).on()
    pyb.delay(400)
    pyb.LED((i%4)+1).off()
What is conformed working:
  • Red/Green LEDs
What has not been checked:
  • Turning motors on and off
    Expansion boads
    Communication with the radio
What is not working:
  • Accelerometer
    onewire for Expansion Boards
    Over the air firmware updates
Technical details:
The firmware flashing procedure is slightly different to crazyflie2 and is the equivalent of CLOAD=0. This will replace the bootloader and you will lose the ability to load new firmware over the air (needs to be flashed via usb).
micropython is similar but not identical to python 3.4, notably there are substantially less libraries available by default and modules like 'sys' have only basic functionality. for a good introduction see http://docs.micropython.org/en/latest/t ... index.html
There is no flight control software at the moment(on the todo list) so its up to you to spin the motors at the correct speed and stay level (without the use of the accelerometer until that driver gets written)
As the usual firmware is not there, software that communicates with the firmware over the radio will not work. this includes anything using the official crazyflie python libraries


Feedback/feature requests are welcome
chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

Re: Running python on the crazyflie2

Post by chad »

This is really cool. I picked up a µPython board not too long ago but haven't had the chance to do much with it. Seeing micro python ported to the crazyflie 2 is, well, crazy cool!

As soon as I have an opportunity, I'll try it out. This looks particularly fun. Thanks!!
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
dbrgn
Member
Posts: 51
Joined: Tue Dec 16, 2014 9:42 pm

Re: Running python on the crazyflie2

Post by dbrgn »

Wow, that's cool!
Da_Blitz
Beginner
Posts: 3
Joined: Fri Dec 19, 2014 3:48 pm

Re: Running python on the crazyflie2

Post by Da_Blitz »

Just a quick update

* I have the PWM working for the motors based on the official crazyflie firmware and have done a tethered take-off (usb cable was plugged in for shell access)
* 'headlights' on the LED ring board work. currently working on setting colours on the ring
* reading values from the IMU/MPC should be straight forward. will most likely have to provide a 'high level' and 'low level' interface
* Reading the EEPROM in a compatible way will also need a driver
* Will need a driver for the One wire bus (i have something based off continuations up my sleeve from an earlier protocol parser i wrote)
* There is no 'commander' you will have to fly it yourself for the moment. The code will eventually be split into a low level interfacing library and a high level services layer allowing you to worry about things such as navigation and communication and less so about keeping the drone in the air

Current oder for intended compleation is as follows
* LEDs
* Presure sensor driver
* Gyroscope/accelerometer/magnetometer
* One Wire
* EEPROM
* Automated flight code/commander

Currently aiming to have this up and running for LCA2015 (NZ) for the openhardware track so if anyone sees a crazyflie while you are there come over and say hi.

hats off to the micropython and crazyflie team, this has been a lot simpler and robust than i could have ever hoped for and having an unbrickable device really makes for a much more pleasant testing experience
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Running python on the crazyflie2

Post by tobias »

How on earth have you managed to get micropython up and running this fast, I'm amazed! Arnaud will be jumping around when he reads this :D
chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

Re: Running python on the crazyflie2

Post by chad »

tobias wrote:How on earth have you managed to get micropython up and running this fast, I'm amazed!
Well, his username is Da_Blitz and if you define "blitz" as "a sudden, energetic, and concerted effort, typically on a specific task," then it's understandable. ;)
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
Da_Blitz
Beginner
Posts: 3
Joined: Fri Dec 19, 2014 3:48 pm

Re: Running python on the crazyflie2

Post by Da_Blitz »

Da_Blitz wrote:Just a quick update
Current oder for intended compleation is as follows
* LEDs
* Presure sensor driver
* Gyroscope/accelerometer/magnetometer
* One Wire
* EEPROM
* Automated flight code/commander
Just finished up a driver for the LED ring, the forward headlights 'just work' however there is no PWM to change their brightness/dim them due to timer 3 being reserved for system use only (may be able to cheat here)

there is a driver already for the MPU9150, i will need to check how compatible it is with the MPU9250 and add any missing support if it wont work however i can now scan both i2c buses and see both the EEPROM and the MPU after a quick patch to micropython to support I2C bus 3, from memory this is in the github repo mentioned above already so pull the latest version if you already have checked it out

the pixel ring driver is currently bit banged with thumb-2 assembly code due to timing requirements and taking 340uS per update giving a decent update rate and should form the basis for the one wire driver as well

I originally intended to push a 'flie.py' module to load on to the device for hardware support however i will be splitting this off and putting it on the chesseshop/pypi so that ir can be pip install'd to the device from a computer and allow me to maintain the module separately to the micropython project. With any luck i will hit the commander stage late this week and have all the hardware fully supported


I have noticed a high pitch whine when i bring the board close to my ear, can anyone confirm they are getting this with the default firmware? i will swap back to the crazyflie32 firmware tonight and test but would not mind double checking against a different device as it may be indicative of a setup issue in my code
Jaja
Beginner
Posts: 3
Joined: Wed Mar 02, 2016 6:32 am

Re: Running python on the crazyflie2

Post by Jaja »

hello crazyflie people. I'm a teacher and super excited about this micropython thing. I see that project looks on hold but I'll get my hands on a 2.0 drone and start working quickly on it. I'll keep you in touch.
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: Running python on the crazyflie2

Post by kristoffer »

Looking forward to hear about any progress!
chad
Expert
Posts: 555
Joined: Sun Sep 28, 2014 12:54 am
Location: New York, USA
Contact:

Re: Running python on the crazyflie2

Post by chad »

kristoffer wrote:Looking forward to hear about any progress!
So am I!! Micropython is really cool and Da_Blitz was moving quick on this last year. I'm not sure where he ended up. The last commit to his GitHub repo was the day before his last post here and there hasn't been any activity since. :cry:

Also, I think Da_Blitz signed up and posted prior to reply notifications being available and enabled by default in the forum so I hope he selected to be notified himself or maybe we'll need to try to reach him through his GitHub...?
Crazyflier - my CF journal...
4x Crazyflie Nano (1.0) 10-DOF + NeoPixel Ring mod.
3x Crazyflie 2.0 + Qi Charger and LED Decks.
Raspberry Pi Ground Control.
Mac OS X Dev Environment.
Walkera Devo7e, ESky ET6I, PS3 and iOS Controllers.
Post Reply