X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=blobdiff_plain;f=projects%2Fmicrob2010%2Fcobboard%2Fshovel.c;h=42ab78bce33c89b094357edf05064b5efd41a471;hp=39ce2bc33de99dc4e185c7e17844196d44861ee6;hb=5d21466eb434aa44eeb334a19668c58ffef5665f;hpb=57b3e145f2ff46e1a7e7d522c85f3c56821dbf48 diff --git a/projects/microb2010/cobboard/shovel.c b/projects/microb2010/cobboard/shovel.c index 39ce2bc..42ab78b 100644 --- a/projects/microb2010/cobboard/shovel.c +++ b/projects/microb2010/cobboard/shovel.c @@ -40,14 +40,63 @@ #include #include "main.h" +#include "shovel.h" + +#define SHOVEL_DOWN 100 +#define SHOVEL_MID 4500 +#define SHOVEL_UP 11000 /* init spickle position at beginning */ static void shovel_autopos(void) { + printf_P(PSTR("shovel autopos...")); pwm_ng_set(SHOVEL_PWM, -500); wait_ms(1000); pwm_ng_set(LEFT_SPICKLE_PWM, 0); encoders_spi_set_value(SHOVEL_ENCODER, 0); + printf_P(PSTR("ok\r\n")); +} + +static uint8_t shovel_is_at_pos(int32_t pos) +{ + int32_t diff; + diff = pos - encoders_spi_get_value(SHOVEL_ENCODER); + if (diff < 0) + diff = -diff; + if (diff < 500) + return 1; + return 0; +} + +void shovel_down(void) +{ + 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) +{ + 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) +{ + quadramp_set_1st_order_vars(&cobboard.shovel.qr, 2000, 2500); + quadramp_set_2nd_order_vars(&cobboard.shovel.qr, 80, 15); + cs_set_consign(&cobboard.shovel.cs, SHOVEL_UP); +} + +uint8_t shovel_is_up(void) +{ + return shovel_is_at_pos(SHOVEL_UP); +} + +uint8_t shovel_is_down(void) +{ + return shovel_is_at_pos(SHOVEL_DOWN); } void shovel_init(void)