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, real wheel diameter: 0.12454m
109 #define STEP_PER_M_AVG 5766.1
110 #define STEP_PER_M_LEFT (STEP_PER_M_AVG)
111 #define STEP_PER_M_RIGHT (STEP_PER_M_AVG)
112 #define WHEEL_DIST 0.36923 // Real: 0.252
113 #define PWM_BREAK INT16_MIN
125 static volatile struct {
129 } cmd_vel = {0, 0, 0};
131 static volatile uint8_t ireg=0;
132 static volatile uint8_t bootloader=0;
133 static volatile int16_t motor1=0; // -255..+255
134 static volatile int16_t motor2=0;
135 static volatile int16_t motor3=0;
136 static volatile int16_t motor4=0;
137 static volatile int16_t pos1=0; // step
138 static volatile int16_t pos2=0;
139 static volatile int16_t pos3=0;
140 static volatile int16_t pos4=0;
141 static volatile enum mode motor1_mode=MOTOR_MANUAL;
142 static volatile enum mode motor2_mode=MOTOR_MANUAL;
143 static volatile enum mode motor3_mode=MOTOR_MANUAL;
144 static volatile enum mode motor4_mode=MOTOR_MANUAL;
145 static volatile uint8_t motor1_switch=1;
146 static volatile uint8_t motor2_switch=1;
147 static volatile uint8_t motor3_switch=0;
148 static volatile uint8_t motor4_switch=0;
149 static volatile int16_t speed1_wish=0; // step/s
150 static volatile int16_t speed2_wish=0;
151 static volatile int16_t speed3_wish=0;
152 static volatile int16_t speed4_wish=0;
153 static volatile int16_t speed1_wish_old=0;
154 static volatile int16_t speed2_wish_old=0;
155 static volatile int16_t speed3_wish_old=0;
156 static volatile int16_t speed4_wish_old=0;
157 static volatile uint8_t run_update=0;
158 static volatile int16_t speed1=0; // step/s
159 static volatile int16_t speed2=0;
160 static volatile int16_t speed3=0;
161 static volatile int16_t speed4=0;
162 static volatile ufloat_t pos_x={0.0};
163 static volatile ufloat_t pos_y={0.0};
164 static volatile ufloat_t angle={0.0};
165 static volatile float cur_speed_lin=0;
166 static volatile float cur_speed_rot=0;
167 static volatile uint8_t count_test=0;
168 static volatile uint8_t front_handicap=0;
169 static volatile uint8_t aft_handicap=0;
170 static volatile uint8_t error_state=0;
174 static uint8_t tmp=0;
175 static int16_t tmp16=0;
176 static ufloat_t tmp_speed;
177 static ufloat_t tmp_angle;
181 case 0x60: // start write
187 case 0x00: // register select
189 ireg--; // because we do ireg++ below
192 case 0x01: // Motor 1 MSB
196 case 0x02: // Motor 1 LSB
197 motor1 = tmp<<8 | TWDR;
198 motor1_mode = MOTOR_MANUAL;
201 case 0x03: // Motor 2 MSB
205 case 0x04: // Motor 2 LSB
206 motor2 = tmp<<8 | TWDR;
207 motor2_mode = MOTOR_MANUAL;
210 case 0x05: // Motor 3 MSB
214 case 0x06: // Motor 3 LSB
215 motor3 = tmp<<8 | TWDR;
216 motor3_mode = MOTOR_MANUAL;
219 case 0x07: // Motor 4 MSB
223 case 0x08: // Motor 4 LSB
224 motor4 = tmp<<8 | TWDR;
225 motor4_mode = MOTOR_MANUAL;
228 case 0x20: // Motor 1 speed wish MSB
232 case 0x21: // Motor 1 speed wish LSB
233 speed1_wish = tmp<<8 | TWDR;
234 motor1_mode = MOTOR_PID;
237 case 0x22: // Motor 2 speed wish MSB
241 case 0x23: // Motor 2 speed wish LSB
242 speed2_wish = tmp<<8 | TWDR;
243 motor2_mode = MOTOR_PID;
246 case 0x24: // Motor 3 speed wish MSB
250 case 0x25: // Motor 3 speed wish LSB
251 speed3_wish = tmp<<8 | TWDR;
252 motor3_mode = MOTOR_PID;
255 case 0x26: // Motor 4 speed wish MSB
259 case 0x27: // Motor 4 speed wish LSB
260 speed4_wish = tmp<<8 | TWDR;
261 motor4_mode = MOTOR_PID;
264 case 0x28: // Left speed wish MSB
268 case 0x29: // Left speed wish
269 tmp_speed.i = tmp_speed.i << 8 | TWDR;
272 case 0x2A: // Left speed wish
273 tmp_speed.i = tmp_speed.i << 8 | TWDR;
276 case 0x2B: // Left speed wish LSB
277 tmp_speed.i = tmp_speed.i << 8 | TWDR;
278 speed1_wish = tmp_speed.f*STEP_PER_M_LEFT;
279 speed2_wish = tmp_speed.f*STEP_PER_M_LEFT;
280 motor1_mode = MOTOR_PID;
281 motor2_mode = MOTOR_PID;
284 case 0x2C: // Right speed wish MSB
288 case 0x2D: // Right speed wish
289 tmp_speed.i = tmp_speed.i << 8 | TWDR;
292 case 0x2E: // Right speed wish
293 tmp_speed.i = tmp_speed.i << 8 | TWDR;
296 case 0x2F: // Right speed wish LSB
297 tmp_speed.i = tmp_speed.i << 8 | TWDR;
298 speed1_wish = tmp_speed.f*STEP_PER_M_RIGHT;
299 speed2_wish = tmp_speed.f*STEP_PER_M_RIGHT;
300 motor1_mode = MOTOR_PID;
301 motor2_mode = MOTOR_PID;
304 case 0x50: // speed wish MSB
308 case 0x51: // speed wish
309 tmp_speed.i = tmp_speed.i << 8 | TWDR;
312 case 0x52: // speed wish
313 tmp_speed.i = tmp_speed.i << 8 | TWDR;
316 case 0x53: // speed wish LSB
317 tmp_speed.i = tmp_speed.i << 8 | TWDR;
318 cmd_vel.speed = tmp_speed.f;
321 case 0x54: // angle wish MSB
325 case 0x55: // angle wish
326 tmp_angle.i = tmp_angle.i << 8 | TWDR;
329 case 0x56: // angle wish
330 tmp_angle.i = tmp_angle.i << 8 | TWDR;
333 case 0x57: // angle wish LSB
334 tmp_angle.i = tmp_angle.i << 8 | TWDR;
335 cmd_vel.angle = tmp_angle.f;
339 case 0x90: // Motor 1 switch
340 motor1_switch = TWDR;
343 case 0x91: // Motor 2 switch
344 motor2_switch = TWDR;
347 case 0x92: // Motor 3 switch
348 motor3_switch = TWDR;
351 case 0x93: // Motor 4 switch
352 motor4_switch = TWDR;
355 case 0x94: // Front Handicap
356 front_handicap = TWDR;
360 case 0x95: // Aft Handicap
365 case 0xff: // bootloader
372 case 0xA8: // start read
375 case 0x02: // Motor 1 PWM
379 case 0x03: // Dummy to allow continous read
383 case 0x04: // Motor 2 PWM
387 case 0x05: // Dummy to allow continous read
391 case 0x06: // Motor 3 PWM
395 case 0x07: // Dummy to allow continous read
399 case 0x08: // Motor 4 PWM
403 case 0x09: // Dummy to allow continous read
407 case 0x10: // Hall 1 MSB
412 case 0x11: // Hall 1 LSB
416 case 0x12: // Hall 2 MSB
421 case 0x13: // Hall 2 LSB
425 case 0x14: // Hall 3 MSB
430 case 0x15: // Hall 3 LSB
434 case 0x16: // Hall 4 MSB
439 case 0x17: // Hall 4 LSB
443 case 0x20: // Motor 1 speed wish MSB
444 TWDR = speed1_wish>>8;
447 case 0x21: // Motor 1 speed wish LSB
451 case 0x22: // Motor 2 speed wish MSB
452 TWDR = speed2_wish>>8;
455 case 0x23: // Motor 2 speed wish LSB
459 case 0x24: // Motor 3 speed wish MSB
460 TWDR = speed3_wish>>8;
463 case 0x25: // Motor 3 speed wish LSB
467 case 0x26: // Motor 4 speed wish MSB
468 TWDR = speed4_wish>>8;
471 case 0x27: // Motor 4 speed wish LSB
475 case 0x30: // Motor 1 speed MSB
479 case 0x31: // Motor 1 speed LSB
483 case 0x32: // Motor 2 speed MSB
487 case 0x33: // Motor 2 speed LSB
491 case 0x34: // Motor 3 speed MSB
495 case 0x35: // Motor 3 speed LSB
499 case 0x36: // Motor 4 speed MSB
503 case 0x37: // Motor 4 speed LSB
507 case 0x38: // speed MSB
508 tmp_speed.f = cur_speed_lin;
509 TWDR = tmp_speed.i>>24;
513 TWDR = tmp_speed.i>>16;
517 TWDR = tmp_speed.i>>8;
520 case 0x3B: // speed LSB
524 case 0x3C: // angle MSB
525 tmp_angle.f = cur_speed_rot;
526 TWDR = tmp_angle.i>>24;
530 TWDR = tmp_angle.i>>16;
534 TWDR = tmp_angle.i>>8;
537 case 0x3F: // angle LSB
541 case 0x40: // Position x MSB
545 case 0x41: // Position x
549 case 0x42: // Position x
553 case 0x43: // Position x LSB
557 case 0x44: // Position y MSB
561 case 0x45: // Position y
565 case 0x46: // Position y
569 case 0x47: // Position y LSB
573 case 0x48: // Position angle MSB
577 case 0x49: // Position angle
581 case 0x4A: // Position angle
585 case 0x4B: // Position angle LSB
589 case 0xA0: // Reset reason
590 TWDR = MCUCSR & 0x0f;
594 case 0xA1: // Error status
598 case 0xA2: // count test
613 static void update_hall1(void) {
614 unsigned char status = (PINA >> 0) & 0x3;
615 static unsigned char oldstatus=0;
616 unsigned char diff, new;
622 new ^= 0x1; // convert gray to binary
623 diff = oldstatus - new; // difference last - new
624 if (diff & 0x1) { // bit 0 = value (1)
625 oldstatus = new; // store new as next last
626 if (motor1_switch) pos1 += (diff & 2) - 1; // bit 1 = direction (+/-)
627 else pos1 -= (diff & 2) - 1;
632 static void update_hall2(void) {
633 unsigned char status = (PINA >> 4) & 0x3;
634 static unsigned char oldstatus=0;
635 unsigned char diff, new;
641 new ^= 0x1; // convert gray to binary
642 diff = oldstatus - new; // difference last - new
643 if (diff & 0x1) { // bit 0 = value (1)
644 oldstatus = new; // store new as next last
645 if (motor2_switch) pos2 -= (diff & 2) - 1; // bit 1 = direction (+/-)
646 else pos2 += (diff & 2) - 1;
651 static void update_hall3(void) {
652 unsigned char status = (PINA >> 2) & 0x3;
653 static unsigned char oldstatus=0;
654 unsigned char diff, new;
660 new ^= 0x1; // convert gray to binary
661 diff = oldstatus - new; // difference last - new
662 if (diff & 0x1) { // bit 0 = value (1)
663 oldstatus = new; // store new as next last
664 if (motor3_switch) pos3 -= (diff & 2) - 1; // bit 1 = direction (+/-)
665 else pos3 += (diff & 2) - 1;
670 static void update_hall4(void) {
671 unsigned char status = (PINA >> 6) & 0x3;
672 static unsigned char oldstatus=0;
673 unsigned char diff, new;
679 new ^= 0x1; // convert gray to binary
680 diff = oldstatus - new; // difference last - new
681 if (diff & 0x1) { // bit 0 = value (1)
682 oldstatus = new; // store new as next last
683 if (motor4_switch) pos4 += (diff & 2) - 1; // bit 1 = direction (+/-)
684 else pos4 -= (diff & 2) - 1;
689 static void update_motor(void) {
690 static int16_t m1_old=SHRT_MIN;
691 static int16_t m2_old=SHRT_MIN;
692 static int16_t m3_old=SHRT_MIN;
693 static int16_t m4_old=SHRT_MIN;
695 error_state &= 0xf0; // clear lower bits
696 error_state |= ~((PIND & 0x40)>>3 | (PINB & 0x07)) & 0xf;
698 if (m1_old != motor1) { // update only when changed
701 PORTC &= ~(1 << 3) & ~(1 << 2);
702 } else if (motor1 == PWM_BREAK) {
703 PORTC |= (1 << 3) | (1 << 2);
704 } else if ((!motor1_switch && motor1 > 0) || (motor1_switch && motor1 < 0)) {
710 } else { // motor1 < 0
722 if (m2_old != motor2) { // update only when changed
725 PORTC &= ~(1 << 5) & ~(1 << 4);
726 } else if (motor2 == PWM_BREAK) {
727 PORTC |= (1 << 5) | (1 << 4);
728 } else if ((!motor2_switch && motor2 > 0) || (motor2_switch && motor2 < 0)) {
734 } else { // motor2 < 0
746 if (m3_old != motor3) { // update only when changed
749 PORTC &= ~(1 << 7) & ~(1 << 6);
750 } else if (motor3 == PWM_BREAK) {
751 PORTC |= (1 << 7) | (1 << 6);
752 } else if ((!motor3_switch && motor3 > 0) || (motor3_switch && motor3 < 0)) {
758 } else { // motor3 < 0
770 if (m4_old != motor4) { // update only when changed
773 PORTD &= ~(1 << 3) & ~(1 << 2);
774 } else if (motor4 == PWM_BREAK) {
775 PORTD |= (1 << 3) | (1 << 2);
776 } else if ((!motor4_switch && motor4 > 0) || (motor4_switch && motor4 < 0)) {
782 } else { // motor4 < 0
796 static void update_pos(void) {
797 static int16_t pos1_last=0;
798 static int16_t pos2_last=0;
799 static int16_t pos3_last=0;
800 static int16_t pos4_last=0;
801 int16_t pos1_diff; // steps
805 float diff_left_m, diff_right_m, angle_diff, translation;
806 float pos_x_new, pos_y_new, angle_new;
807 float tmp_speed_lin, tmp_speed_rot;
808 int16_t cur_pos1, cur_pos2, cur_pos3, cur_pos4;
809 int16_t new_speed1, new_speed2, new_speed3, new_speed4;
819 pos1_diff = cur_pos1 - pos1_last;
820 pos2_diff = cur_pos2 - pos2_last;
821 pos3_diff = cur_pos3 - pos3_last;
822 pos4_diff = cur_pos4 - pos4_last;
824 new_speed1 = pos1_diff/PID_T;
825 new_speed2 = pos2_diff/PID_T;
826 new_speed3 = pos3_diff/PID_T;
827 new_speed4 = pos4_diff/PID_T;
829 diff_left_m = (pos1_diff + pos2_diff)/(2*STEP_PER_M_LEFT);
830 diff_right_m = (pos3_diff + pos4_diff)/(2*STEP_PER_M_RIGHT);
831 angle_diff = (diff_right_m - diff_left_m) / WHEEL_DIST;
833 angle_new = angle.f + angle_diff;
834 if (angle_new > 2*M_PI) angle_new-=2*M_PI;
835 else if (angle_new < -2*M_PI) angle_new+=2*M_PI;
837 translation = (diff_left_m + diff_right_m)/2.0;
838 pos_x_new = pos_x.f + cos(angle_new)*translation;
839 pos_y_new = pos_y.f + sin(angle_new)*translation;
841 tmp_speed_lin = translation/PID_T;
842 tmp_speed_rot = angle_diff/PID_T;
853 cur_speed_lin = tmp_speed_lin;
854 cur_speed_rot = tmp_speed_rot;
857 pos1_last = cur_pos1;
858 pos2_last = cur_pos2;
859 pos3_last = cur_pos3;
860 pos4_last = cur_pos4;
864 static void update_pid(void) {
865 static int16_t eold1=0;
866 static int16_t eold2=0;
867 static int16_t eold3=0;
868 static int16_t eold4=0;
869 static int32_t esum1=0;
870 static int32_t esum2=0;
871 static int32_t esum3=0;
872 static int32_t esum4=0;
874 // protect motors from damage if stalling
875 if (labs(esum1) > 140000 && speed1 == 0) {
877 motor1_mode = MOTOR_MANUAL;
878 error_state |= (1<<4);
881 if (labs(esum2) > 140000 && speed2 == 0) {
883 motor2_mode = MOTOR_MANUAL;
884 error_state |= (1<<5);
887 if (labs(esum3) > 140000 && speed3 == 0) {
889 motor3_mode = MOTOR_MANUAL;
890 error_state |= (1<<6);
893 // protect motors from damage if stalling
894 if (labs(esum4) > 140000 && speed4 == 0) {
896 motor4_mode = MOTOR_MANUAL;
897 error_state |= (1<<7);
901 if (motor1_mode == MOTOR_PID) {
902 if (speed1_wish != speed1_wish_old) {
903 if (abs(speed1_wish - speed1_wish_old) > 500) esum1 = 0;
904 speed1_wish_old = speed1_wish;
907 if (speed1_wish == 0) {
910 error_state &= ~(1<<4);
912 int16_t e = speed1_wish - speed1;
914 motor1 = KP*e + KI*PID_T*esum1 + KD/PID_T*(e - eold1);
917 if (motor1 > 0 && speed1_wish < 0) motor1=PWM_BREAK;
918 else if (motor1 < 0 && speed1_wish > 0) motor1=PWM_BREAK;
919 else if (motor1 > 255) motor1 = 255;
920 else if (motor1 < -255) motor1 = -255;
923 if (motor2_mode == MOTOR_PID) {
924 if (speed2_wish != speed2_wish_old) {
925 if (abs(speed2_wish - speed2_wish_old) > 500) esum2 = 0;
926 speed2_wish_old = speed2_wish;
929 if (speed2_wish == 0) {
932 error_state &= ~(1<<5);
934 int16_t e = speed2_wish - speed2;
936 motor2 = KP*e + KI*PID_T*esum2 + KD/PID_T*(e - eold2);
939 if (motor2 > 0 && speed2_wish < 0) motor2=PWM_BREAK;
940 else if (motor2 < 0 && speed2_wish > 0) motor2=PWM_BREAK;
941 else if (motor2 > 255) motor2 = 255;
942 else if (motor2 < -255) motor2 = -255;
945 if (motor3_mode == MOTOR_PID) {
946 if (speed3_wish != speed3_wish_old) {
947 if (abs(speed3_wish - speed3_wish_old) > 500) esum3 = 0;
948 speed3_wish_old = speed3_wish;
951 if (speed3_wish == 0) {
954 error_state &= ~(1<<6);
956 int16_t e = speed3_wish - speed3;
958 motor3 = KP*e + KI*PID_T*esum3 + KD/PID_T*(e - eold3);
961 if (motor3 > 0 && speed3_wish < 0) motor3=PWM_BREAK;
962 else if (motor3 < 0 && speed3_wish > 0) motor3=PWM_BREAK;
963 else if (motor3 > 255) motor3 = 255;
964 else if (motor3 < -255) motor3 = -255;
967 if (motor4_mode == MOTOR_PID) {
968 if (speed4_wish != speed4_wish_old) {
969 if (abs(speed4_wish - speed4_wish_old) > 500) esum4 = 0;
970 speed4_wish_old = speed4_wish;
973 if (speed4_wish == 0) {
976 error_state &= ~(1<<7);
978 int16_t e = speed4_wish - speed4;
980 motor4 = KP*e + KI*PID_T*esum4 + KD/PID_T*(e - eold4);
983 if (motor4 > 0 && speed4_wish < 0) motor4=PWM_BREAK;
984 else if (motor4 < 0 && speed4_wish > 0) motor4=PWM_BREAK;
985 else if (motor4 > 255) motor4 = 255;
986 else if (motor4 < -255) motor4 = -255;
992 ISR(TIMER1_OVF_vect) {
1005 DDRC = (1 << 7) | (1 << 6) | (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2);
1006 DDRD = (1 << 7) | (1 << 5) | (1 << 4) | (1 << 3) | (1 << 2);
1007 // Pullup Diag/Enable
1008 PORTB = (1 << 0) | (1 << 1) | (1 << 2);
1013 uart_setup_stdout();
1020 // Timer 1: Fast PWM non-inverting mode, Top=255 => 15.625kHz
1022 TCCR1A = (1 << COM1A1) | (1 << COM1B1) | (1 << WGM10);
1023 TCCR1B = (1 << WGM12) | (1 << CS10);
1028 // Timer 2: Fast PWM non-inverting mode, Top=255
1030 TCCR2 = (1 << WGM21) | (1 << WGM20) | (1 << COM21) | (1 << CS20);
1034 // Timer 0: Fast PWM non-inverting mode, Top=255
1036 TCCR0 = (1 << WGM01) | (1 << WGM00) | (1 << COM01) | (1 << CS00);
1039 printf("\r\nStart\r\n");
1041 set_sleep_mode(SLEEP_MODE_IDLE);
1042 // Enable Timer 1 Overflow Interrupt
1043 TIMSK = (1 << TOIE1);
1048 case 0xff: // Magic reg that starts the bootloader
1049 if (bootloader == 0xa5) {
1052 void (*start)(void) = (void*)0x1800;
1059 if (cmd_vel.bUpdate) {
1060 float speed_wish_right, speed_wish_left;
1064 speed = cmd_vel.speed;
1065 angle = cmd_vel.angle;
1066 cmd_vel.bUpdate = 0;
1069 speed_wish_right = (angle*WHEEL_DIST)/2 + speed;
1070 speed_wish_left = speed*2-speed_wish_right;
1072 speed_wish_left*=STEP_PER_M_LEFT;
1073 speed_wish_right*=STEP_PER_M_RIGHT;
1075 if (aft_handicap > 0) {
1076 speed1_wish = speed_wish_left * (100-aft_handicap)/100.0;
1077 speed3_wish = speed_wish_right * (100-aft_handicap)/100.0;
1079 speed1_wish = speed_wish_left;
1080 speed3_wish = speed_wish_right;
1082 if (front_handicap > 0) {
1083 speed2_wish = speed_wish_left * (100-front_handicap)/100.0;
1084 speed4_wish = speed_wish_right * (100-front_handicap)/100.0;
1086 speed2_wish = speed_wish_left;
1087 speed4_wish = speed_wish_right;
1089 motor1_mode = MOTOR_PID;
1090 motor2_mode = MOTOR_PID;
1091 motor3_mode = MOTOR_PID;
1092 motor4_mode = MOTOR_PID;
1095 if (run_update >= 156) { // ~100Hz