Controlling crazyflie motors from PC

Firmware/software/electronics/mechanics
Freddy
Beginner
Posts: 9
Joined: Tue Nov 26, 2013 10:33 pm

Controlling crazyflie motors from PC

Post 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
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Controlling crazyflie motors from PC

Post 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.
Freddy
Beginner
Posts: 9
Joined: Tue Nov 26, 2013 10:33 pm

Re: Controlling crazyflie motors from PC

Post by Freddy »

Thanks tobias :D

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
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Controlling crazyflie motors from PC

Post 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.
geffaelden
Beginner
Posts: 11
Joined: Mon Nov 23, 2015 7:10 am

Re: Controlling crazyflie motors from PC

Post 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
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Controlling crazyflie motors from PC

Post by tobias »

geffaelden
Beginner
Posts: 11
Joined: Mon Nov 23, 2015 7:10 am

Re: Controlling crazyflie motors from PC

Post 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
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Controlling crazyflie motors from PC

Post 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
muhamriaz4
Beginner
Posts: 5
Joined: Sat Oct 17, 2015 9:19 am

Re: Controlling crazyflie motors from PC

Post 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?
Analogy
Beginner
Posts: 19
Joined: Fri Oct 24, 2014 6:55 am

Re: Controlling crazyflie motors from PC

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