Commit f1e320d7 authored by mattdr's avatar mattdr
Browse files

added buttons to hone in the offset

parent f75a6184
This diff is collapsed.
This diff is collapsed.
......@@ -20,7 +20,17 @@ int Zoffset = 0;
// This is the difference in encoder tics from the Z index to
// the electrical encoder zero (which is found by powering the
// AB block and waiting for the motor to settle)
int hard_coded_offset = -1042;
int hard_coded_offset = -307;
//Invert position to invert position add 341 to any offset
// hand calibration (done by buttons)
int button_offset = 0;
//how much of an effect the button press has
int button_offset_increment = 5;
// how long in microsec (us) to delay between phases while calibrating
// the wheel
......@@ -29,6 +39,10 @@ int calibration_delay = 1000;
// Timer setup (for speed calc)
IntervalTimer speed_timer;
// buttons (for hand tuneing)
int ButtonA = 11;
int ButtonB = 12;
//forward declarations
void isr_index(void);
int wrap_wheel_tics(int in_position);
......@@ -39,6 +53,8 @@ int get_raw_wheel_position_ticks(void);
int get_elec_rev_position_ticks(int mechanical_position);
int get_phase_number(int elec_position);
void print_speed_ISR(void);
void buttonA_ISR(void);
void buttonB_ISR(void);
......@@ -68,7 +84,38 @@ void encoder_setup(void)
//setup the speed timer to run every 1 sec
speed_timer.begin(print_speed_ISR, 1000000);
delay(5000); //sit tight for a bit
delay(1000); //sit tight for a bit
//setup interupts to allow button presses
pinMode(ButtonA, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(ButtonA), buttonA_ISR, RISING);
pinMode(ButtonB, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(ButtonB), buttonB_ISR, RISING);
}
void buttonA_ISR(){
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
if (interrupt_time - last_interrupt_time > 125)
{
button_offset += button_offset_increment;
Serial.print("+ Button Offset: ");
Serial.println(button_offset);
}
last_interrupt_time = interrupt_time;
}
void buttonB_ISR(){
static unsigned long last_interrupt_time = 0;
unsigned long interrupt_time = millis();
if (interrupt_time - last_interrupt_time > 125)
{
button_offset -= button_offset_increment;
Serial.print("- Button Offset: ");
Serial.println(button_offset);
}
last_interrupt_time = interrupt_time;
}
// Interrupt that is used to print out speed every so often
......@@ -116,7 +163,11 @@ int get_Zoffset(void)
int get_wheel_position_ticks(void)
{
int raw_position = encoder.calcPosn();
return wrap_wheel_tics(raw_position - Zoffset - hard_coded_offset);
cli();
int my_position = raw_position - Zoffset - hard_coded_offset - button_offset;
sei();
int wrapped_position = wrap_wheel_tics(my_position);
return wrapped_position;
}
......
......@@ -89,6 +89,8 @@ void motor_setup(void) {
//setup the pot_0_timer to run every thirty times a second
pot_0_timer.begin(pot_0_speed_ISR, 33333);
}
void pot_0_speed_ISR() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment