weak current limit on spickles
[aversive.git] / projects / microb2010 / cobboard / cs.c
index 0ed2f1a..386b360 100644 (file)
@@ -1,7 +1,7 @@
-/*  
+/*
  *  Copyright Droids Corporation
  *  Olivier Matz <zer0@droids-corp.org>
- * 
+ *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  the Free Software Foundation; either version 2 of the License, or
@@ -46,8 +46,7 @@
 #include "main.h"
 #include "actuator.h"
 #include "spickle.h"
-
-#define DEBUG_CPLD
+#include "shovel.h"
 
 /* called every 5 ms */
 static void do_cs(__attribute__((unused)) void *dummy)
@@ -56,11 +55,7 @@ static void do_cs(__attribute__((unused)) void *dummy)
        if (cobboard.flags & DO_ENCODERS) {
                encoders_spi_manage(NULL);
        }
-#ifdef DEBUG_CPLD
-       cobboard.left_spickle.prev = cobboard.left_spickle.cs.filtered_feedback_value;
-       cobboard.right_spickle.prev = cobboard.right_spickle.cs.filtered_feedback_value;
-       cobboard.shovel.prev = cobboard.shovel.cs.filtered_feedback_value;
-#endif
+
        /* control system */
        if (cobboard.flags & DO_CS) {
                if (cobboard.left_spickle.on)
@@ -70,30 +65,6 @@ static void do_cs(__attribute__((unused)) void *dummy)
                if (cobboard.shovel.on)
                        cs_manage(&cobboard.shovel.cs);
        }
-#ifdef DEBUG_CPLD
-       {
-               extern int16_t g_encoders_spi_previous[4];
-               int32_t ls, rs, sh;
-
-               ls = (cobboard.left_spickle.prev - cobboard.left_spickle.cs.filtered_feedback_value);
-               rs = (cobboard.right_spickle.prev - cobboard.right_spickle.cs.filtered_feedback_value);
-               sh = (cobboard.shovel.prev - cobboard.shovel.cs.filtered_feedback_value);
-               if (ls < -2000 || ls > 2000 ||
-                   rs < -2000 || rs > 2000 ||
-                   sh < -2000 || sh > 2000) {
-                       printf_P(PSTR("left_spickle %ld "), ls);
-                       printf_P(PSTR("right_spickle %ld "), rs);
-                       printf_P(PSTR("shovel %ld "), sh);
-                       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);
-               }
-       }
-#endif
 
        if ((cobboard.flags & DO_BD) && (cobboard.flags & DO_POWER)) {
                bd_manage_from_cs(&cobboard.left_spickle.bd, &cobboard.left_spickle.cs);
@@ -102,12 +73,12 @@ static void do_cs(__attribute__((unused)) void *dummy)
 
                /* urgent case: stop power on blocking */
                if (cobboard.flags & DO_ERRBLOCKING) {
-                       if (/* bd_get(&cobboard.left_spickle.bd) || */
-                           /* bd_get(&cobboard.right_spickle.bd) || */
-                           bd_get(&cobboard.shovel.bd)) {
-                               printf_P(PSTR("MOTOR BLOCKED STOP ALL\r\n"));
-                               cobboard.flags &= ~(DO_POWER | DO_ERRBLOCKING);
-                       }
+/*                     if (bd_get(&cobboard.left_spickle.bd) || */
+/*                         bd_get(&cobboard.right_spickle.bd) || */
+/*                         bd_get(&cobboard.shovel.bd)) { */
+/*                             printf_P(PSTR("MOTOR BLOCKED STOP ALL\r\n")); */
+/*                             cobboard.flags &= ~(DO_POWER | DO_ERRBLOCKING); */
+/*                     } */
                }
        }
        if (cobboard.flags & DO_POWER)
@@ -196,14 +167,14 @@ void microb_cs_init(void)
 
        /* quadramp */
        quadramp_init(&cobboard.shovel.qr);
-       quadramp_set_1st_order_vars(&cobboard.shovel.qr, 2000, 2000); /* set speed */
+       quadramp_set_1st_order_vars(&cobboard.shovel.qr, 2500, 2500); /* set speed */
        quadramp_set_2nd_order_vars(&cobboard.shovel.qr, 50, 20); /* set accel */
 
        /* CS */
        cs_init(&cobboard.shovel.cs);
        cs_set_consign_filter(&cobboard.shovel.cs, quadramp_do_filter, &cobboard.shovel.qr);
        cs_set_correct_filter(&cobboard.shovel.cs, pid_do_filter, &cobboard.shovel.pid);
-       cs_set_process_in(&cobboard.shovel.cs, pwm_ng_set, SHOVEL_PWM);
+       cs_set_process_in(&cobboard.shovel.cs, shovel_set, SHOVEL_PWM);
        cs_set_process_out(&cobboard.shovel.cs, encoders_spi_get_value, SHOVEL_ENCODER);
        cs_set_consign(&cobboard.shovel.cs, 0);