Commit 6e3996c3 authored by mattdr's avatar mattdr
Browse files

Merge branch 'master' of gitlab.eecs.umich.edu:mattdr/supermileage_2018

parents 90a306ce 1cdc7e6b
*.DS_Store
*.checksum
*.code-workspace
...@@ -258,11 +258,11 @@ int calibrate_encoder() ...@@ -258,11 +258,11 @@ int calibrate_encoder()
set_block_phase(p); set_block_phase(p);
delayMicroseconds(CALIBRATION_DELAY); delayMicroseconds(CALIBRATION_DELAY);
} }
turn_all_off(); turn_all_mosfets_off();
if(calibrated == true){ if(calibrated == true){
//ditch the interrupt //ditch the interrupt
turn_all_off(); turn_all_mosfets_off();
detachInterrupt(digitalPinToInterrupt(Z)); detachInterrupt(digitalPinToInterrupt(Z));
if(getDebugOn()) { if(getDebugOn()) {
...@@ -275,7 +275,7 @@ int calibrate_encoder() ...@@ -275,7 +275,7 @@ int calibrate_encoder()
} }
} }
turn_all_off(); turn_all_mosfets_off();
Serial.println("CALIBRATION FAILED"); Serial.println("CALIBRATION FAILED");
return -1; return -1;
} }
......
...@@ -48,57 +48,98 @@ H TO TO SEND SPECIFIC PHASES DEBUG MOTOR\n"); ...@@ -48,57 +48,98 @@ H TO TO SEND SPECIFIC PHASES DEBUG MOTOR\n");
if (Serial.available()) { if (Serial.available()) {
incomingByte = Serial.read(); incomingByte = Serial.read();
} }
if(incomingByte == ' ')//space bar switch(incomingByte) {
{ case ' ':
break; break;
} case 'z':
else if(incomingByte == 'z') //'z' charge_bootstrap_capacitors();
{ do_hard_coded_offset();// run the set zero
charge_bootstrap_capacitors(); break;
do_hard_coded_offset();// run the set zero case 'o':
} charge_bootstrap_capacitors();
else if(incomingByte == 'o') //'o' open_loop_control();
{ break;
charge_bootstrap_capacitors(); case 'l':
open_loop_control(); charge_bootstrap_capacitors();
} locate_state_positions();
else if(incomingByte == 'l') //'l' break;
{ case 'd':
charge_bootstrap_capacitors(); charge_bootstrap_capacitors();
locate_state_positions(); direct_position_control();
} break;
else if (incomingByte == 'd') //'d' case 'b':
{ charge_bootstrap_capacitors();
charge_bootstrap_capacitors(); motor_butt_control_inefficient();
direct_position_control(); break;
} case 's':
else if (incomingByte == 'b') //'b' charge_bootstrap_capacitors();
{ motor_butt_control_precalculated();
charge_bootstrap_capacitors(); break;
motor_butt_control_inefficient(); case 'y':
} debug_low_state_by_state();
else if (incomingByte == 's') //'s' break;
{ case 'u':
charge_bootstrap_capacitors(); debug_pot_0_scaled();
motor_butt_control_precalculated(); break;
} case 'k':
else if (incomingByte == 'y') // 'y' debug_encoder();
{ break;
debug_low_state_by_state(); case 'h':
} debug_motor();
else if (incomingByte == 'u') //'u' break;
{
debug_pot_0_scaled();
}
else if (incomingByte == 'k') //'k'
{
debug_encoder();
}
else if (incomingByte == 'h') //'h'
{
debug_motor();
} }
// if(incomingByte == ' ')//space bar
// {
// break;
// }
// else if(incomingByte == 'z') //'z'
// {
// charge_bootstrap_capacitors();
// do_hard_coded_offset();// run the set zero
// }
// else if(incomingByte == 'o') //'o'
// {
// charge_bootstrap_capacitors();
// open_loop_control();
// }
// else if(incomingByte == 'l') //'l'
// {
// charge_bootstrap_capacitors();
// locate_state_positions();
// }
// else if (incomingByte == 'd') //'d'
// {
// charge_bootstrap_capacitors();
// direct_position_control();
// }
// else if (incomingByte == 'b') //'b'
// {
// charge_bootstrap_capacitors();
// motor_butt_control_inefficient();
// }
// else if (incomingByte == 's') //'s'
// {
// charge_bootstrap_capacitors();
// motor_butt_control_precalculated();
// }
// else if (incomingByte == 'y') // 'y'
// {
// debug_low_state_by_state();
// }
// else if (incomingByte == 'u') //'u'
// {
// debug_pot_0_scaled();
// }
// else if (incomingByte == 'k') //'k'
// {
// debug_encoder();
// }
// else if (incomingByte == 'h') //'h'
// {
// debug_motor();
// }
} }
charge_bootstrap_capacitors(); charge_bootstrap_capacitors();
......
...@@ -46,7 +46,7 @@ int POT_0_VALUE = 0; ...@@ -46,7 +46,7 @@ int POT_0_VALUE = 0;
void pot_0_speed_ISR(); void pot_0_speed_ISR();
void turn_all_off(); void turn_all_mosfets_off();
int one_to_scaleFactor(int x); int one_to_scaleFactor(int x);
void set_phase(int high1, int high2, int high3, int low1, int low2, int low3); void set_phase(int high1, int high2, int high3, int low1, int low2, int low3);
void set_block_phase(int phase); void set_block_phase(int phase);
...@@ -79,7 +79,7 @@ void motor_setup(void) { ...@@ -79,7 +79,7 @@ void motor_setup(void) {
analogWriteFrequency(L2, FREQ); analogWriteFrequency(L2, FREQ);
analogWriteFrequency(L3, FREQ); analogWriteFrequency(L3, FREQ);
turn_all_off(); turn_all_mosfets_off();
//setup the halfbridges enables //setup the halfbridges enables
// pinMode(HB1EN, OUTPUT); // pinMode(HB1EN, OUTPUT);
...@@ -117,7 +117,7 @@ void pot_0_speed_ISR() { ...@@ -117,7 +117,7 @@ void pot_0_speed_ISR() {
// } // }
} }
void turn_all_off() { void turn_all_mosfets_off() {
analogWrite(L1, 0); analogWrite(L1, 0);
analogWrite(L2, 0); analogWrite(L2, 0);
analogWrite(L3, 0); analogWrite(L3, 0);
...@@ -176,7 +176,7 @@ void set_block_phase(int phase) ...@@ -176,7 +176,7 @@ void set_block_phase(int phase)
set_phase(0,0,1,0,1,0); //Phase CB set_phase(0,0,1,0,1,0); //Phase CB
break; break;
default : default :
turn_all_off(); turn_all_mosfets_off();
//no break needed //no break needed
} }
return; return;
...@@ -261,25 +261,30 @@ void set_phase_float(float f1, float f2, float f3) ...@@ -261,25 +261,30 @@ void set_phase_float(float f1, float f2, float f3)
int f2i = (int) f2; int f2i = (int) f2;
int f3i = (int) f3; int f3i = (int) f3;
bool f1_is_transient = false;
bool f2_is_transient = false;
bool f3_is_transient = false;
// work with transient states
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);
f1_is_transient = true;
} }
else if ( (last_f1i != 0) && (f1i == 0) ){ else if ( (last_f1i != 0) && (f1i == 0) ){
//f1 used to have high side running now has low side on //f1 used to have high side running now has low side on
// turn off the high side first then do f1s low side // turn off the high side first then do f1s low side
analogWrite(H1, 0); analogWrite(H1, 0);
analogWrite(L1, 255); analogWrite(L1, 255);
f1_is_transient = true;
}
else {
if (f1i == 0) {
analogWrite(L1, 255);
}
else{
analogWrite(L1, 0);
}
analogWrite(H1, f1i);
} }
if ( (last_f2i == 0) && (f2i != 0) ) if ( (last_f2i == 0) && (f2i != 0) )
...@@ -288,16 +293,22 @@ void set_phase_float(float f1, float f2, float f3) ...@@ -288,16 +293,22 @@ void set_phase_float(float f1, float f2, float f3)
// turn off f2 low side first then do f2s high side // turn off f2 low side first then do f2s high side
analogWrite(L2, 0); analogWrite(L2, 0);
analogWrite(H2, f2i); analogWrite(H2, f2i);
f2_is_transient = true;
} }
else if ( (last_f2i != 0) && (f2i == 0) ){ else if ( (last_f2i != 0) && (f2i == 0) ){
//f2 used to have high side running now has low side on //f2 used to have high side running now has low side on
// turn off the high side first then do f2s low side // turn off the high side first then do f2s low side
analogWrite(H2, 0); analogWrite(H2, 0);
analogWrite(L2, 255); analogWrite(L2, 255);
f2_is_transient = true;
} }
else {
if(f2i == 0){
analogWrite(L2, 255);
}
else{
analogWrite(L2, 0);
}
analogWrite(H2, f2i);
}
if ( (last_f3i == 0) && (f3i != 0) ) if ( (last_f3i == 0) && (f3i != 0) )
{ {
...@@ -305,38 +316,14 @@ void set_phase_float(float f1, float f2, float f3) ...@@ -305,38 +316,14 @@ void set_phase_float(float f1, float f2, float f3)
// turn off f3 low side first then do f3s high side // turn off f3 low side first then do f3s high side
analogWrite(L3, 0); analogWrite(L3, 0);
analogWrite(H3, f3i); analogWrite(H3, f3i);
f3_is_transient = true;
} }
else if ( (last_f3i != 0) && (f3i == 0) ){ else if ( (last_f3i != 0) && (f3i == 0) ){
//f3 used to have high side running now has low side on //f3 used to have high side running now has low side on
// turn off the high side first then do f3s low side // turn off the high side first then do f3s low side
analogWrite(H3, 0); analogWrite(H3, 0);
analogWrite(L3, 255); analogWrite(L3, 255);
f3_is_transient = true;
} }
else {
if (! f1_is_transient){
if(f1i == 0){
analogWrite(L1, 255);
}
else{
analogWrite(L1, 0);
}
analogWrite(H1, f1i);
}
if (! f2_is_transient){
if(f2i == 0){
analogWrite(L2, 255);
}
else{
analogWrite(L2, 0);
}
analogWrite(H2, f2i);
}
if (! f3_is_transient){
if(f3i == 0){ if(f3i == 0){
analogWrite(L3, 255); analogWrite(L3, 255);
} }
...@@ -349,8 +336,6 @@ void set_phase_float(float f1, float f2, float f3) ...@@ -349,8 +336,6 @@ void set_phase_float(float f1, float f2, float f3)
last_f1i = f1i; last_f1i = f1i;
last_f2i = f2i; last_f2i = f2i;
last_f3i = f3i; last_f3i = f3i;
} }
void motor_butt_control_inefficient(void) void motor_butt_control_inefficient(void)
...@@ -435,11 +420,11 @@ void open_loop_control(void) ...@@ -435,11 +420,11 @@ void open_loop_control(void)
// this should allways be called right before powering the motor // this should allways be called right before powering the motor
void charge_bootstrap_capacitors(void) void charge_bootstrap_capacitors(void)
{ {
turn_all_off(); turn_all_mosfets_off();
delayMicroseconds(50); delayMicroseconds(50);
set_phase(0,0,0,1,1,1); set_phase(0,0,0,1,1,1);
delayMicroseconds(50); delayMicroseconds(50);
turn_all_off(); turn_all_mosfets_off();
} }
//using hardcoded located state positions //using hardcoded located state positions
...@@ -565,7 +550,7 @@ void debug_motor(void) { ...@@ -565,7 +550,7 @@ void debug_motor(void) {
set_phase(0,0,1,0,1,0); set_phase(0,0,1,0,1,0);
delay(10); delay(10);
} }
turn_all_off(); turn_all_mosfets_off();
Serial.println("DONE WITH AROUND THE WORLD"); Serial.println("DONE WITH AROUND THE WORLD");
case 1: case 1:
...@@ -599,7 +584,7 @@ void debug_motor(void) { ...@@ -599,7 +584,7 @@ void debug_motor(void) {
break; break;
case -16: case -16:
turn_all_off(); turn_all_mosfets_off();
Serial.println("STOP THE PRESSES!!!"); Serial.println("STOP THE PRESSES!!!");
break; break;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
#define MOTOR_CTRL_H_ #define MOTOR_CTRL_H_
void motor_setup(void); void motor_setup(void);
void turn_all_off(); void turn_all_mosfets_off();
void set_block_phase(int phase); void set_block_phase(int phase);
void debug_motor(void); void debug_motor(void);
void open_loop_control(void); void open_loop_control(void);
......
...@@ -56,6 +56,20 @@ int get_pot_1_inv(void) ...@@ -56,6 +56,20 @@ int get_pot_1_inv(void)
return (int)potval; //read from pot return (int)potval; //read from pot
} }
//Helper funtion for limiting change of potval
int ROC_limiter(int potval) {
//If a positive change is larger than the limit, slow down how fast it changes
if ((potval - UPWARD_ROC_PREV_VALUE) > UPWARD_ROC_LIMITER) {
potval = UPWARD_ROC_PREV_VALUE + UPWARD_ROC_LIMITER;
}
//If a negative change is larger than the limit, slow down how fast it changes
else if ((potval - UPWARD_ROC_PREV_VALUE) < -UPWARD_ROC_LIMITER) {
potval = UPWARD_ROC_PREV_VALUE - UPWARD_ROC_LIMITER;
}
UPWARD_ROC_PREV_VALUE = potval;
return potval;
}
//reads potentiometer on pin A0 and scales by scale_factor //reads potentiometer on pin A0 and scales by scale_factor
//NOTE: scale factor should only be 0-255! //NOTE: scale factor should only be 0-255!
// TODO: make sure this code is not run too often it will take time // TODO: make sure this code is not run too often it will take time
...@@ -64,12 +78,7 @@ int get_pot_0_scaled(int scaleFactor, float period_over_255) ...@@ -64,12 +78,7 @@ int get_pot_0_scaled(int scaleFactor, float period_over_255)
volatile float raw_potval = analogRead(A0); volatile float raw_potval = analogRead(A0);
float potval = raw_potval; float potval = raw_potval;
if ((potval - UPWARD_ROC_PREV_VALUE) > UPWARD_ROC_LIMITER) { potval = ROC_limiter(potval);
potval = UPWARD_ROC_PREV_VALUE + UPWARD_ROC_LIMITER;
}
else if ((potval - UPWARD_ROC_PREV_VALUE) < UPWARD_ROC_LIMITER) {
potval = UPWARD_ROC_PREV_VALUE - UPWARD_ROC_LIMITER;
}
//This code creates a limit on the amount of power durring calibration //This code creates a limit on the amount of power durring calibration
if (!is_calibration_complete()){ if (!is_calibration_complete()){
...@@ -78,7 +87,7 @@ int get_pot_0_scaled(int scaleFactor, float period_over_255) ...@@ -78,7 +87,7 @@ int get_pot_0_scaled(int scaleFactor, float period_over_255)
} }
} }
UPWARD_ROC_PREV_VALUE = potval;
potval = potval/1024; potval = potval/1024;
potval = potval * scaleFactor; potval = potval * scaleFactor;
...@@ -128,7 +137,7 @@ void do_hard_coded_offset(void) ...@@ -128,7 +137,7 @@ void do_hard_coded_offset(void)
//now lets grab the position //now lets grab the position
my_position = get_raw_wheel_position_ticks() - get_Zoffset(); my_position = get_raw_wheel_position_ticks() - get_Zoffset();
//turn it off! //turn it off!
turn_all_off(); turn_all_mosfets_off();
//print it out wayyyy too much It is supposed to get stuck here //print it out wayyyy too much It is supposed to get stuck here
Serial.println("Get Hard coded offset got a BC position of:"); Serial.println("Get Hard coded offset got a BC position of:");
Serial.println(my_position); Serial.println(my_position);
...@@ -157,7 +166,7 @@ void locate_state_positions(void) ...@@ -157,7 +166,7 @@ void locate_state_positions(void)
Serial.printf("%d:%d\n", p, get_wheel_position_ticks()); Serial.printf("%d:%d\n", p, get_wheel_position_ticks());
} }
} }
turn_all_off(); turn_all_mosfets_off();
while(1) while(1)
{ {
} }
...@@ -168,9 +177,9 @@ void debug_low_state_by_state(void) ...@@ -168,9 +177,9 @@ void debug_low_state_by_state(void)
while(1){ while(1){
Serial.println("lets run some debug tests"); Serial.println("lets run some debug tests");
Serial.println("Hit space to call turn_all_off()"); Serial.println("Hit space to call turn_all_mosfets_off()");
block_until_spacebar(); block_until_spacebar();
turn_all_off(); turn_all_mosfets_off();
Serial.println("Hit space to call setphase(0,0,0,0,0,0)"); Serial.println("Hit space to call setphase(0,0,0,0,0,0)");
block_until_spacebar(); block_until_spacebar();
set_phase(0,0,0,0,0,0); set_phase(0,0,0,0,0,0);
......
...@@ -11,6 +11,8 @@ void locate_state_positions(void); ...@@ -11,6 +11,8 @@ void locate_state_positions(void);
void direct_position_control(void); void direct_position_control(void);
void debug_low_state_by_state(void); void debug_low_state_by_state(void);
int debug_pot_0_scaled(void); int debug_pot_0_scaled(void);
int ROC_limiter(int potval);
void set_calibration_complete(void);
......
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