CrazyFlie comms protocols

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

CrazyFlie comms protocols

Post by Freddy »

Hi,

I am having a bit of difficulty with fully underrstanding the comms protocols for sending and receiving setpoints. I want to change the data in the setpoint to include more parameters as part of development of the control system. For example send P I and D values for the PID controller and also an altititude, so say 4 floating point numbers
setpoint(roll,pitch,yaw,thrust,P,I,D,altitude) for instance.

If i understand correctly, input.py uses these commands to send the setpoint using:

Line:101 sendControlSetpointSignal = pyqtSignal(float, float, float, int)
Line:296 self.sendControlSetpointSignal.emit(trimmed_rol, trimmed_pitch, yaw, thrust)[/color]

Assuming I have the variables taken care of correctly and the firmware updated to handle the incoming new setpoint, can I just change this code to:

Line:101 sendControlSetpointSignal = pyqtSignal(float, float, float, int, float, float, float,float)
Line:296 self.sendControlSetpointSignal.emit(trimmed_rol, trimmed_pitch, yaw, thrust, P, I, D, altitude)

or will there be consequences to this alteration that I am missing somewhere?


At the CrazyFlie end I think commander.c is receiving the setpoint data with:

void commanderGetRPY(float* eulerRollDesired, float* eulerPitchDesired, float* eulerYawDesired)
{
int usedSide = side;

*eulerRollDesired = targetVal[usedSide].roll;
*eulerPitchDesired = targetVal[usedSide].pitch;
*eulerYawDesired = targetVal[usedSide].yaw;
}

void commanderGetRPYType(RPYType* rollType, RPYType* pitchType, RPYType* yawType)
{
*rollType = ANGLE;
*pitchType = ANGLE;
*yawType = RATE;
}

void commanderGetThrust(uint16_t* thrust)
{
int usedSide = side;
uint16_t rawThrust = targetVal[usedSide].thrust;

Can I just add something like this after the commanderGetThrust:

void commanderGetPIDandAlt(float P, float I,float D,float Altitude)
{
P=targetVal[usedSide].P;
I=tagetVal[usedSide].I;
D=targetVal[usedSide].D;
Altitude=targetVal[usedSide].Altitide;
}

My brain can not handle programming in C and Python at the same time without overheating. Any help would be much appreciated!

Thanks Freddy
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: CrazyFlie comms protocols

Post by arnaud »

Hi Freddy,

The commander protocol is currently documented in the wiki http://wiki.bitcraze.se/projects:crazyf ... m_protocol, the commands are divided in ports which allows to route the package to the right subsystem on the copter and client. So if you want to add things to the controller packets the only place you have to look at are /lib/cflib/crazyflie/commander.py in the client and /modules/src/commander.c in the copter (of course you will also have use-case specifics modification at other places, but these two files are the only one involved directly with the commander communication packet). You need to make sure that "pk.data = struct.pack('<fffH', roll, -pitch, yaw, thrust)" of the client shall stay in synch with "struct CommanderCrtpValues" in the copter. Be aware that the commander on the copter is implementing a crude double buffering mechanism, the only place where it is safe to read the commander structure is in the "commanderGetRPY" function.

Modifying the controller packet format will make your client incompatible with 'stock' crazyflie so be careful at what you use it with. The safe way is to add variable at the end of the packet, adding them in the middle will be dangerous if you connect a copter running the sock firmware (you would set the thrust at random values ...).

As for your example, we have created the param subsystem to allow controlling variables in the copter without requiring this kind of protocol modification. The pid controller is already accessible via the parameters subsystem (see parameter tab in the client, pid_attitude and pid_rate groups). It would be easier controlling as much as possible things with the param subsystem: http://wiki.bitcraze.se/projects:crazyf ... arameters1
Freddy
Beginner
Posts: 9
Joined: Tue Nov 26, 2013 10:33 pm

Re: CrazyFlie comms protocols

Post by Freddy »

Thanks arnuad,
all sorted out now, well nearly :)
Post Reply