Page 1 of 2
Controlling crazyflie motors from PC
Posted: Tue Nov 26, 2013 10:43 pm
by Freddy
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
Re: Controlling crazyflie motors from PC
Posted: Fri Nov 29, 2013 8:18 am
by tobias
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:
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
Then expose the motorPowerM* variables to the parameter framework by adding them to the bottom of the file:
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)
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.
Re: Controlling crazyflie motors from PC
Posted: Sat Nov 30, 2013 2:44 pm
by Freddy
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
Re: Controlling crazyflie motors from PC
Posted: Tue Dec 03, 2013 8:11 am
by tobias
No it is not possible to overwrite the bootloader so you can always program it even if the FW you programmed is corrupt.
Re: Controlling crazyflie motors from PC
Posted: Tue Nov 24, 2015 4:20 am
by geffaelden
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:
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
Then expose the motorPowerM* variables to the parameter framework by adding them to the bottom of the file:
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)
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.
may i ask which c file in the firmware is to be edited for this code? Thanks
Re: Controlling crazyflie motors from PC
Posted: Tue Nov 24, 2015 12:22 pm
by tobias
Re: Controlling crazyflie motors from PC
Posted: Tue Feb 02, 2016 6:21 am
by geffaelden
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:
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
Then expose the motorPowerM* variables to the parameter framework by adding them to the bottom of the file:
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)
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.
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
Posted: Tue Feb 02, 2016 12:21 pm
by tobias
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
Re: Controlling crazyflie motors from PC
Posted: Sun Feb 14, 2016 7:50 am
by muhamriaz4
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?
Re: Controlling crazyflie motors from PC
Posted: Mon Feb 15, 2016 7:33 am
by Analogy
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.