X-Git-Url: https://defiant.homedns.org/gitweb/?p=ros_wild_thumper.git;a=blobdiff_plain;f=avr%2Fmotor_ctrl%2Fmain.c;h=66a7c4afd63af534cb47608eb82c805bcf7dd2fd;hp=5c6a667f28449ca59c3ec96890a8726343a1333e;hb=f01d69d0a1b761c2d7c4f662b5be998fc1a889c8;hpb=dc43ace40c91efd3f0ed892898d5e1d62c2f2fd9;ds=sidebyside diff --git a/avr/motor_ctrl/main.c b/avr/motor_ctrl/main.c index 5c6a667..66a7c4a 100644 --- a/avr/motor_ctrl/main.c +++ b/avr/motor_ctrl/main.c @@ -101,8 +101,8 @@ #define TWI_RESET TWCR &= ~((1 << TWSTO) | (1 << TWEN)); TWI_ACK #define TWI_NAK TWCR = (1< 255) motor1 = 255; + if (motor1 > 0 && speed1_wish < 0) motor1=0; + else if (motor1 < 0 && speed1_wish > 0) motor1=0; + else if (motor1 > 255) motor1 = 255; else if (motor1 < -255) motor1 = -255; } } @@ -886,7 +888,9 @@ static void update_pid(void) { motor2 = KP*e + KI*PID_T*esum2 + KD/PID_T*(e - eold2); eold2 = e; - if (motor2 > 255) motor2 = 255; + if (motor2 > 0 && speed2_wish < 0) motor2=0; + else if (motor2 < 0 && speed2_wish > 0) motor2=0; + else if (motor2 > 255) motor2 = 255; else if (motor2 < -255) motor2 = -255; } } @@ -901,7 +905,9 @@ static void update_pid(void) { motor3 = KP*e + KI*PID_T*esum3 + KD/PID_T*(e - eold3); eold3 = e; - if (motor3 > 255) motor3 = 255; + if (motor3 > 0 && speed3_wish < 0) motor3=0; + else if (motor3 < 0 && speed3_wish > 0) motor3=0; + else if (motor3 > 255) motor3 = 255; else if (motor3 < -255) motor3 = -255; } } @@ -916,7 +922,9 @@ static void update_pid(void) { motor4 = KP*e + KI*PID_T*esum4 + KD/PID_T*(e - eold4); eold4 = e; - if (motor4 > 255) motor4 = 255; + if (motor4 > 0 && speed4_wish < 0) motor4=0; + else if (motor4 < 0 && speed4_wish > 0) motor4=0; + else if (motor4 > 255) motor4 = 255; else if (motor4 < -255) motor4 = -255; } }