X-Git-Url: http://git.droids-corp.org/?p=aversive.git;a=blobdiff_plain;f=projects%2Fmicrob2010%2Fmainboard%2Fcs.c;h=6ef8fe934024333b2029c14f93d3f6d649446bdd;hp=b8d6e08fa5232325333fcbbccf2f2b595bc5a9a6;hb=17aadc4c8c3e60c2b5e6bbba91c8542849addbd7;hpb=6914527de2ecfef9d790740c71739e7418246b96 diff --git a/projects/microb2010/mainboard/cs.c b/projects/microb2010/mainboard/cs.c index b8d6e08..6ef8fe9 100644 --- a/projects/microb2010/mainboard/cs.c +++ b/projects/microb2010/mainboard/cs.c @@ -80,6 +80,15 @@ int32_t encoders_right_cobroller_speed(void *number) } #endif +#ifndef HOST_VERSION +#define DEBUG_CPLD +#endif + +#ifdef DEBUG_CPLD +extern int16_t g_encoders_spi_previous[4]; +static int32_t ll_prev, rr_prev; +#endif + /* called every 5 ms */ static void do_cs(void *dummy) { @@ -89,10 +98,29 @@ static void do_cs(void *dummy) #ifdef HOST_VERSION robotsim_update(); #else +#ifdef DEBUG_CPLD + int32_t ll, rr; +#endif /* read encoders */ if (mainboard.flags & DO_ENCODERS) { encoders_spi_manage(NULL); } +#ifdef DEBUG_CPLD + ll = encoders_spi_get_value(LEFT_ENCODER); + rr = encoders_spi_get_value(RIGHT_ENCODER); + if ((ll - ll_prev > 3000) || (ll - ll_prev < -3000) || + (rr - rr_prev > 3000) || (rr - rr_prev < -3000)) { + 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); + } + ll_prev = ll; + rr_prev = rr; +#endif #endif /* robot system, conversion to angle,distance */ @@ -213,9 +241,9 @@ void microb_cs_init(void) RIGHT_ENCODER, IMP_COEF * 1.); #else rs_set_left_ext_encoder(&mainboard.rs, encoders_spi_get_value, - LEFT_ENCODER, IMP_COEF * -1.036); + LEFT_ENCODER, IMP_COEF * -1.011718); rs_set_right_ext_encoder(&mainboard.rs, encoders_spi_get_value, - RIGHT_ENCODER, IMP_COEF * 1.037); + RIGHT_ENCODER, IMP_COEF * 1.012695); #endif /* rs will use external encoders */ rs_set_flags(&mainboard.rs, RS_USE_EXT); @@ -224,7 +252,7 @@ void microb_cs_init(void) position_init(&mainboard.pos); position_set_physical_params(&mainboard.pos, VIRTUAL_TRACK_MM, DIST_IMP_MM); position_set_related_robot_system(&mainboard.pos, &mainboard.rs); - position_set_centrifugal_coef(&mainboard.pos, 0.000016); + // position_set_centrifugal_coef(&mainboard.pos, 0.000016); position_use_ext(&mainboard.pos); /* TRAJECTORY MANAGER */ @@ -240,8 +268,8 @@ void microb_cs_init(void) /* ---- CS angle */ /* PID */ pid_init(&mainboard.angle.pid); - pid_set_gains(&mainboard.angle.pid, 500, 10, 7000); - pid_set_maximums(&mainboard.angle.pid, 0, 20000, 4095); + pid_set_gains(&mainboard.angle.pid, 850, 30, 15000); + pid_set_maximums(&mainboard.angle.pid, 0, 10000, 4095); pid_set_out_shift(&mainboard.angle.pid, 10); pid_set_derivate_filter(&mainboard.angle.pid, 4); @@ -261,13 +289,13 @@ void microb_cs_init(void) /* Blocking detection */ bd_init(&mainboard.angle.bd); bd_set_speed_threshold(&mainboard.angle.bd, 80); - bd_set_current_thresholds(&mainboard.angle.bd, 500, 8000, 1000000, 50); + bd_set_current_thresholds(&mainboard.angle.bd, 500, 8000, 1000000, 20); /* ---- CS distance */ /* PID */ pid_init(&mainboard.distance.pid); - pid_set_gains(&mainboard.distance.pid, 500, 10, 7000); - pid_set_maximums(&mainboard.distance.pid, 0, 2000, 4095); + pid_set_gains(&mainboard.distance.pid, 850, 30, 15000); + pid_set_maximums(&mainboard.distance.pid, 0, 10000, 4095); pid_set_out_shift(&mainboard.distance.pid, 10); pid_set_derivate_filter(&mainboard.distance.pid, 6); @@ -287,7 +315,7 @@ void microb_cs_init(void) /* Blocking detection */ bd_init(&mainboard.distance.bd); bd_set_speed_threshold(&mainboard.distance.bd, 60); - bd_set_current_thresholds(&mainboard.distance.bd, 500, 8000, 1000000, 50); + bd_set_current_thresholds(&mainboard.distance.bd, 500, 8000, 1000000, 20); #ifndef HOST_VERSION /* ---- CS left_cobroller */ @@ -332,13 +360,18 @@ void microb_cs_init(void) #endif /* !HOST_VERSION */ /* set them on !! */ - mainboard.angle.on = 0; - mainboard.distance.on = 0; + mainboard.angle.on = 1; + mainboard.distance.on = 1; mainboard.left_cobroller.on = 1; mainboard.right_cobroller.on = 1; +#ifdef DEBUG_CPLD + ll_prev = encoders_spi_get_value(LEFT_ENCODER); + rr_prev = encoders_spi_get_value(RIGHT_ENCODER); +#endif scheduler_add_periodical_event_priority(do_cs, NULL, 5000L / SCHEDULER_UNIT, CS_PRIO); + }