Commit a6f948f4 authored by cdemp's avatar cdemp
Browse files
parents 000ed127 46da06c0
......@@ -79,10 +79,11 @@ void encoder_setup(void)
pinMode(Z, INPUT); // sets the Z signal as digital pin input
//interupt when the z position is found
//TODO: Move this to after the setup.
attachInterrupt(digitalPinToInterrupt(Z), isr_index, RISING);
encoder.setup();
encoder.start();// Start Quad Decode position count
encoder.setup(); // Look at A and B channels and calculate our count
encoder.start();// Start Quad Decode position count (A and B channels)
//xPosn.zeroFTM(); //This zeros the counter
......@@ -95,6 +96,7 @@ void encoder_setup(void)
delay(1000); //sit tight for a bit
//setup interupts to allow button presses
// TODO: Ask Matt about button presses.
pinMode(ButtonA, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(ButtonA), buttonA_ISR, RISING);
pinMode(ButtonB, INPUT_PULLUP);
......@@ -316,7 +318,7 @@ void set_calibration_complete()
void debug_encoder(void)
{
while(1){
int position = encoder.calcPosn();
/*int position = encoder.calcPosn();*/
static int lastZoffset = 0;
static int lastNetPosition = 0;
int netPosition = 0;
......
......@@ -55,6 +55,8 @@ H TO TO SEND SPECIFIC PHASES DEBUG MOTOR\n");
case ' ':
break;
case 'z':
// Use this function to calculate a new Z-Offset when the encoder has been
// decoupled from the motor.
charge_bootstrap_capacitors();
do_hard_coded_offset();// run the set zero
break;
......@@ -76,6 +78,7 @@ H TO TO SEND SPECIFIC PHASES DEBUG MOTOR\n");
motor_butt_control_inefficient();
break;
case 's':
// This is our default when not in debug mode
charge_bootstrap_capacitors();
motor_butt_control_precalculated();
break;
......@@ -163,7 +166,7 @@ H TO TO SEND SPECIFIC PHASES DEBUG MOTOR\n");
void loop()
{
//hold on to the old phase number
static int last_phase = 0;
/*static int last_phase = 0;*/
// get the current encoder tics (this does the math to offset)
int position = get_wheel_position_ticks();
......
......@@ -63,12 +63,12 @@ void motor_setup(void) {
pinMode(L1, OUTPUT);
pinMode(L2, OUTPUT);
pinMode(L3, OUTPUT);
pinMode(H1, OUTPUT);
pinMode(H2, OUTPUT);
pinMode(H3, OUTPUT);
pinMode(L1, OUTPUT); // pin 5
pinMode(L2, OUTPUT); // pin 20
pinMode(L3, OUTPUT); // pin 22
pinMode(H1, OUTPUT); // pin 6
pinMode(H2, OUTPUT); // pin 21
pinMode(H3, OUTPUT); // pin 23
//PWM setup
......@@ -98,6 +98,7 @@ void motor_setup(void) {
digitalWrite(time_led, LOW);
//setup the pot_0_timer and the coast_timer to run thirty times a second to find value from pot
// 30 times a second, go check the pot value via ISR
pot_0_timer.begin(pot_0_speed_ISR, 33333);
}
......@@ -253,22 +254,23 @@ void set_phase_float(float f1, float f2, float f3)
sei();
//digitalWrite(led, LOW);// stop a timer
// Scaling sin factor by pot value to make it more reasonible -> If throttle is 0, dont do anything
f1 = (f1 * potval);
f2 = (f2 * potval);
f3 = (f3 * potval);
// Val 0-255 scaled by pot and f1
int f1i = (int) f1;
int f2i = (int) f2;
int f3i = (int) f3;
// The if and else if stuff here is forcing H1/L1/H2/L2/H3/L3 to be written in a specific, right way
if ( (last_f1i == 0) && (f1i != 0) )
{
// f1 used to have low side on now has high side on
// turn off f1 low side first then do f1s high side
analogWrite(L1, 0);
analogWrite(H1, f1i);
analogWrite(H1, f1i); //0 = full off duty cycle, 255 = full on duty cycle
}
else if ( (last_f1i != 0) && (f1i == 0) ){
......@@ -388,7 +390,7 @@ void motor_butt_control_precalculated(void)
}
//This just spins the motor using speed (potentiometer on pin A1)
//and torque (potentiometer on pin A0)
//and torque (potentiometer on pin A1)
void open_loop_control(void)
{
// This is just a stupid work around for now
......
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