X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=blobdiff_plain;f=projects%2Fmicrob2010%2Fcobboard%2Fshovel.c;h=e06638d1d060a60147be0ef1acabcae551fd9bef;hp=6d71e5876834f256d7a16fcc3c2cbbc1472874bf;hb=04f1061f2c5959ce87f632591576097f540dfc14;hpb=fa8546ea39c7442ad3bf5a822a72a2b50a41045d diff --git a/projects/microb2010/cobboard/shovel.c b/projects/microb2010/cobboard/shovel.c index 6d71e58..e06638d 100644 --- a/projects/microb2010/cobboard/shovel.c +++ b/projects/microb2010/cobboard/shovel.c @@ -1,6 +1,6 @@ -/* +/* * Copyright Droids Corporation (2010) - * + * * 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 @@ -40,8 +40,19 @@ #include #include "main.h" +#include "state.h" #include "shovel.h" +#define SHOVEL_DOWN 100 +#define SHOVEL_MID 4500 +#define SHOVEL_UP 11300 +#define SHOVEL_KICKSTAND_UP 13400 +#define SHOVEL_KICKSTAND_DOWN 10400 + +static int32_t shovel_k1 = 1000; +static int32_t shovel_k2 = 20; +static uint8_t shovel_current_limit = 1; + /* init spickle position at beginning */ static void shovel_autopos(void) { @@ -64,6 +75,96 @@ static uint8_t shovel_is_at_pos(int32_t pos) return 0; } +void shovel_set_current_limit_coefs(int32_t k1, int32_t k2) +{ + shovel_k1 = k1; + shovel_k2 = k2; +} + +uint8_t shovel_get_current_limit_coefs(int32_t *k1, int32_t *k2) +{ + *k1 = shovel_k1; + *k2 = shovel_k2; + return shovel_current_limit; +} + +void shovel_current_limit_enable(uint8_t enable) +{ + shovel_current_limit = enable; +} + +/* Set CS command for shovel. Called by CS manager. */ +void shovel_set(void *mot, int32_t cmd) +{ + static int32_t oldpos; + int32_t pos, maxcmd, speed; + + pos = encoders_spi_get_value(SHOVEL_ENCODER); + if (shovel_current_limit) { + speed = pos - oldpos; + if (speed > 0 && cmd < 0) + maxcmd = shovel_k1; + else if (speed < 0 && cmd > 0) + maxcmd = shovel_k1; + else { + speed = ABS(speed); + maxcmd = shovel_k1 + shovel_k2 * speed; + } + if (cmd > maxcmd) + cmd = maxcmd; + else if (cmd < -maxcmd) + cmd = -maxcmd; + } + + pwm_ng_set(mot, cmd); + oldpos = pos; +} + +void shovel_down(void) +{ + shovel_current_limit_enable(0); + quadramp_set_1st_order_vars(&cobboard.shovel.qr, 2500, 2500); + quadramp_set_2nd_order_vars(&cobboard.shovel.qr, 50, 80); + cs_set_consign(&cobboard.shovel.cs, SHOVEL_DOWN); +} + +void shovel_mid(void) +{ + shovel_current_limit_enable(0); + quadramp_set_1st_order_vars(&cobboard.shovel.qr, 2500, 2500); + quadramp_set_2nd_order_vars(&cobboard.shovel.qr, 80, 80); + cs_set_consign(&cobboard.shovel.cs, SHOVEL_MID); +} + +void shovel_up(void) +{ + shovel_current_limit_enable(0); + if (state_get_cob_count() <= 1) + quadramp_set_1st_order_vars(&cobboard.shovel.qr, 700, 2500); + else + quadramp_set_1st_order_vars(&cobboard.shovel.qr, 1000, 2500); + quadramp_set_2nd_order_vars(&cobboard.shovel.qr, 80, 15); + cs_set_consign(&cobboard.shovel.cs, SHOVEL_UP); +} + +void shovel_kickstand_up(void) +{ + shovel_set_current_limit_coefs(1000, 20); + shovel_current_limit_enable(1); + quadramp_set_1st_order_vars(&cobboard.shovel.qr, 200, 200); + quadramp_set_2nd_order_vars(&cobboard.shovel.qr, 10, 10); + cs_set_consign(&cobboard.shovel.cs, SHOVEL_KICKSTAND_UP); +} + +void shovel_kickstand_down(void) +{ + shovel_set_current_limit_coefs(500, 0); + shovel_current_limit_enable(1); + quadramp_set_1st_order_vars(&cobboard.shovel.qr, 200, 200); + quadramp_set_2nd_order_vars(&cobboard.shovel.qr, 10, 10); + cs_set_consign(&cobboard.shovel.cs, SHOVEL_KICKSTAND_DOWN); +} + uint8_t shovel_is_up(void) { return shovel_is_at_pos(SHOVEL_UP); @@ -74,6 +175,11 @@ uint8_t shovel_is_down(void) return shovel_is_at_pos(SHOVEL_DOWN); } +uint8_t shovel_is_mid(void) +{ + return shovel_is_at_pos(SHOVEL_MID); +} + void shovel_init(void) { shovel_autopos();