Page 1 of 2

how to alter the controller's code

Posted: Wed Sep 05, 2018 2:03 am
by zjc515484158
dear developers,
I want add two servos to the CF2 and now I don't know how to control them to rotate by a controller. Can you help me find the controller's code and alter it? :oops:
thanks very much

Re: how to alter the controller's code

Posted: Wed Sep 05, 2018 3:32 am
by whoenig
If it is a standard servo controlled by PWM, you can look at this code I wrote a while ago: https://github.com/USC-ACTLab/crazyflie ... ervodeck.c.

Re: how to alter the controller's code

Posted: Wed Sep 26, 2018 6:33 am
by zhoujincheng
thanks for your reply, and I have uploaded the servedeck.c program and add "PROJ_OBJ_CF2 += servodeck.o" to the Makefile. Then I connect the lines to the UAV, but the servo have no response. Can you tell me what should I do to control the servo work? :shock:

Re: how to alter the controller's code

Posted: Thu Sep 27, 2018 2:49 am
by whoenig
You also need to make sure that the deck driver gets actually loaded. Copy config.mk.example to config.mk (in crazyflie-firmware/blob/master/tools/make/). Then, add "CFLAGS += -DDECK_FORCE=bcServo" and recompile (you might need to do a clean build).

Re: how to alter the controller's code

Posted: Fri Oct 26, 2018 2:36 am
by zhoujincheng
and next , how can I modify the crazyflie client to control the servo rotate?

Re: how to alter the controller's code

Posted: Fri Oct 26, 2018 4:25 am
by arnaud
If your driver is accessible as a parameter you can modify the parameter value in the param tab of the client. This is more of a debug mode though.

Depending of how you want to control your servo the best is to run the client from its source code, find an existing functionality that matches what you want to do and dig in the code to find out how it is implemented. For example the client has functionalities to change the ledring color using a gamepad button, if you want to move the servo on a gamepad button you can look at the code implementing that and modify it for your needs.

If you tell us in a bit more details what functionality you want to implement in the client we can give you some pointers.

Re: how to alter the controller's code

Posted: Sat Oct 27, 2018 12:58 am
by whoenig
The driver exposes the PWM config (frequency and ratio) as parameters, see https://github.com/USC-ACTLab/crazyflie ... #L162-L165. Thus, you can use the parameter tab to change the settings. As arnaud said, any more high-level behavior might need some code changes.

Re: how to alter the controller's code

Posted: Sat Oct 27, 2018 6:43 am
by zhoujincheng
thanks you very much,I want realize a functionality that two servos rotate certain degree between -45° and 45 ° when I press a gamepad's button, two servos stop till I press the button again. I don't know where and how to change the client code...

Re: how to alter the controller's code

Posted: Tue Oct 30, 2018 7:10 am
by zhoujincheng
sorry for another question:if I want to add the second servo, should I add another servodeck2 ? or modify the servodeck's code? and how ...

Re: how to alter the controller's code

Posted: Wed Oct 31, 2018 12:24 am
by whoenig
Either works. The main challenge is to find another available pin that can do PWM in HW. The driver itself just configures the pin accordingly. I would suggest starting reading the documentation of the STM32, and trying to understand the existing servo code (you can ask specific questions here of course).