#include <rdline.h>
#include "main.h"
+#include "state.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)
+{
+ if (state_get_cob_count() <= 1)
+ quadramp_set_1st_order_vars(&cobboard.shovel.qr, 1000, 2500);
+ else
+ 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)