state_set_mode(I2C_COBBOARD_MODE_HARVEST);
state_set_spickle(side, 0);
}
+ else if (!strcmp_P(res->arg1, PSTR("weak_pack"))) {
+ state_set_mode(I2C_COBBOARD_MODE_HARVEST);
+ state_set_spickle(side, I2C_COBBOARD_SPK_WEAK);
+ }
else if (!strcmp_P(res->arg1, PSTR("deploy"))) {
state_set_mode(I2C_COBBOARD_MODE_HARVEST);
state_set_spickle(side, I2C_COBBOARD_SPK_DEPLOY);
prog_char str_state2_arg0[] = "cobboard";
parse_pgm_token_string_t cmd_state2_arg0 = TOKEN_STRING_INITIALIZER(struct cmd_state2_result, arg0, str_state2_arg0);
-prog_char str_state2_arg1[] = "harvest#deploy#pack#harvest_nomove#deploy_nomove";
+prog_char str_state2_arg1[] = "harvest#deploy#pack#weak_pack#harvest_nomove#deploy_nomove";
parse_pgm_token_string_t cmd_state2_arg1 = TOKEN_STRING_INITIALIZER(struct cmd_state2_result, arg1, str_state2_arg1);
prog_char str_state2_arg2[] = "left#right";
parse_pgm_token_string_t cmd_state2_arg2 = TOKEN_STRING_INITIALIZER(struct cmd_state2_result, arg2, str_state2_arg2);
{
struct cmd_spickle_params2_result * res = parsed_result;
- if (!strcmp_P(res->arg1, PSTR("coef"))) {
- spickle_set_coefs(res->arg2, res->arg3);
+ if (!strcmp_P(res->arg1, PSTR("wcoef"))) {
+ spickle_set_wcoefs(res->arg2, res->arg3);
+ }
+ else if (!strcmp_P(res->arg1, PSTR("scoef"))) {
+ spickle_set_scoefs(res->arg2, res->arg3);
}
/* else show */
prog_char str_spickle_params2_arg0[] = "spickle_params2";
parse_pgm_token_string_t cmd_spickle_params2_arg0 =
TOKEN_STRING_INITIALIZER(struct cmd_spickle_params2_result, arg0, str_spickle_params2_arg0);
-prog_char str_spickle_params2_arg1[] = "coef";
+prog_char str_spickle_params2_arg1[] = "wcoef#scoef";
parse_pgm_token_string_t cmd_spickle_params2_arg1 =
TOKEN_STRING_INITIALIZER(struct cmd_spickle_params2_result, arg1, str_spickle_params2_arg1);
parse_pgm_token_num_t cmd_spickle_params2_arg2 =
#include "sensor.h"
#include "../common/i2c_commands.h"
+#include "state.h"
#include "main.h"
#include "actuator.h"
struct spickle_params {
/* current limit (common to left and right) */
- int32_t k1;
- int32_t k2;
+ int32_t sk1;
+ int32_t sk2;
+ int32_t wk1;
+ int32_t wk2;
/* cs blocks */
struct cs_block * const csb[2];
};
static struct spickle_params spickle = {
- .k1 = 1000,
- .k2 = 20,
+ .sk1 = 1000,
+ .sk2 = 20,
+ .wk1 = 200,
+ .wk2 = 20,
.csb = {
&cobboard.left_spickle,
&cobboard.right_spickle,
{
static int32_t oldpos_left, oldpos_right;
int32_t oldpos, pos, maxcmd, speed;
+ int32_t k1, k2;
if (mot == LEFT_SPICKLE_PWM) {
pos = encoders_spi_get_value(LEFT_SPICKLE_ENCODER);
oldpos = oldpos_left;
+ if (state_spicklemode_weak(I2C_LEFT_SIDE)) {
+ k1 = spickle.wk1;
+ k2 = spickle.wk2;
+ }
+ else {
+ k1 = spickle.sk1;
+ k2 = spickle.sk2;
+ }
}
else {
pos = encoders_spi_get_value(RIGHT_SPICKLE_ENCODER);
oldpos = oldpos_right;
+ if (state_spicklemode_weak(I2C_RIGHT_SIDE)) {
+ k1 = spickle.wk1;
+ k2 = spickle.wk2;
+ }
+ else {
+ k1 = spickle.sk1;
+ k2 = spickle.sk2;
+ }
}
speed = pos - oldpos;
if (speed > 0 && cmd < 0)
- maxcmd = spickle.k1;
+ maxcmd = k1;
else if (speed < 0 && cmd > 0)
- maxcmd = spickle.k1;
+ maxcmd = k1;
else {
speed = ABS(speed);
- maxcmd = spickle.k1 + spickle.k2 * speed;
+ maxcmd = k1 + k2 * speed;
}
if (cmd > maxcmd)
cmd = maxcmd;
oldpos_right = pos;
}
-void spickle_set_coefs(uint32_t k1, uint32_t k2)
+void spickle_set_wcoefs(uint32_t k1, uint32_t k2)
{
- spickle.k1 = k1;
- spickle.k2 = k2;
+ spickle.wk1 = k1;
+ spickle.wk2 = k2;
+}
+
+void spickle_set_scoefs(uint32_t k1, uint32_t k2)
+{
+ spickle.sk1 = k1;
+ spickle.sk2 = k2;
}
void spickle_set_pos(uint8_t side, int32_t pos_packed,
void spickle_dump_params(void)
{
- printf_P(PSTR("coef %ld %ld\r\n"), spickle.k1, spickle.k2);
+ printf_P(PSTR("strong_coef %ld %ld\r\n"), spickle.sk1, spickle.sk2);
+ printf_P(PSTR("weak_coef %ld %ld\r\n"), spickle.wk1, spickle.wk2);
printf_P(PSTR("left pos %ld %ld\r\n"),
spickle.pos_packed[I2C_LEFT_SIDE],
spickle.pos_mid[I2C_LEFT_SIDE],
#define _SPICKLE_H_
void spickle_set(void *dummy, int32_t cmd);
-void spickle_set_coefs(uint32_t k1, uint32_t k2);
+void spickle_set_scoefs(uint32_t k1, uint32_t k2);
+void spickle_set_wcoefs(uint32_t k1, uint32_t k2);
void spickle_set_pos(uint8_t side, int32_t pos_pack,
int32_t pos_mid, int32_t pos_deployed);
return rspickle & I2C_COBBOARD_SPK_NO_MOVE;
}
+uint8_t state_spicklemode_weak(uint8_t side)
+{
+ if (side == I2C_LEFT_SIDE)
+ return lspickle & I2C_COBBOARD_SPK_WEAK;
+ else
+ return rspickle & I2C_COBBOARD_SPK_WEAK;
+}
+
/* pack/deploy spickles depending on mode */
static void spickle_prepare(uint8_t side)
{
/* get current state */
uint8_t state_get_mode(void);
uint8_t state_get_status(void);
+uint8_t state_spicklemode_weak(uint8_t side);
void state_set_i2c_ignore(uint8_t val);
uint8_t state_get_i2c_ignore(void);
#define I2C_COBBOARD_SPK_DEPLOY 0x01 /* deploy the spickle */
#define I2C_COBBOARD_SPK_AUTOHARVEST 0x02 /* auto harvest the cobs */
#define I2C_COBBOARD_SPK_NO_MOVE 0x04 /* if enabled, don't change state */
+#define I2C_COBBOARD_SPK_WEAK 0x08 /* if enabled, current limit */
uint8_t lspickle;
uint8_t rspickle;
};