Controlling crazyflie motors from PC
Controlling crazyflie motors from PC
Hi everyone,
I am working on making a mathematical model of the crazyflie. To calculate some of the physical parameters of the crazyflie I would like to control the individual thrusts of each motor from the client. I have got the example python ramping script to work to ramp all motors and use the pitch,roll,yaw,thrust controls, but I want to be able to, for instance, get motor #1 to spin at 50% thrust, with other motors stopped.
Are there communication parameters that allow this? I have read through the developement docs and can't find an instruction for control that would allow this.
Thanks Freddy
I am working on making a mathematical model of the crazyflie. To calculate some of the physical parameters of the crazyflie I would like to control the individual thrusts of each motor from the client. I have got the example python ramping script to work to ramp all motors and use the pitch,roll,yaw,thrust controls, but I want to be able to, for instance, get motor #1 to spin at 50% thrust, with other motors stopped.
Are there communication parameters that allow this? I have read through the developement docs and can't find an instruction for control that would allow this.
Thanks Freddy
Re: Controlling crazyflie motors from PC
Hi Freddy,
No there is no API for controlling the motors individually yet. It could be added pretty easily though if you just want to set them to a fixed value for a while. How familiar are you with c programming?
In the distributePower function comment out the setting of the motors like this:
Then expose the motorPowerM* variables to the parameter framework by adding them to the bottom of the file:
Compile and flash the Crazyflie. You should then be a able to set these values from the parameters tab in the cfclient. If I remember correctly the max thrust is 65535 and not a uint32.
I have not tested this though so be a bit careful.
No there is no API for controlling the motors individually yet. It could be added pretty easily though if you just want to set them to a fixed value for a while. How familiar are you with c programming?
In the distributePower function comment out the setting of the motors like this:
Code: Select all
#else // QUAD_FORMATION_NORMAL
// motorPowerM1 = limitThrust(thrust + pitch + yaw);
// motorPowerM2 = limitThrust(thrust - roll - yaw);
// motorPowerM3 = limitThrust(thrust - pitch + yaw);
// motorPowerM4 = limitThrust(thrust + roll - yaw);
#endif
Code: Select all
// Params for motor thrust
PARAM_GROUP_START(motors)
PARAM_ADD(PARAM_UINT32, motorPowerM1, &motorPowerM1)
PARAM_ADD(PARAM_UINT32, motorPowerM2, &motorPowerM2)
PARAM_ADD(PARAM_UINT32, motorPowerM3, &motorPowerM3)
PARAM_ADD(PARAM_UINT32, motorPowerM4, &motorPowerM4)
PARAM_GROUP_STOP(motors)
I have not tested this though so be a bit careful.
Re: Controlling crazyflie motors from PC
Thanks tobias
I have been reading through the crazyflie info on the webpages and trying to find the actual firmware program for controlling it without any luck until I followed your link.
C programming is not a problem though I do have ONE question for you.
Is it possible to cause any damage (other than physical from crashing) to the crazyflie by changing the program? It is always possible to flash the original one back into it again and all will be good again I take it.
regards Freddy
I have been reading through the crazyflie info on the webpages and trying to find the actual firmware program for controlling it without any luck until I followed your link.
C programming is not a problem though I do have ONE question for you.
Is it possible to cause any damage (other than physical from crashing) to the crazyflie by changing the program? It is always possible to flash the original one back into it again and all will be good again I take it.
regards Freddy
Re: Controlling crazyflie motors from PC
No it is not possible to overwrite the bootloader so you can always program it even if the FW you programmed is corrupt.
-
- Beginner
- Posts: 11
- Joined: Mon Nov 23, 2015 7:10 am
Re: Controlling crazyflie motors from PC
tobias wrote:Hi Freddy,
No there is no API for controlling the motors individually yet. It could be added pretty easily though if you just want to set them to a fixed value for a while. How familiar are you with c programming?
In the distributePower function comment out the setting of the motors like this:Then expose the motorPowerM* variables to the parameter framework by adding them to the bottom of the file:Code: Select all
#else // QUAD_FORMATION_NORMAL // motorPowerM1 = limitThrust(thrust + pitch + yaw); // motorPowerM2 = limitThrust(thrust - roll - yaw); // motorPowerM3 = limitThrust(thrust - pitch + yaw); // motorPowerM4 = limitThrust(thrust + roll - yaw); #endif
Compile and flash the Crazyflie. You should then be a able to set these values from the parameters tab in the cfclient. If I remember correctly the max thrust is 65535 and not a uint32.Code: Select all
// Params for motor thrust PARAM_GROUP_START(motors) PARAM_ADD(PARAM_UINT32, motorPowerM1, &motorPowerM1) PARAM_ADD(PARAM_UINT32, motorPowerM2, &motorPowerM2) PARAM_ADD(PARAM_UINT32, motorPowerM3, &motorPowerM3) PARAM_ADD(PARAM_UINT32, motorPowerM4, &motorPowerM4) PARAM_GROUP_STOP(motors)
I have not tested this though so be a bit careful.
may i ask which c file in the firmware is to be edited for this code? Thanks
-
- Beginner
- Posts: 11
- Joined: Mon Nov 23, 2015 7:10 am
Re: Controlling crazyflie motors from PC
tobias wrote:Hi Freddy,
No there is no API for controlling the motors individually yet. It could be added pretty easily though if you just want to set them to a fixed value for a while. How familiar are you with c programming?
In the distributePower function comment out the setting of the motors like this:Then expose the motorPowerM* variables to the parameter framework by adding them to the bottom of the file:Code: Select all
#else // QUAD_FORMATION_NORMAL // motorPowerM1 = limitThrust(thrust + pitch + yaw); // motorPowerM2 = limitThrust(thrust - roll - yaw); // motorPowerM3 = limitThrust(thrust - pitch + yaw); // motorPowerM4 = limitThrust(thrust + roll - yaw); #endif
Compile and flash the Crazyflie. You should then be a able to set these values from the parameters tab in the cfclient. If I remember correctly the max thrust is 65535 and not a uint32.Code: Select all
// Params for motor thrust PARAM_GROUP_START(motors) PARAM_ADD(PARAM_UINT32, motorPowerM1, &motorPowerM1) PARAM_ADD(PARAM_UINT32, motorPowerM2, &motorPowerM2) PARAM_ADD(PARAM_UINT32, motorPowerM3, &motorPowerM3) PARAM_ADD(PARAM_UINT32, motorPowerM4, &motorPowerM4) PARAM_GROUP_STOP(motors)
I have not tested this though so be a bit careful.
I have tried to compile the code with this method and I still cannot control the motors individually after setting the param values. Am I missing something?
Thanks
Re: Controlling crazyflie motors from PC
Can it be that you have a CF2 which is in X configuration? Comment that as well and test
Code: Select all
#ifdef QUAD_FORMATION_X
int16_t r = roll >> 1;
int16_t p = pitch >> 1;
//motorPowerM1 = limitThrust(thrust - r + p + yaw);
//motorPowerM2 = limitThrust(thrust - r - p - yaw);
//motorPowerM3 = limitThrust(thrust + r - p + yaw);
//motorPowerM4 = limitThrust(thrust + r + p - yaw);
#else // QUAD_FORMATION_NORMAL
//motorPowerM1 = limitThrust(thrust + pitch + yaw);
//motorPowerM2 = limitThrust(thrust - roll - yaw);
//motorPowerM3 = limitThrust(thrust - pitch + yaw);
//motorPowerM4 = limitThrust(thrust + roll - yaw);
#endif
-
- Beginner
- Posts: 5
- Joined: Sat Oct 17, 2015 9:19 am
Re: Controlling crazyflie motors from PC
Hey,
I wish to also form a mathematical model and send direct commands to each of the crazyflie motors through an arduino. Will the above the method also work here?
I wish to also form a mathematical model and send direct commands to each of the crazyflie motors through an arduino. Will the above the method also work here?
Re: Controlling crazyflie motors from PC
Your best bet is actually to implement your model in the crazyflie firmware, it is capable of updating the motors much more frequently and with lower latency.