6 #include <avr/interrupt.h>
11 * I2C Register Map (8 Bit)
12 * 0x00 Register select
13 * 0x01 Motor 1 PWM MSB
14 * 0x02 Motor 1 PWM LSB
15 * 0x03 Motor 2 PWM MSB
16 * 0x04 Motor 2 PWM LSB
17 * 0x05 Motor 3 PWM MSB
18 * 0x06 Motor 3 PWM LSB
19 * 0x07 Motor 4 PWM MSB
20 * 0x08 Motor 4 PWM LSB
31 * 0x20 Motor 1 speed wish MSB
32 * 0x21 Motor 1 speed wish LSB
33 * 0x22 Motor 2 speed wish MSB
34 * 0x23 Motor 2 speed wish LSB
35 * 0x24 Motor 3 speed wish MSB
36 * 0x25 Motor 3 speed wish LSB
37 * 0x26 Motor 4 speed wish MSB
38 * 0x27 Motor 4 speed wish LSB
39 * 0x28 Left speed wish (m/s) MSB
40 * 0x29 Left speed wish (m/s)
41 * 0x2A Left speed wish (m/s)
42 * 0x2B Left speed wish (m/s) LSB
43 * 0x2C Right speed wish (m/s) MSB
44 * 0x2D Right speed wish (m/s)
45 * 0x2E Right speed wish (m/s)
46 * 0x2F Right speed wish (m/s) LSB
47 * 0x30 Motor 1 speed MSB
48 * 0x31 Motor 1 speed LSB
49 * 0x32 Motor 2 speed MSB
50 * 0x33 Motor 2 speed LSB
51 * 0x34 Motor 3 speed MSB
52 * 0x35 Motor 3 speed LSB
53 * 0x36 Motor 4 speed MSB
54 * 0x37 Motor 4 speed LSB
55 * 0x38 Speed (m/s) MSB
58 * 0x3B Speed (m/s) LSB
59 * 0x3C Angle (rad/s) MSB
62 * 0x3F Angle (rad/s) LSB
63 * 0x40 Position x (m) MSB
66 * 0x43 Position x (m) LSB
67 * 0x44 Position y (m) MSB
70 * 0x47 Position y (m) LSB
71 * 0x48 Position angle MSB
74 * 0x4B Position angle LSB
76 * 0x50 speed wish (m/s) MSB
77 * 0x51 speed wish (m/s)
78 * 0x52 speed wish (m/s)
79 * 0x53 speed wish (m/s) LSB
80 * 0x54 angle wish (rad/s) MSB
81 * 0x55 angle wish (rad/s)
82 * 0x56 angle wish (rad/s)
83 * 0x57 angle wish (rad/s) LSB
100 #define TWI_ACK TWCR = (1<<TWEA) | (1<<TWINT) | (1<<TWEN) | (1<<TWIE)
101 #define TWI_RESET TWCR &= ~((1 << TWSTO) | (1 << TWEN)); TWI_ACK
102 #define TWI_NAK TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWIE)
108 // wheel diameter=12cm, encoder=48cpr, gear ratio=1:47
109 // STEP_PER_M = 48*47/(d*pi)
110 // Left real diameter: 0.12808, Right real diameter: 0.121
111 #define STEP_PER_M 5770.8
112 #define STEP_PER_M_LEFT (STEP_PER_M)
113 #define STEP_PER_M_RIGHT (STEP_PER_M)
114 #define WHEEL_DIST 0.39912 // Measured: 0.252
115 #define PWM_BREAK INT16_MIN
127 static volatile struct {
131 } cmd_vel = {0, 0, 0};
133 static volatile uint8_t ireg=0;
134 static volatile uint8_t bootloader=0;
135 static volatile int16_t motor1=0; // -255..+255
136 static volatile int16_t motor2=0;
137 static volatile int16_t motor3=0;
138 static volatile int16_t motor4=0;
139 static volatile int16_t pos1=0; // step
140 static volatile int16_t pos2=0;
141 static volatile int16_t pos3=0;
142 static volatile int16_t pos4=0;
143 static volatile enum mode motor1_mode=MOTOR_MANUAL;
144 static volatile enum mode motor2_mode=MOTOR_MANUAL;
145 static volatile enum mode motor3_mode=MOTOR_MANUAL;
146 static volatile enum mode motor4_mode=MOTOR_MANUAL;
147 static volatile uint8_t motor1_switch=1;
148 static volatile uint8_t motor2_switch=1;
149 static volatile uint8_t motor3_switch=0;
150 static volatile uint8_t motor4_switch=0;
151 static volatile int16_t speed1_wish=0; // step/s
152 static volatile int16_t speed2_wish=0;
153 static volatile int16_t speed3_wish=0;
154 static volatile int16_t speed4_wish=0;
155 static volatile int16_t speed1_wish_old=0;
156 static volatile int16_t speed2_wish_old=0;
157 static volatile int16_t speed3_wish_old=0;
158 static volatile int16_t speed4_wish_old=0;
159 static volatile uint8_t run_update=0;
160 static volatile int16_t speed1=0; // step/s
161 static volatile int16_t speed2=0;
162 static volatile int16_t speed3=0;
163 static volatile int16_t speed4=0;
164 static volatile ufloat_t pos_x={0.0};
165 static volatile ufloat_t pos_y={0.0};
166 static volatile ufloat_t angle={0.0};
167 static volatile float cur_speed_lin=0;
168 static volatile float cur_speed_rot=0;
169 static volatile uint8_t count_test=0;
170 static volatile uint8_t front_handicap=0;
171 static volatile uint8_t aft_handicap=0;
172 static volatile uint8_t error_state=0;
176 static uint8_t tmp=0;
177 static int16_t tmp16=0;
178 static ufloat_t tmp_speed;
179 static ufloat_t tmp_angle;
183 case 0x60: // start write
189 case 0x00: // register select
191 ireg--; // because we do ireg++ below
194 case 0x01: // Motor 1 MSB
198 case 0x02: // Motor 1 LSB
199 motor1 = tmp<<8 | TWDR;
200 motor1_mode = MOTOR_MANUAL;
203 case 0x03: // Motor 2 MSB
207 case 0x04: // Motor 2 LSB
208 motor2 = tmp<<8 | TWDR;
209 motor2_mode = MOTOR_MANUAL;
212 case 0x05: // Motor 3 MSB
216 case 0x06: // Motor 3 LSB
217 motor3 = tmp<<8 | TWDR;
218 motor3_mode = MOTOR_MANUAL;
221 case 0x07: // Motor 4 MSB
225 case 0x08: // Motor 4 LSB
226 motor4 = tmp<<8 | TWDR;
227 motor4_mode = MOTOR_MANUAL;
230 case 0x20: // Motor 1 speed wish MSB
234 case 0x21: // Motor 1 speed wish LSB
235 speed1_wish = tmp<<8 | TWDR;
236 motor1_mode = MOTOR_PID;
239 case 0x22: // Motor 2 speed wish MSB
243 case 0x23: // Motor 2 speed wish LSB
244 speed2_wish = tmp<<8 | TWDR;
245 motor2_mode = MOTOR_PID;
248 case 0x24: // Motor 3 speed wish MSB
252 case 0x25: // Motor 3 speed wish LSB
253 speed3_wish = tmp<<8 | TWDR;
254 motor3_mode = MOTOR_PID;
257 case 0x26: // Motor 4 speed wish MSB
261 case 0x27: // Motor 4 speed wish LSB
262 speed4_wish = tmp<<8 | TWDR;
263 motor4_mode = MOTOR_PID;
266 case 0x28: // Left speed wish MSB
270 case 0x29: // Left speed wish
271 tmp_speed.i = tmp_speed.i << 8 | TWDR;
274 case 0x2A: // Left speed wish
275 tmp_speed.i = tmp_speed.i << 8 | TWDR;
278 case 0x2B: // Left speed wish LSB
279 tmp_speed.i = tmp_speed.i << 8 | TWDR;
280 speed1_wish = tmp_speed.f*STEP_PER_M_LEFT;
281 speed2_wish = tmp_speed.f*STEP_PER_M_LEFT;
282 motor1_mode = MOTOR_PID;
283 motor2_mode = MOTOR_PID;
286 case 0x2C: // Right speed wish MSB
290 case 0x2D: // Right speed wish
291 tmp_speed.i = tmp_speed.i << 8 | TWDR;
294 case 0x2E: // Right speed wish
295 tmp_speed.i = tmp_speed.i << 8 | TWDR;
298 case 0x2F: // Right speed wish LSB
299 tmp_speed.i = tmp_speed.i << 8 | TWDR;
300 speed1_wish = tmp_speed.f*STEP_PER_M_RIGHT;
301 speed2_wish = tmp_speed.f*STEP_PER_M_RIGHT;
302 motor1_mode = MOTOR_PID;
303 motor2_mode = MOTOR_PID;
306 case 0x50: // speed wish MSB
310 case 0x51: // speed wish
311 tmp_speed.i = tmp_speed.i << 8 | TWDR;
314 case 0x52: // speed wish
315 tmp_speed.i = tmp_speed.i << 8 | TWDR;
318 case 0x53: // speed wish LSB
319 tmp_speed.i = tmp_speed.i << 8 | TWDR;
320 cmd_vel.speed = tmp_speed.f;
323 case 0x54: // angle wish MSB
327 case 0x55: // angle wish
328 tmp_angle.i = tmp_angle.i << 8 | TWDR;
331 case 0x56: // angle wish
332 tmp_angle.i = tmp_angle.i << 8 | TWDR;
335 case 0x57: // angle wish LSB
336 tmp_angle.i = tmp_angle.i << 8 | TWDR;
337 cmd_vel.angle = tmp_angle.f;
341 case 0x90: // Motor 1 switch
342 motor1_switch = TWDR;
345 case 0x91: // Motor 2 switch
346 motor2_switch = TWDR;
349 case 0x92: // Motor 3 switch
350 motor3_switch = TWDR;
353 case 0x93: // Motor 4 switch
354 motor4_switch = TWDR;
357 case 0x94: // Front Handicap
358 front_handicap = TWDR;
362 case 0x95: // Aft Handicap
367 case 0xff: // bootloader
374 case 0xA8: // start read
377 case 0x02: // Motor 1 PWM
381 case 0x03: // Dummy to allow continous read
385 case 0x04: // Motor 2 PWM
389 case 0x05: // Dummy to allow continous read
393 case 0x06: // Motor 3 PWM
397 case 0x07: // Dummy to allow continous read
401 case 0x08: // Motor 4 PWM
405 case 0x09: // Dummy to allow continous read
409 case 0x10: // Hall 1 MSB
414 case 0x11: // Hall 1 LSB
418 case 0x12: // Hall 2 MSB
423 case 0x13: // Hall 2 LSB
427 case 0x14: // Hall 3 MSB
432 case 0x15: // Hall 3 LSB
436 case 0x16: // Hall 4 MSB
441 case 0x17: // Hall 4 LSB
445 case 0x20: // Motor 1 speed wish MSB
446 TWDR = speed1_wish>>8;
449 case 0x21: // Motor 1 speed wish LSB
453 case 0x22: // Motor 2 speed wish MSB
454 TWDR = speed2_wish>>8;
457 case 0x23: // Motor 2 speed wish LSB
461 case 0x24: // Motor 3 speed wish MSB
462 TWDR = speed3_wish>>8;
465 case 0x25: // Motor 3 speed wish LSB
469 case 0x26: // Motor 4 speed wish MSB
470 TWDR = speed4_wish>>8;
473 case 0x27: // Motor 4 speed wish LSB
477 case 0x30: // Motor 1 speed MSB
481 case 0x31: // Motor 1 speed LSB
485 case 0x32: // Motor 2 speed MSB
489 case 0x33: // Motor 2 speed LSB
493 case 0x34: // Motor 3 speed MSB
497 case 0x35: // Motor 3 speed LSB
501 case 0x36: // Motor 4 speed MSB
505 case 0x37: // Motor 4 speed LSB
509 case 0x38: // speed MSB
510 tmp_speed.f = cur_speed_lin;
511 TWDR = tmp_speed.i>>24;
515 TWDR = tmp_speed.i>>16;
519 TWDR = tmp_speed.i>>8;
522 case 0x3B: // speed LSB
526 case 0x3C: // angle MSB
527 tmp_angle.f = cur_speed_rot;
528 TWDR = tmp_angle.i>>24;
532 TWDR = tmp_angle.i>>16;
536 TWDR = tmp_angle.i>>8;
539 case 0x3F: // angle LSB
543 case 0x40: // Position x MSB
547 case 0x41: // Position x
551 case 0x42: // Position x
555 case 0x43: // Position x LSB
559 case 0x44: // Position y MSB
563 case 0x45: // Position y
567 case 0x46: // Position y
571 case 0x47: // Position y LSB
575 case 0x48: // Position angle MSB
579 case 0x49: // Position angle
583 case 0x4A: // Position angle
587 case 0x4B: // Position angle LSB
591 case 0xA0: // Reset reason
592 TWDR = MCUCSR & 0x0f;
596 case 0xA1: // Error status
600 case 0xA2: // count test
615 static void update_hall1(void) {
616 unsigned char status = (PINA >> 0) & 0x3;
617 static unsigned char oldstatus=0;
618 unsigned char diff, new;
624 new ^= 0x1; // convert gray to binary
625 diff = oldstatus - new; // difference last - new
626 if (diff & 0x1) { // bit 0 = value (1)
627 oldstatus = new; // store new as next last
628 if (motor1_switch) pos1 += (diff & 2) - 1; // bit 1 = direction (+/-)
629 else pos1 -= (diff & 2) - 1;
634 static void update_hall2(void) {
635 unsigned char status = (PINA >> 4) & 0x3;
636 static unsigned char oldstatus=0;
637 unsigned char diff, new;
643 new ^= 0x1; // convert gray to binary
644 diff = oldstatus - new; // difference last - new
645 if (diff & 0x1) { // bit 0 = value (1)
646 oldstatus = new; // store new as next last
647 if (motor2_switch) pos2 -= (diff & 2) - 1; // bit 1 = direction (+/-)
648 else pos2 += (diff & 2) - 1;
653 static void update_hall3(void) {
654 unsigned char status = (PINA >> 2) & 0x3;
655 static unsigned char oldstatus=0;
656 unsigned char diff, new;
662 new ^= 0x1; // convert gray to binary
663 diff = oldstatus - new; // difference last - new
664 if (diff & 0x1) { // bit 0 = value (1)
665 oldstatus = new; // store new as next last
666 if (motor3_switch) pos3 -= (diff & 2) - 1; // bit 1 = direction (+/-)
667 else pos3 += (diff & 2) - 1;
672 static void update_hall4(void) {
673 unsigned char status = (PINA >> 6) & 0x3;
674 static unsigned char oldstatus=0;
675 unsigned char diff, new;
681 new ^= 0x1; // convert gray to binary
682 diff = oldstatus - new; // difference last - new
683 if (diff & 0x1) { // bit 0 = value (1)
684 oldstatus = new; // store new as next last
685 if (motor4_switch) pos4 += (diff & 2) - 1; // bit 1 = direction (+/-)
686 else pos4 -= (diff & 2) - 1;
691 static void update_motor(void) {
692 static int16_t m1_old=SHRT_MIN;
693 static int16_t m2_old=SHRT_MIN;
694 static int16_t m3_old=SHRT_MIN;
695 static int16_t m4_old=SHRT_MIN;
697 error_state &= 0xf0; // clear lower bits
698 error_state |= ~((PIND & 0x40)>>3 | (PINB & 0x07)) & 0xf;
700 if (m1_old != motor1) { // update only when changed
703 PORTC &= ~(1 << 3) & ~(1 << 2);
704 } else if (motor1 == PWM_BREAK) {
705 PORTC |= (1 << 3) | (1 << 2);
706 } else if ((!motor1_switch && motor1 > 0) || (motor1_switch && motor1 < 0)) {
712 } else { // motor1 < 0
724 if (m2_old != motor2) { // update only when changed
727 PORTC &= ~(1 << 5) & ~(1 << 4);
728 } else if (motor2 == PWM_BREAK) {
729 PORTC |= (1 << 5) | (1 << 4);
730 } else if ((!motor2_switch && motor2 > 0) || (motor2_switch && motor2 < 0)) {
736 } else { // motor2 < 0
748 if (m3_old != motor3) { // update only when changed
751 PORTC &= ~(1 << 7) & ~(1 << 6);
752 } else if (motor3 == PWM_BREAK) {
753 PORTC |= (1 << 7) | (1 << 6);
754 } else if ((!motor3_switch && motor3 > 0) || (motor3_switch && motor3 < 0)) {
760 } else { // motor3 < 0
772 if (m4_old != motor4) { // update only when changed
775 PORTD &= ~(1 << 3) & ~(1 << 2);
776 } else if (motor4 == PWM_BREAK) {
777 PORTD |= (1 << 3) | (1 << 2);
778 } else if ((!motor4_switch && motor4 > 0) || (motor4_switch && motor4 < 0)) {
784 } else { // motor4 < 0
798 static void update_pos(void) {
799 static int16_t pos1_last=0;
800 static int16_t pos2_last=0;
801 static int16_t pos3_last=0;
802 static int16_t pos4_last=0;
803 int16_t pos1_diff; // steps
807 float diff_left_m, diff_right_m, angle_diff, translation;
808 float pos_x_new, pos_y_new, angle_new;
809 float tmp_speed_lin, tmp_speed_rot;
810 int16_t cur_pos1, cur_pos2, cur_pos3, cur_pos4;
811 int16_t new_speed1, new_speed2, new_speed3, new_speed4;
821 pos1_diff = cur_pos1 - pos1_last;
822 pos2_diff = cur_pos2 - pos2_last;
823 pos3_diff = cur_pos3 - pos3_last;
824 pos4_diff = cur_pos4 - pos4_last;
826 new_speed1 = pos1_diff/PID_T;
827 new_speed2 = pos2_diff/PID_T;
828 new_speed3 = pos3_diff/PID_T;
829 new_speed4 = pos4_diff/PID_T;
831 diff_left_m = (pos1_diff + pos2_diff)/(2*STEP_PER_M_LEFT);
832 diff_right_m = (pos3_diff + pos4_diff)/(2*STEP_PER_M_RIGHT);
833 angle_diff = (diff_right_m - diff_left_m) / WHEEL_DIST;
835 angle_new = angle.f + angle_diff;
836 if (angle_new > 2*M_PI) angle_new-=2*M_PI;
837 else if (angle_new < -2*M_PI) angle_new+=2*M_PI;
839 translation = (diff_left_m + diff_right_m)/2.0;
840 pos_x_new = pos_x.f + cos(angle_new)*translation;
841 pos_y_new = pos_y.f + sin(angle_new)*translation;
843 tmp_speed_lin = translation/PID_T;
844 tmp_speed_rot = angle_diff/PID_T;
855 cur_speed_lin = tmp_speed_lin;
856 cur_speed_rot = tmp_speed_rot;
859 pos1_last = cur_pos1;
860 pos2_last = cur_pos2;
861 pos3_last = cur_pos3;
862 pos4_last = cur_pos4;
866 static void update_pid(void) {
867 static int16_t eold1=0;
868 static int16_t eold2=0;
869 static int16_t eold3=0;
870 static int16_t eold4=0;
871 static int32_t esum1=0;
872 static int32_t esum2=0;
873 static int32_t esum3=0;
874 static int32_t esum4=0;
876 // protect motors from damage if stalling
877 if (labs(esum1) > 140000 && speed1 == 0) {
879 motor1_mode = MOTOR_MANUAL;
880 error_state |= (1<<4);
883 if (labs(esum2) > 140000 && speed2 == 0) {
885 motor2_mode = MOTOR_MANUAL;
886 error_state |= (1<<5);
889 if (labs(esum3) > 140000 && speed3 == 0) {
891 motor3_mode = MOTOR_MANUAL;
892 error_state |= (1<<6);
895 // protect motors from damage if stalling
896 if (labs(esum4) > 140000 && speed4 == 0) {
898 motor4_mode = MOTOR_MANUAL;
899 error_state |= (1<<7);
903 if (motor1_mode == MOTOR_PID) {
904 if (speed1_wish != speed1_wish_old) {
905 if (abs(speed1_wish - speed1_wish_old) > 500) esum1 = 0;
906 speed1_wish_old = speed1_wish;
909 if (speed1_wish == 0) {
912 error_state &= ~(1<<4);
914 int16_t e = speed1_wish - speed1;
916 motor1 = KP*e + KI*PID_T*esum1 + KD/PID_T*(e - eold1);
919 if (motor1 > 0 && speed1_wish < 0) motor1=PWM_BREAK;
920 else if (motor1 < 0 && speed1_wish > 0) motor1=PWM_BREAK;
921 else if (motor1 > 255) motor1 = 255;
922 else if (motor1 < -255) motor1 = -255;
925 if (motor2_mode == MOTOR_PID) {
926 if (speed2_wish != speed2_wish_old) {
927 if (abs(speed2_wish - speed2_wish_old) > 500) esum2 = 0;
928 speed2_wish_old = speed2_wish;
931 if (speed2_wish == 0) {
934 error_state &= ~(1<<5);
936 int16_t e = speed2_wish - speed2;
938 motor2 = KP*e + KI*PID_T*esum2 + KD/PID_T*(e - eold2);
941 if (motor2 > 0 && speed2_wish < 0) motor2=PWM_BREAK;
942 else if (motor2 < 0 && speed2_wish > 0) motor2=PWM_BREAK;
943 else if (motor2 > 255) motor2 = 255;
944 else if (motor2 < -255) motor2 = -255;
947 if (motor3_mode == MOTOR_PID) {
948 if (speed3_wish != speed3_wish_old) {
949 if (abs(speed3_wish - speed3_wish_old) > 500) esum3 = 0;
950 speed3_wish_old = speed3_wish;
953 if (speed3_wish == 0) {
956 error_state &= ~(1<<6);
958 int16_t e = speed3_wish - speed3;
960 motor3 = KP*e + KI*PID_T*esum3 + KD/PID_T*(e - eold3);
963 if (motor3 > 0 && speed3_wish < 0) motor3=PWM_BREAK;
964 else if (motor3 < 0 && speed3_wish > 0) motor3=PWM_BREAK;
965 else if (motor3 > 255) motor3 = 255;
966 else if (motor3 < -255) motor3 = -255;
969 if (motor4_mode == MOTOR_PID) {
970 if (speed4_wish != speed4_wish_old) {
971 if (abs(speed4_wish - speed4_wish_old) > 500) esum4 = 0;
972 speed4_wish_old = speed4_wish;
975 if (speed4_wish == 0) {
978 error_state &= ~(1<<7);
980 int16_t e = speed4_wish - speed4;
982 motor4 = KP*e + KI*PID_T*esum4 + KD/PID_T*(e - eold4);
985 if (motor4 > 0 && speed4_wish < 0) motor4=PWM_BREAK;
986 else if (motor4 < 0 && speed4_wish > 0) motor4=PWM_BREAK;
987 else if (motor4 > 255) motor4 = 255;
988 else if (motor4 < -255) motor4 = -255;
994 ISR(TIMER1_OVF_vect) {
1007 DDRC = (1 << 7) | (1 << 6) | (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2);
1008 DDRD = (1 << 7) | (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2);
1009 // Pullup Diag/Enable
1010 PORTB = (1 << 0) | (1 << 1) | (1 << 2);
1015 uart_setup_stdout();
1022 // Timer 1: Fast PWM non-inverting mode, Top=255 => 15.625kHz
1024 TCCR1A = (1 << COM1A1) | (1 << COM1B1) | (1 << WGM10);
1025 TCCR1B = (1 << WGM12) | (1 << CS10);
1030 // Timer 2: Fast PWM non-inverting mode, Top=255
1032 TCCR2 = (1 << WGM21) | (1 << WGM20) | (1 << COM21) | (1 << CS20);
1036 // Timer 0: Fast PWM non-inverting mode, Top=255
1038 TCCR0 = (1 << WGM01) | (1 << WGM00) | (1 << COM01) | (1 << CS00);
1041 printf("\r\nStart\r\n");
1043 set_sleep_mode(SLEEP_MODE_IDLE);
1044 // Enable Timer 1 Overflow Interrupt
1045 TIMSK = (1 << TOIE1);
1050 case 0xff: // Magic reg that starts the bootloader
1051 if (bootloader == 0xa5) {
1054 void (*start)(void) = (void*)0x1800;
1061 if (cmd_vel.bUpdate) {
1062 float speed_wish_right, speed_wish_left;
1066 speed = cmd_vel.speed;
1067 angle = cmd_vel.angle;
1068 cmd_vel.bUpdate = 0;
1071 speed_wish_right = (angle*WHEEL_DIST)/2 + speed;
1072 speed_wish_left = speed*2-speed_wish_right;
1074 speed_wish_left*=STEP_PER_M_LEFT;
1075 speed_wish_right*=STEP_PER_M_RIGHT;
1077 if (aft_handicap > 0) {
1078 speed1_wish = speed_wish_left * (100-aft_handicap)/100.0;
1079 speed3_wish = speed_wish_right * (100-aft_handicap)/100.0;
1081 speed1_wish = speed_wish_left;
1082 speed3_wish = speed_wish_right;
1084 if (front_handicap > 0) {
1085 speed2_wish = speed_wish_left * (100-front_handicap)/100.0;
1086 speed4_wish = speed_wish_right * (100-front_handicap)/100.0;
1088 speed2_wish = speed_wish_left;
1089 speed4_wish = speed_wish_right;
1091 motor1_mode = MOTOR_PID;
1092 motor2_mode = MOTOR_PID;
1093 motor3_mode = MOTOR_PID;
1094 motor4_mode = MOTOR_PID;
1097 if (run_update >= 156) { // ~100Hz