Firmware: Difference between revisions

From Distributed Autonomous and Networked Control Lab
Jump to navigation Jump to search
Jnoronha (talk | contribs)
Jnoronha (talk | contribs)
finished yaw modification section (still missing final FIRMWARE yaw change code)
Line 1: Line 1:
Not much work has been done in the Firmware yet. (as of 7/20/16) The few things we have been able to successfully modify are:
Not much work has been done in the Firmware yet (as of 7/20/16). The few things we have been able to successfully modify are:


#Creating New Log Blocks
#Creating New Log Blocks
Line 48: Line 48:
===Using New Log Blocks in Swarm Client===
===Using New Log Blocks in Swarm Client===
Now that we have these new log blocks in the Firmware, we can [[:Logging#New Client Log Blocks|use log blocks in the Client]]
Now that we have these new log blocks in the Firmware, we can [[:Logging#New Client Log Blocks|use log blocks in the Client]]
==Modify the Default Yaw Mode==
There are 3 types of Yaw Modes available in the Firmware (as of 7/21/16), as shown (code in ''Firmware > modules > interface > commander.h'')
<blockquote>
<code>
<pre>
typedef enum
{
  CAREFREE  = 0, // Yaw is locked to world coordinates thus heading stays the same when yaw rotates
  PLUSMODE  = 1, // Plus-mode. Motor M1 is defined as front
  XMODE    = 2, // X-mode. M1 & M4 is defined as front
} YawModeType;
</pre>
</code>
</blockquote>
:'''Note:''' The default mode for the Crazyflie 2.0 is ''XMODE''. The ''PLUSMODE'' is default for the Crazyflie 1.0, but can still be used on the Crazyflie 2.0 if desired.
===Carefree Mode===
''CAREFREE'' mode is what our Crazyflie 2.0's are using, this mode applies a transformation to the Pitch and Roll setpoints depending on the angle of Yaw. We used to perform this calculation on the Client like this (code in ''eris_vrpn.cpp''):
<blockquote>
<code>
<pre>
#if USE_PR_YAW_CORRECT
//CORRECTS PITCH AND ROLL PID ERRORS TO ACCOUNT FOR QUADS CURRENT YAW DIRECTION (_/57.2958 converts DEG to RADIANS)
xError2 = cos(correctedYaw2 / 57.2958)*(xPositionDesired2 - xPosition2) - sin(correctedYaw2 / 57.2958)*(yPositionDesired2 - yPosition2);
yError2 = sin(correctedYaw2 / 57.2958)*(xPositionDesired2 - xPosition2) + cos(correctedYaw2 / 57.2958)*(yPositionDesired2 - yPosition2);
#else
xError2 = xPositionDesired2 - xPosition2;
yError2 = yPositionDesired2 - yPosition2;
#endif
controllerSetXYError(&pidCtrl2, xError2, yError2);
</pre>
</code>
</blockquote>
This is no longer necessary on the Client because this is the exact same calculation ''CAREFREE'' mode performs on the Firmware. So this reduces the computation done on the Client in each Crazyflie Callback.
====Changing Yaw Mode in Firmware====
To change the Yaw Mode to ''CAREFREE'' mode we had to make the modification shown (code in ''Firmware > modules > src > commander.c''):
<blockquote>
<code>
<pre>
***INSERT CODE CHANGE***
</pre>
</code>
</blockquote>





Revision as of 17:50, 21 July 2016

Not much work has been done in the Firmware yet (as of 7/20/16). The few things we have been able to successfully modify are:

  1. Creating New Log Blocks
  2. Modifying the Default Yaw Mode
  3. Adding and Modifying Parameter Values

New Firmware Log Blocks

In the Crazyflie Firmware there is a generalized logging framework that allows us to make any group of variables into a log block. It makes things very easy to log. Here are a few examples:

Ex. 1. Magnometer Log Block (code found in Firmware > modules > src > stabilizer.c)


LOG_GROUP_START(mag)
LOG_ADD(LOG_FLOAT, x, &mag.x)
LOG_ADD(LOG_FLOAT, y, &mag.y)
LOG_ADD(LOG_FLOAT, z, &mag.z)
LOG_GROUP_STOP(mag)

So with this code we have created a log block called 'mag' and it contains the X, Y, and Z measurements from the magnetometer sensor.
Ex. 2. Accelerometer Log Block (code found in Firmware > modules > src > stabilizer.c)


LOG_GROUP_START(acc)
LOG_ADD(LOG_FLOAT, x, &acc.x)
LOG_ADD(LOG_FLOAT, y, &acc.y)
LOG_ADD(LOG_FLOAT, z, &acc.z)
LOG_ADD(LOG_FLOAT, zw, &accWZ)
LOG_ADD(LOG_FLOAT, mag2, &accMAG)
LOG_GROUP_STOP(acc)

Just like in the magnetometer block, here we have created a log group called 'acc' and inside this group we are logging the variables for the accelerometer's X, Y, and Z values as well as 2 other gravity based variables used for thrust compensation.

Using New Log Blocks in Swarm Client

Now that we have these new log blocks in the Firmware, we can use log blocks in the Client


Modify the Default Yaw Mode

There are 3 types of Yaw Modes available in the Firmware (as of 7/21/16), as shown (code in Firmware > modules > interface > commander.h)


typedef enum
{
  CAREFREE  = 0, // Yaw is locked to world coordinates thus heading stays the same when yaw rotates
  PLUSMODE  = 1, // Plus-mode. Motor M1 is defined as front
  XMODE     = 2, // X-mode. M1 & M4 is defined as front
} YawModeType;

Note: The default mode for the Crazyflie 2.0 is XMODE. The PLUSMODE is default for the Crazyflie 1.0, but can still be used on the Crazyflie 2.0 if desired.

Carefree Mode

CAREFREE mode is what our Crazyflie 2.0's are using, this mode applies a transformation to the Pitch and Roll setpoints depending on the angle of Yaw. We used to perform this calculation on the Client like this (code in eris_vrpn.cpp):


#if USE_PR_YAW_CORRECT
	//CORRECTS PITCH AND ROLL PID ERRORS TO ACCOUNT FOR QUADS CURRENT YAW DIRECTION (_/57.2958 converts DEG to RADIANS)
	xError2 = cos(correctedYaw2 / 57.2958)*(xPositionDesired2 - xPosition2) - sin(correctedYaw2 / 57.2958)*(yPositionDesired2 - yPosition2);	
	yError2 = sin(correctedYaw2 / 57.2958)*(xPositionDesired2 - xPosition2) + cos(correctedYaw2 / 57.2958)*(yPositionDesired2 - yPosition2);
#else
	xError2 = xPositionDesired2 - xPosition2;
	yError2 = yPositionDesired2 - yPosition2;
#endif

	controllerSetXYError(&pidCtrl2, xError2, yError2);

This is no longer necessary on the Client because this is the exact same calculation CAREFREE mode performs on the Firmware. So this reduces the computation done on the Client in each Crazyflie Callback.

Changing Yaw Mode in Firmware

To change the Yaw Mode to CAREFREE mode we had to make the modification shown (code in Firmware > modules > src > commander.c):


***INSERT CODE CHANGE***



Main Directory
Crazyflie Swarm Home | PC Client Software | USB Radio | Firmware | FAQ
Modifications Directory
Controller | Logging | Keyboard Commands | Changing Radio Channel | Flight Modes | Callbacks | Adding a Crazyflie | Firmware