The unified diff between revisions [23a3e9a5..] and [d0420ebd..] is displayed below. It can also be downloaded as a raw diff.

This diff has been restricted to the following files: 'dcm.c'

#
# old_revision [23a3e9a50b4034343e3bd217d2c225dcaec064dd]
# new_revision [d0420ebd87c820e33a32b29727989516e15980a8]
#
# patch "dcm.c"
#  from [35a44d5b49a5c9bf56678ae7af0b611fde405621]
#    to [34486e2e7948509c6f2648d365feb84c22ab5b14]
#
============================================================
--- dcm.c	35a44d5b49a5c9bf56678ae7af0b611fde405621
+++ dcm.c	34486e2e7948509c6f2648d365feb84c22ab5b14
@@ -8,6 +8,7 @@
 #include "matrix.h"
 #include "dcm.h"
 #include "uart.h"
+#include "motor.h"
 
 #define GRAVITY 9.80665f
 
@@ -27,13 +28,15 @@ float omega_i[3] = {0.0, 0.0, 0.0};
 float omega_p[3] = {0.0, 0.0, 0.0};
 float omega_i[3] = {0.0, 0.0, 0.0};
 
+float omega_x, omega_y, omega_z;
+
 float delta_t = 0.01;
 
 void dcm_update(float x, float y, float z)
 {
-	float omega_x = x + omega_i[0] + omega_p[0];
-	float omega_y = y + omega_i[1] + omega_p[1];
-	float omega_z = z + omega_i[2] + omega_p[2];
+	omega_x = x + omega_i[0] + omega_p[0];
+	omega_y = y + omega_i[1] + omega_p[1];
+	omega_z = z + omega_i[2] + omega_p[2];
 
 	float tx = delta_t * omega_x;
 	float ty = delta_t * omega_y;
@@ -182,9 +185,12 @@ void dcm_drift_correction(float x, float
 		omega_i[i] += error[i] * (KI_ROLLPITCH * weight);
 	}
 
+#if 0
 	putstr("w: ");
 	putint_s((int)(weight * 100000.0f));
 	putstr("\r\n");
+#endif
+
 #if 0
 	putstr("p: ");
 	putint_s((int)(omega_p[0] * 100000.0f));
@@ -202,6 +208,22 @@ void dcm_drift_correction(float x, float
 #endif
 }
 
+void dcm_attitude_error(float roll, float pitch, float yaw)
+{
+	/* dcm[6] = sine of pitch */
+	/* dcm[7] = sine of roll */
+
+	/* pitch error = pitch - dcm[6] */
+	/* roll error = roll - dcm[7] */
+
+	/* That was the theory. In practice, there appears to be some
+	   confusion over axes. Pitch and roll seem.. reversed. */
+
+	/* TODO: What if we are upside down? */
+
+	motor_pid_update(roll, dcm[6], pitch, -dcm[7], yaw, -omega_z);
+}
+
 void dcm_dump(void)
 {
 	putstr("dcm: ");