X-Git-Url: https://defiant.homedns.org/gitweb/?p=ros_wild_thumper.git;a=blobdiff_plain;f=avr%2Fmotor_ctrl%2Fmain.c;h=3642d4a8b222e59530eaafb28cb8a287f3dcd4da;hp=16c8b0cc2d0c2a51d364d00b603270f79d58e20a;hb=d1683df60f044ecabcda11f24c835122a8cf20e4;hpb=5077968a53d2753a51d0d765275259468fa012b2 diff --git a/avr/motor_ctrl/main.c b/avr/motor_ctrl/main.c index 16c8b0c..3642d4a 100644 --- a/avr/motor_ctrl/main.c +++ b/avr/motor_ctrl/main.c @@ -5,6 +5,9 @@ #include #include #include +#include +#include +#include #include "uart.h" /* @@ -104,15 +107,16 @@ // wheel diameter=12cm, encoder=48cpr, gear ratio=1:47 // STEP_PER_M = 48*47/(d*pi) // Left real diameter: 0.12808, Right real diameter: 0.121 -#define STEP_PER_M 5770.8 +#define STEP_PER_M 5573.0 #define STEP_PER_M_LEFT (STEP_PER_M) #define STEP_PER_M_RIGHT (STEP_PER_M) #define WHEEL_DIST 0.39912 // Measured: 0.252 #define PWM_BREAK INT16_MIN +#define STALL_LIMIT 140000 -#define TWI_ACK TWCR = (1< 140000 && speed1 == 0) { + if (labs(esum1) > STALL_LIMIT && speed1 == 0) { motor1 = 0; motor1_mode = MOTOR_MANUAL; error_state |= (1<<4); esum1 = 0; } - if (labs(esum2) > 140000 && speed2 == 0) { + if (labs(esum2) > STALL_LIMIT && speed2 == 0) { motor2 = 0; motor2_mode = MOTOR_MANUAL; error_state |= (1<<5); esum2 = 0; } - if (labs(esum3) > 140000 && speed3 == 0) { + if (labs(esum3) > STALL_LIMIT && speed3 == 0) { motor3 = 0; motor3_mode = MOTOR_MANUAL; error_state |= (1<<6); esum3 = 0; } - if (labs(esum4) > 140000 && speed4 == 0) { + if (labs(esum4) > STALL_LIMIT && speed4 == 0) { motor4 = 0; motor4_mode = MOTOR_MANUAL; error_state |= (1<<7); @@ -1040,7 +1047,7 @@ int main(void) { // I2C TWAR = 0x50; - TWI_RESET; + TWI_ACK; // Motor 1 & 2 // Also used for PWM frequency TIMER1_FREQ (F_CPU/256) @@ -1081,10 +1088,11 @@ int main(void) { case 0xff: // Magic reg that starts the bootloader if (bootloader == 0xa5) { cli(); - { - void (*start)(void) = (void*)0x1800; - start(); - } + // write mark to first area in eeprom + eeprom_write_byte((uint8_t*)0, 123); + eeprom_busy_wait(); + // Use watchdog to restart + wdt_enable(WDTO_15MS); } break; }