Commit 11f1f1bf authored by zataraclark's avatar zataraclark
Browse files

Changed do_hard_coded_offset to run through each phase before holding at phase 6

parents 7f4e2306 6e3996c3
*.DS_Store
*.checksum
*.code-workspace
......@@ -14,6 +14,7 @@ int get_phase_number(int elec_position);
int get_Zoffset(void);
bool is_calibration_complete();
void set_calibration_comlete(void);
void set_calibration_complete();
......
......@@ -48,59 +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();
......
......@@ -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)
......@@ -538,7 +523,7 @@ void debug_motor(void) {
int i = 0;
// put your main code here, to run repeatedly:
Serial.println("I am alive!");
short incomingByte;
short incomingByte = -1;
delay(50); // do not print too fast!
if (Serial.available()) {
incomingByte = Serial.read(); // will not be -1
......
......@@ -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;
......
......@@ -11,6 +11,10 @@ void locate_state_positions(void);
void direct_position_control(void);
void debug_low_state_by_state(void);
int debug_pot_0_scaled(void);
<<<<<<< HEAD
=======
int ROC_limiter(int potval);
>>>>>>> 6e3996c33ae3a7925a12b8e9282cd01a004ef3b3
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