Commit 1cdc7e6b authored by skwirskj's avatar skwirskj
Browse files

Added .gitignore and changes to files

Made a helper function for the ROC limiter, and cleaned up some code.
parent d8113077
*.DS_Store
*.checksum
*.code-workspace
......@@ -258,11 +258,11 @@ int calibrate_encoder()
set_block_phase(p);
delayMicroseconds(CALIBRATION_DELAY);
}
turn_all_off();
turn_all_mosfets_off();
if(calibrated == true){
//ditch the interrupt
turn_all_off();
turn_all_mosfets_off();
detachInterrupt(digitalPinToInterrupt(Z));
if(getDebugOn()) {
......@@ -275,7 +275,7 @@ int calibrate_encoder()
}
}
turn_all_off();
turn_all_mosfets_off();
Serial.println("CALIBRATION FAILED");
return -1;
}
......
......@@ -48,57 +48,98 @@ H TO TO SEND SPECIFIC PHASES DEBUG MOTOR\n");
if (Serial.available()) {
incomingByte = Serial.read();
}
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();
switch(incomingByte) {
case ' ':
break;
case 'z':
charge_bootstrap_capacitors();
do_hard_coded_offset();// run the set zero
break;
case 'o':
charge_bootstrap_capacitors();
open_loop_control();
break;
case 'l':
charge_bootstrap_capacitors();
locate_state_positions();
break;
case 'd':
charge_bootstrap_capacitors();
direct_position_control();
break;
case 'b':
charge_bootstrap_capacitors();
motor_butt_control_inefficient();
break;
case 's':
charge_bootstrap_capacitors();
motor_butt_control_precalculated();
break;
case 'y':
debug_low_state_by_state();
break;
case 'u':
debug_pot_0_scaled();
break;
case 'k':
debug_encoder();
break;
case 'h':
debug_motor();
break;
}
// 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();
......
......@@ -46,7 +46,7 @@ int POT_0_VALUE = 0;
void pot_0_speed_ISR();
void turn_all_off();
void turn_all_mosfets_off();
int one_to_scaleFactor(int x);
void set_phase(int high1, int high2, int high3, int low1, int low2, int low3);
void set_block_phase(int phase);
......@@ -79,7 +79,7 @@ void motor_setup(void) {
analogWriteFrequency(L2, FREQ);
analogWriteFrequency(L3, FREQ);
turn_all_off();
turn_all_mosfets_off();
//setup the halfbridges enables
// pinMode(HB1EN, OUTPUT);
......@@ -117,7 +117,7 @@ void pot_0_speed_ISR() {
// }
}
void turn_all_off() {
void turn_all_mosfets_off() {
analogWrite(L1, 0);
analogWrite(L2, 0);
analogWrite(L3, 0);
......@@ -176,7 +176,7 @@ void set_block_phase(int phase)
set_phase(0,0,1,0,1,0); //Phase CB
break;
default :
turn_all_off();
turn_all_mosfets_off();
//no break needed
}
return;
......@@ -261,25 +261,30 @@ void set_phase_float(float f1, float f2, float f3)
int f2i = (int) f2;
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) )
{
// 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);
f1_is_transient = true;
}
else if ( (last_f1i != 0) && (f1i == 0) ){
//f1 used to have high side running now has low side on
// turn off the high side first then do f1s low side
analogWrite(H1, 0);
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) )
......@@ -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
analogWrite(L2, 0);
analogWrite(H2, f2i);
f2_is_transient = true;
}
else if ( (last_f2i != 0) && (f2i == 0) ){
//f2 used to have high side running now has low side on
// turn off the high side first then do f2s low side
analogWrite(H2, 0);
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) )
{
......@@ -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
analogWrite(L3, 0);
analogWrite(H3, f3i);
f3_is_transient = true;
}
else if ( (last_f3i != 0) && (f3i == 0) ){
//f3 used to have high side running now has low side on
// turn off the high side first then do f3s low side
analogWrite(H3, 0);
analogWrite(L3, 255);
f3_is_transient = true;
}
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){
else {
if(f3i == 0){
analogWrite(L3, 255);
}
......@@ -349,8 +336,6 @@ void set_phase_float(float f1, float f2, float f3)
last_f1i = f1i;
last_f2i = f2i;
last_f3i = f3i;
}
void motor_butt_control_inefficient(void)
......@@ -435,11 +420,11 @@ void open_loop_control(void)
// this should allways be called right before powering the motor
void charge_bootstrap_capacitors(void)
{
turn_all_off();
turn_all_mosfets_off();
delayMicroseconds(50);
set_phase(0,0,0,1,1,1);
delayMicroseconds(50);
turn_all_off();
turn_all_mosfets_off();
}
//using hardcoded located state positions
......@@ -565,7 +550,7 @@ void debug_motor(void) {
set_phase(0,0,1,0,1,0);
delay(10);
}
turn_all_off();
turn_all_mosfets_off();
Serial.println("DONE WITH AROUND THE WORLD");
case 1:
......@@ -599,7 +584,7 @@ void debug_motor(void) {
break;
case -16:
turn_all_off();
turn_all_mosfets_off();
Serial.println("STOP THE PRESSES!!!");
break;
......
......@@ -2,7 +2,7 @@
#define MOTOR_CTRL_H_
void motor_setup(void);
void turn_all_off();
void turn_all_mosfets_off();
void set_block_phase(int phase);
void debug_motor(void);
void open_loop_control(void);
......
......@@ -56,6 +56,20 @@ int get_pot_1_inv(void)
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
//NOTE: scale factor should only be 0-255!
// 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)
volatile float raw_potval = analogRead(A0);
float potval = raw_potval;
if ((potval - UPWARD_ROC_PREV_VALUE) > UPWARD_ROC_LIMITER) {
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;
}
potval = ROC_limiter(potval);
//This code creates a limit on the amount of power durring calibration
if (!is_calibration_complete()){
......@@ -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 * scaleFactor;
......@@ -128,7 +137,7 @@ void do_hard_coded_offset(void)
//now lets grab the position
my_position = get_raw_wheel_position_ticks() - get_Zoffset();
//turn it off!
turn_all_off();
turn_all_mosfets_off();
//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(my_position);
......@@ -157,7 +166,7 @@ void locate_state_positions(void)
Serial.printf("%d:%d\n", p, get_wheel_position_ticks());
}
}
turn_all_off();
turn_all_mosfets_off();
while(1)
{
}
......@@ -168,9 +177,9 @@ void debug_low_state_by_state(void)
while(1){
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();
turn_all_off();
turn_all_mosfets_off();
Serial.println("Hit space to call setphase(0,0,0,0,0,0)");
block_until_spacebar();
set_phase(0,0,0,0,0,0);
......
......@@ -11,6 +11,8 @@ void locate_state_positions(void);
void direct_position_control(void);
void debug_low_state_by_state(void);
int debug_pot_0_scaled(void);
int ROC_limiter(int potval);
void set_calibration_complete(void);
......
Supports Markdown
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