TB3-源码剖析-2.按键测试行走30cm
void driveTest(uint8_t buttons) { static bool move[2] = {false, false}; static int32_t saved_tick[2] = {0, 0}; static double diff_encoder = 0.0; int32_t current_tick[2] = {0, 0}; motor_driver.readEncoder(current_tick[LEFT], current_tick[RIGHT]); if (buttons & (1<<0)) { move[LINEAR] = true; saved_tick[RIGHT] = current_tick[RIGHT]; diff_encoder = TEST_DISTANCE / (0.207 / 4096); // (Circumference of Wheel) / (The number of tick per revolution) tTime[6] = millis(); } else if (buttons & (1<<1)) { move[ANGULAR] = true; saved_tick[RIGHT] = current_tick[RIGHT]; diff_encoder = (TEST_RADIAN * TURNING_RADIUS) / (0.207 / 4096); tTime[6] = millis(); } if (move[LINEAR]) { if (abs(saved_tick[RIGHT] - current_tick[RIGHT]) <= diff_encoder) { goal_velocity_from_button[LINEAR] = 0.05; tTime[6] = millis(); } else { goal_velocity_from_button[LINEAR] = 0.0; move[LINEAR] = false; } } else if (move[ANGULAR]) { if (abs(saved_tick[RIGHT] - current_tick[RIGHT]) <= diff_encoder) { goal_velocity_from_button[ANGULAR]= -0.7; tTime[6] = millis(); } else { goal_velocity_from_button[ANGULAR] = 0.0; move[ANGULAR] = false; } } }
<< 上一篇
下一篇 >>