how to alter the controller's code

Discussions about quadcopters/multi-rotors
zjc515484158
Beginner
Posts: 3
Joined: Thu May 17, 2018 10:58 am

how to alter the controller's code

Post 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
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: how to alter the controller's code

Post 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.
zhoujincheng
Beginner
Posts: 8
Joined: Wed Sep 26, 2018 3:18 am

Re: how to alter the controller's code

Post 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:
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: how to alter the controller's code

Post 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).
zhoujincheng
Beginner
Posts: 8
Joined: Wed Sep 26, 2018 3:18 am

Re: how to alter the controller's code

Post by zhoujincheng »

and next , how can I modify the crazyflie client to control the servo rotate?
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: how to alter the controller's code

Post 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.
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: how to alter the controller's code

Post 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.
zhoujincheng
Beginner
Posts: 8
Joined: Wed Sep 26, 2018 3:18 am

Re: how to alter the controller's code

Post 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...
zhoujincheng
Beginner
Posts: 8
Joined: Wed Sep 26, 2018 3:18 am

Re: how to alter the controller's code

Post 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 ...
whoenig
Expert
Posts: 395
Joined: Mon Oct 27, 2014 2:55 am

Re: how to alter the controller's code

Post 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).
Post Reply