uint16_t pid_find_max_encoder_value(void){ uint16_t enc_val = 0, prev_enc_val = -1; motor_speed(75); //Stop at left end while(enc_val != prev_enc_val){ printf("In while\n"); enc_val = motor_encoder_read(); _delay_ms(100); prev_enc_val = motor_encoder_read(); } printf("Out of while\n"); motor_speed(0); motor_encoder_reset(); //Stop at right end and set max motor_speed(-75); enc_val = 0, prev_enc_val = -1; while(enc_val != prev_enc_val){ enc_val = motor_encoder_read(); _delay_ms(100); prev_enc_val = motor_encoder_read(); } motor_speed(0); //Max value of encoder. return enc_val; }
void motor_init(void) { DDRF |= (1<<MOTOR_DIR) | (1<<MOTOR_EN) | (1<<MOTOR_SEL) | (1<<MOTOR_RST) | (1<<MOTOR_OE); DDRK = 0; PORTF |= (1 << MOTOR_EN); motor_encoder_reset(); }
//MOTOR SPEED NEEDS TO BE TUNED FOR INDIVIDUAL GAME BOARD void motor_controller_calibrate_by_reset(){ uint8_t speed = 65; motor_init(); uint16_t position; uint16_t prev_position; motor_speed(speed); motor_direction(right); _delay_ms(150); position = motor_encoder_read(); //go right until stopped, then set encoder to zero while(position != prev_position){ position = motor_encoder_read(); _delay_ms(100); prev_position = position; position = motor_encoder_read(); printf("position: %u\tPrev: %u\n", position, prev_position); } motor_encoder_reset(); motor_speed(speed); motor_direction(left); _delay_ms(150); //go left until stopped, set max left to current position do{ position = motor_encoder_read(); _delay_ms(100); prev_position = position; position = motor_encoder_read(); printf("position: %d\n", position); } while(position != prev_position); max_left = position; motor_speed(0); motor_speed(speed); motor_direction(right); _delay_ms(100); while(motor_encoder_read() > 4500){ _delay_ms(100); } }
// Initializes the motor in port C void motor_init() { max520_init(MAX520_TWI_ADDRESS); DDRC |= (1<<PC3) | (1<<PC4) | (1<<PC5) | (1<<PC6) | (1<<PC7); DDRK = 0; motor_output_enable(ENABLE); motor_encoder_reset(); motor_encoder_select_byte(ENCODER_HIGH); motor_speed(0); motor_enable(ENABLE); }
void motor_init(){ max520_init(); MOTOR_DDR |= (1 << MOTOR_EN) | (1 << MOTOR_DIR) | (1 << MOTOR_SEL) | (1 << MOTOR_ENCODER_RESET) | (1 << MOTOR_OUTPUT_EN); MOTOR_PORT |= (1 << MOTOR_EN) | (1 << MOTOR_DIR) | (1 << MOTOR_SEL); MOTOR_PORT &= ~(1 << MOTOR_OUTPUT_EN); DDRK = 0; motor_encoder_reset(); }
uint16_t controller_init(){ motor_speed(75); uint16_t enc_val = 0, prev_enc_val = -1; while(enc_val != prev_enc_val){ enc_val = motor_encoder_read(); _delay_ms(100); prev_enc_val = motor_encoder_read(); } motor_speed(0); motor_encoder_reset(); motor_speed(-75); enc_val = 0, prev_enc_val = -1; while(enc_val != prev_enc_val){ enc_val = motor_encoder_read(); _delay_ms(100); prev_enc_val = motor_encoder_read(); } motor_speed(0); //Find max value of encoder. return enc_val; }