debug cpld
[aversive.git] / projects / microb2010 / mainboard / cs.c
index 516f00b..6ef8fe9 100644 (file)
@@ -80,6 +80,15 @@ int32_t encoders_right_cobroller_speed(void *number)
 }
 #endif
 
+#ifndef HOST_VERSION
+#define DEBUG_CPLD
+#endif
+
+#ifdef DEBUG_CPLD
+extern int16_t g_encoders_spi_previous[4];
+static int32_t ll_prev, rr_prev;
+#endif
+
 /* called every 5 ms */
 static void do_cs(void *dummy)
 {
@@ -89,10 +98,29 @@ static void do_cs(void *dummy)
 #ifdef HOST_VERSION
        robotsim_update();
 #else
+#ifdef DEBUG_CPLD
+       int32_t ll, rr;
+#endif
        /* read encoders */
        if (mainboard.flags & DO_ENCODERS) {
                encoders_spi_manage(NULL);
        }
+#ifdef DEBUG_CPLD
+       ll = encoders_spi_get_value(LEFT_ENCODER);
+       rr = encoders_spi_get_value(RIGHT_ENCODER);
+       if ((ll - ll_prev > 3000) || (ll - ll_prev < -3000) ||
+           (rr - rr_prev > 3000) || (rr - rr_prev < -3000)) {
+               printf_P(PSTR("/ %d %d %d %d\r\n"),
+                        g_encoders_spi_previous[0],
+                        g_encoders_spi_previous[1],
+                        g_encoders_spi_previous[2],
+                        g_encoders_spi_previous[3]);
+               BRAKE_ON();
+               while (1);
+       }
+       ll_prev = ll;
+       rr_prev = rr;
+#endif
 #endif
 
        /* robot system, conversion to angle,distance */
@@ -224,7 +252,7 @@ void microb_cs_init(void)
        position_init(&mainboard.pos);
        position_set_physical_params(&mainboard.pos, VIRTUAL_TRACK_MM, DIST_IMP_MM);
        position_set_related_robot_system(&mainboard.pos, &mainboard.rs);
-       position_set_centrifugal_coef(&mainboard.pos, 0.000016);
+       //      position_set_centrifugal_coef(&mainboard.pos, 0.000016);
        position_use_ext(&mainboard.pos);
 
        /* TRAJECTORY MANAGER */
@@ -240,8 +268,8 @@ void microb_cs_init(void)
        /* ---- CS angle */
        /* PID */
        pid_init(&mainboard.angle.pid);
-       pid_set_gains(&mainboard.angle.pid, 500, 10, 7000);
-       pid_set_maximums(&mainboard.angle.pid, 0, 20000, 4095);
+       pid_set_gains(&mainboard.angle.pid, 850, 30, 15000);
+       pid_set_maximums(&mainboard.angle.pid, 0, 10000, 4095);
        pid_set_out_shift(&mainboard.angle.pid, 10);
        pid_set_derivate_filter(&mainboard.angle.pid, 4);
 
@@ -266,8 +294,8 @@ void microb_cs_init(void)
        /* ---- CS distance */
        /* PID */
        pid_init(&mainboard.distance.pid);
-       pid_set_gains(&mainboard.distance.pid, 500, 10, 7000);
-       pid_set_maximums(&mainboard.distance.pid, 0, 2000, 4095);
+       pid_set_gains(&mainboard.distance.pid, 850, 30, 15000);
+       pid_set_maximums(&mainboard.distance.pid, 0, 10000, 4095);
        pid_set_out_shift(&mainboard.distance.pid, 10);
        pid_set_derivate_filter(&mainboard.distance.pid, 6);
 
@@ -337,8 +365,13 @@ void microb_cs_init(void)
        mainboard.left_cobroller.on = 1;
        mainboard.right_cobroller.on = 1;
 
+#ifdef DEBUG_CPLD
+       ll_prev = encoders_spi_get_value(LEFT_ENCODER);
+       rr_prev = encoders_spi_get_value(RIGHT_ENCODER);
+#endif
 
        scheduler_add_periodical_event_priority(do_cs, NULL,
                                                5000L / SCHEDULER_UNIT,
                                                CS_PRIO);
+
 }