how to alter the controller's code
-
- Beginner
- Posts: 3
- Joined: Thu May 17, 2018 10:58 am
how to alter the controller's code
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?
thanks very much
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?
thanks very much
Re: how to alter the controller's code
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.
-
- Beginner
- Posts: 8
- Joined: Wed Sep 26, 2018 3:18 am
Re: how to alter the controller's code
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?
Re: how to alter the controller's code
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).
-
- Beginner
- Posts: 8
- Joined: Wed Sep 26, 2018 3:18 am
Re: how to alter the controller's code
and next , how can I modify the crazyflie client to control the servo rotate?
Re: how to alter the controller's code
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.
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
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.
-
- Beginner
- Posts: 8
- Joined: Wed Sep 26, 2018 3:18 am
Re: how to alter the controller's code
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...
-
- Beginner
- Posts: 8
- Joined: Wed Sep 26, 2018 3:18 am
Re: how to alter the controller's code
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
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).