How to add new output to Crazyflie 2.0

Firmware/software/electronics/mechanics
Post Reply
braraki
Beginner
Posts: 2
Joined: Mon May 02, 2016 11:30 pm

How to add new output to Crazyflie 2.0

Post by braraki »

I'm trying to add another motor onto my Crazyflie - not for flight, but just to rotate something underneath it. I'm wondering how I can go about controlling the motor. I'm pretty sure I can use the expansion deck / the Deck API, but it's confusing and I'm not sure where to start. I made my own 'expansion deck' with a motor controller on it, but now I have to give it some sort of PWM signal and digital input. In addition, I want to be able to control the motor using a PS3 controller. Is there a way to add that functionality?

Thanks for any help you can offer!

Brandon
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: How to add new output to Crazyflie 2.0

Post by kristoffer »

It should be possible to do what you want.

To get started on decks and drivers, take a look at the traffic light project on hackster https://www.hackster.io/evoggy/flying-t ... ght-8be87d or the crazy car https://www.hackster.io/evoggy/crazycar-3c14b6
and on the wiki https://wiki.bitcraze.io/doc:crazyflie: ... mware:deck

Info on decks in general on the wiki here https://wiki.bitcraze.io/projects:crazy ... ards:index

You could also look at the "official" decks, for instance the LED-ring https://wiki.bitcraze.io/projects:crazy ... ds:ledring for inspiration. You will find schematics on the wiki and the code on https://github.com/bitcraze/crazyflie-firmware/.

Hope you get some new ideas!
braraki
Beginner
Posts: 2
Joined: Mon May 02, 2016 11:30 pm

Re: How to add new output to Crazyflie 2.0

Post by braraki »

Hi kristoffer,

Thanks for the help! I just wanted to let you and anyone else interested in adding motor/pwm outputs know that I was able to get it to work. The steps I did to do it are as follows:

1. Make copies of piezo.h, piezo.c (in drivers), and buzzdeck.c (in deck/drivers/src) and name them along the lines of wheel_driver.h, wheel_driver.c, and wheeldeck.c

2. Change all "piezo"s in wheel_driver.h and wheel_driver.c to "wheel" or whatever. Then go through the timer and port definitions of wheel_driver.c to change them to be what you want (aka modify the names or change the timer or channel). piezo.c makes PWM outputs on TIM5_CH3 and TIM5_CH4. I did not change this for myself. Note that TIM5_CH3 is mapped to TX2 and TIM5_CH4 is mapped to RX2 on the expansion deck. Next, under the comment "// Configure OC3" add the line
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
so that OC3 is not inverted from OC4. Unless you want it to be inverted.
The function piezoSetRatio(uint8_t ratio) sets the PWM duty cycle of the two outputs. You may want to modify this function to take two ratios so that you can give each motor its own duty cycle.

3. Next modify buzzdeck.c (now named wheeldeck.c or whatever). I combined code from buzzdeck.c, this forum post on making digital I/O (viewtopic.php?t=1690) and this tutorial on adding LEDs (https://www.hackster.io/evoggy/flying-t ... ght-8be87d).

4. Add to the Makefile:
#Drivers
PROJ_OBJ_CF2 += wheel_driver.o
#DECK API
PROJ_OBJ_CF2 += wheelDeck.o

5. Make a config.mk file in tools/make and add this line to it:
CFLAGS += -DDECK_FORCE=wheelDeck
"wheelDeck" is whatever you have named your deck.

This should work once it's compiled. For reference, I have the code on github here https://github.com/braraki/crazyflie-firmware
kristoffer
Bitcraze
Posts: 630
Joined: Tue Jun 30, 2015 7:47 am

Re: How to add new output to Crazyflie 2.0

Post by kristoffer »

Nice!

We have started to collect projects on https://www.hackster.io/bitcraze. It would be awesome if you added yours!

- Kristoffer
Post Reply