Commit 214f6829 authored by skwirskj's avatar skwirskj
Browse files

Added Comments to main, motor_ctrl, and encoder

Added someone comments to clarify what is happening in these files. Also added a comment in main to instruct when a new Z-offset should be found.
parent 664b0a77
...@@ -79,10 +79,11 @@ void encoder_setup(void) ...@@ -79,10 +79,11 @@ void encoder_setup(void)
pinMode(Z, INPUT); // sets the Z signal as digital pin input pinMode(Z, INPUT); // sets the Z signal as digital pin input
//interupt when the z position is found //interupt when the z position is found
//TODO: Move this to after the setup.
attachInterrupt(digitalPinToInterrupt(Z), isr_index, RISING); attachInterrupt(digitalPinToInterrupt(Z), isr_index, RISING);
encoder.setup(); encoder.setup(); // Look at A and B channels and calculate our count
encoder.start();// Start Quad Decode position count encoder.start();// Start Quad Decode position count (A and B channels)
//xPosn.zeroFTM(); //This zeros the counter //xPosn.zeroFTM(); //This zeros the counter
...@@ -95,6 +96,7 @@ void encoder_setup(void) ...@@ -95,6 +96,7 @@ void encoder_setup(void)
delay(1000); //sit tight for a bit delay(1000); //sit tight for a bit
//setup interupts to allow button presses //setup interupts to allow button presses
// TODO: Ask Matt about button presses.
pinMode(ButtonA, INPUT_PULLUP); pinMode(ButtonA, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(ButtonA), buttonA_ISR, RISING); attachInterrupt(digitalPinToInterrupt(ButtonA), buttonA_ISR, RISING);
pinMode(ButtonB, INPUT_PULLUP); pinMode(ButtonB, INPUT_PULLUP);
...@@ -316,7 +318,7 @@ void set_calibration_complete() ...@@ -316,7 +318,7 @@ void set_calibration_complete()
void debug_encoder(void) void debug_encoder(void)
{ {
while(1){ while(1){
int position = encoder.calcPosn(); /*int position = encoder.calcPosn();*/
static int lastZoffset = 0; static int lastZoffset = 0;
static int lastNetPosition = 0; static int lastNetPosition = 0;
int netPosition = 0; int netPosition = 0;
......
...@@ -55,6 +55,8 @@ H TO TO SEND SPECIFIC PHASES DEBUG MOTOR\n"); ...@@ -55,6 +55,8 @@ H TO TO SEND SPECIFIC PHASES DEBUG MOTOR\n");
case ' ': case ' ':
break; break;
case 'z': case 'z':
// Use this function to calculate a new Z-Offset when the encoder has been
// decoupled from the motor.
charge_bootstrap_capacitors(); charge_bootstrap_capacitors();
do_hard_coded_offset();// run the set zero do_hard_coded_offset();// run the set zero
break; break;
...@@ -76,6 +78,7 @@ H TO TO SEND SPECIFIC PHASES DEBUG MOTOR\n"); ...@@ -76,6 +78,7 @@ H TO TO SEND SPECIFIC PHASES DEBUG MOTOR\n");
motor_butt_control_inefficient(); motor_butt_control_inefficient();
break; break;
case 's': case 's':
// This is our default when not in debug mode
charge_bootstrap_capacitors(); charge_bootstrap_capacitors();
motor_butt_control_precalculated(); motor_butt_control_precalculated();
break; break;
...@@ -163,7 +166,7 @@ H TO TO SEND SPECIFIC PHASES DEBUG MOTOR\n"); ...@@ -163,7 +166,7 @@ H TO TO SEND SPECIFIC PHASES DEBUG MOTOR\n");
void loop() void loop()
{ {
//hold on to the old phase number //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) // get the current encoder tics (this does the math to offset)
int position = get_wheel_position_ticks(); int position = get_wheel_position_ticks();
......
...@@ -63,12 +63,12 @@ void motor_setup(void) { ...@@ -63,12 +63,12 @@ void motor_setup(void) {
pinMode(L1, OUTPUT); pinMode(L1, OUTPUT); // pin 5
pinMode(L2, OUTPUT); pinMode(L2, OUTPUT); // pin 20
pinMode(L3, OUTPUT); pinMode(L3, OUTPUT); // pin 22
pinMode(H1, OUTPUT); pinMode(H1, OUTPUT); // pin 6
pinMode(H2, OUTPUT); pinMode(H2, OUTPUT); // pin 21
pinMode(H3, OUTPUT); pinMode(H3, OUTPUT); // pin 23
//PWM setup //PWM setup
...@@ -98,6 +98,7 @@ void motor_setup(void) { ...@@ -98,6 +98,7 @@ void motor_setup(void) {
digitalWrite(time_led, LOW); digitalWrite(time_led, LOW);
//setup the pot_0_timer and the coast_timer to run thirty times a second to find value from pot //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); pot_0_timer.begin(pot_0_speed_ISR, 33333);
} }
...@@ -252,22 +253,23 @@ void set_phase_float(float f1, float f2, float f3) ...@@ -252,22 +253,23 @@ void set_phase_float(float f1, float f2, float f3)
sei(); sei();
//digitalWrite(led, LOW);// stop a timer //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); f1 = (f1 * potval);
f2 = (f2 * potval); f2 = (f2 * potval);
f3 = (f3 * potval); f3 = (f3 * potval);
// Val 0-255 scaled by pot and f1
int f1i = (int) f1; int f1i = (int) f1;
int f2i = (int) f2; int f2i = (int) f2;
int f3i = (int) f3; 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) ) if ( (last_f1i == 0) && (f1i != 0) )
{ {
// f1 used to have low side on now has high side on // f1 used to have low side on now has high side on
// turn off f1 low side first then do f1s high side // turn off f1 low side first then do f1s high side
analogWrite(L1, 0); 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) ){ else if ( (last_f1i != 0) && (f1i == 0) ){
......
...@@ -24,7 +24,7 @@ void checkDebugJumper() { ...@@ -24,7 +24,7 @@ void checkDebugJumper() {
} }
bool getDebugOn() { bool getDebugOn() {
return false; //uncomment to disable debug mode return true; //uncomment to disable debug mode
//return true; //return true;
//return DEBUG_JUMPER_ON; //return DEBUG_JUMPER_ON;
} }
......
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