french cup + idf cup
[aversive.git] / projects / microb2010 / ballboard / cs.c
index 262f73c..35628d2 100644 (file)
@@ -45,6 +45,7 @@
 
 #include "main.h"
 #include "actuator.h"
+#include "beacon.h"
 
 int32_t encoders_spi_update_roller_speed(void *number)
 {
@@ -71,6 +72,8 @@ static void do_cs(void *dummy)
                        cs_manage(&ballboard.forktrans.cs);
                if (ballboard.forkrot.on)
                        cs_manage(&ballboard.forkrot.cs);
+               if (ballboard.beacon.on)
+                       cs_manage(&ballboard.beacon.cs);
        }
        if ((ballboard.flags & DO_BD) && (ballboard.flags & DO_POWER)) {
                bd_manage_from_cs(&ballboard.forktrans.bd, &ballboard.forktrans.cs);
@@ -79,6 +82,7 @@ static void do_cs(void *dummy)
                                         cs_get_filtered_feedback(&ballboard.roller.cs),
                                         cs_get_out(&ballboard.roller.cs));
 
+#if 0
                /* urgent case: stop power on blocking */
                if (ballboard.flags & DO_ERRBLOCKING) {
                        if (bd_get(&ballboard.forktrans.bd) ||
@@ -87,6 +91,7 @@ static void do_cs(void *dummy)
                                ballboard.flags &= ~(DO_POWER | DO_ERRBLOCKING);
                        }
                }
+#endif
        }
        if (ballboard.flags & DO_POWER)
                BRAKE_OFF();
@@ -178,8 +183,8 @@ void microb_cs_init(void)
 
        /* QUADRAMP */
        quadramp_init(&ballboard.forkrot.qr);
-       quadramp_set_1st_order_vars(&ballboard.forkrot.qr, 200, 800); /* set speed */
-       quadramp_set_2nd_order_vars(&ballboard.forkrot.qr, 20, 20); /* set accel */
+       quadramp_set_1st_order_vars(&ballboard.forkrot.qr, 1000, 500); /* set speed */
+       quadramp_set_2nd_order_vars(&ballboard.forkrot.qr, 100, 20); /* set accel */
 
        /* CS */
        cs_init(&ballboard.forkrot.cs);
@@ -194,10 +199,27 @@ void microb_cs_init(void)
        bd_set_speed_threshold(&ballboard.forkrot.bd, 150);
        bd_set_current_thresholds(&ballboard.forkrot.bd, 500, 8000, 1000000, 200);
 
+       /* BEACON */
+
+       /* PID */
+       pid_init(&ballboard.beacon.pid);
+       pid_set_gains(&ballboard.beacon.pid, 80, 80, 250);
+       pid_set_maximums(&ballboard.beacon.pid, 0, 10000, 1500);
+       pid_set_out_shift(&ballboard.beacon.pid, 6);
+       pid_set_derivate_filter(&ballboard.beacon.pid, 6);
+
+       /* CS */
+       cs_init(&ballboard.beacon.cs);
+       cs_set_correct_filter(&ballboard.beacon.cs, pid_do_filter, &ballboard.beacon.pid);
+       cs_set_process_in(&ballboard.beacon.cs, pwm_ng_set, BEACON_PWM);
+       cs_set_process_out(&ballboard.beacon.cs, encoders_spi_update_beacon_speed, BEACON_ENCODER);
+       cs_set_consign(&ballboard.beacon.cs, 0);
+
        /* set them on !! */
        ballboard.roller.on = 1;
        ballboard.forktrans.on = 1;
        ballboard.forkrot.on = 0;
+       ballboard.beacon.on = 0;
 
 
        scheduler_add_periodical_event_priority(do_cs, NULL,