Commit 0a98c606 authored by mattdr's avatar mattdr
Browse files

added limiter to pwm durring calibration

parent 33850668
...@@ -14,6 +14,8 @@ int encoder_ticks_in_elec_rotation = 682; // floor(8193 / 12)=682 ...@@ -14,6 +14,8 @@ int encoder_ticks_in_elec_rotation = 682; // floor(8193 / 12)=682
// has the motor been calibrated // has the motor been calibrated
bool calibrated = false; bool calibrated = false;
bool calibration_complete = false; // similar to the bool above but not used inside any interupts
// define the offset from zero using interrupt and the z signal // define the offset from zero using interrupt and the z signal
// This offset is different each time it starts up and must be calibrated // This offset is different each time it starts up and must be calibrated
int Zoffset = 0; int Zoffset = 0;
...@@ -21,7 +23,7 @@ int Zoffset = 0; ...@@ -21,7 +23,7 @@ int Zoffset = 0;
// This is the difference in encoder tics from the Z index to // This is the difference in encoder tics from the Z index to
// the electrical encoder zero (which is found by powering the // the electrical encoder zero (which is found by powering the
// AB block and waiting for the motor to settle) // AB block and waiting for the motor to settle)
int hard_coded_offset = 387; int hard_coded_offset = -615;
//Invert position to invert position add 341 to any offset //Invert position to invert position add 341 to any offset
...@@ -265,6 +267,9 @@ int calibrate_encoder() ...@@ -265,6 +267,9 @@ int calibrate_encoder()
if(getDebugOn()) { if(getDebugOn()) {
Serial.println("CALIBRATION SUCCESSFULL"); Serial.println("CALIBRATION SUCCESSFULL");
} }
cli();
calibration_complete = true;
sei();
return 1; return 1;
} }
} }
...@@ -274,6 +279,11 @@ int calibrate_encoder() ...@@ -274,6 +279,11 @@ int calibrate_encoder()
return -1; return -1;
} }
bool is_calibration_complete()
{
return calibration_complete;
}
//This will provide debug prints with info that could be usefull //This will provide debug prints with info that could be usefull
void debug_encoder(void) void debug_encoder(void)
{ {
......
...@@ -12,6 +12,8 @@ int get_raw_wheel_position_ticks(void); ...@@ -12,6 +12,8 @@ int get_raw_wheel_position_ticks(void);
int get_elec_rev_position_ticks(int mechanical_position); int get_elec_rev_position_ticks(int mechanical_position);
int get_phase_number(int elec_position); int get_phase_number(int elec_position);
int get_Zoffset(void); int get_Zoffset(void);
bool is_calibration_complete();
......
...@@ -3,7 +3,9 @@ ...@@ -3,7 +3,9 @@
#include "motor_ctrl.h" #include "motor_ctrl.h"
#include "encoder.h" #include "encoder.h"
const float UPWARD_ROC_LIMITER = 0.005; float CALIBRATION_MAX_PWM = 53.0;
const float UPWARD_ROC_LIMITER = 20.0;
float UPWARD_ROC_PREV_VALUE = 0; float UPWARD_ROC_PREV_VALUE = 0;
#define debugJumperOut 11 #define debugJumperOut 11
...@@ -62,12 +64,12 @@ int get_pot_0_scaled(int scaleFactor, float period_over_255) ...@@ -62,12 +64,12 @@ 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) { if ((potval - UPWARD_ROC_PREV_VALUE) > UPWARD_ROC_LIMITER) {
// 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) { else if ((potval - UPWARD_ROC_PREV_VALUE) < UPWARD_ROC_LIMITER) {
// potval = UPWARD_ROC_PREV_VALUE - UPWARD_ROC_LIMITER; potval = UPWARD_ROC_PREV_VALUE - UPWARD_ROC_LIMITER;
// } }
UPWARD_ROC_PREV_VALUE = potval; UPWARD_ROC_PREV_VALUE = potval;
...@@ -82,6 +84,13 @@ int get_pot_0_scaled(int scaleFactor, float period_over_255) ...@@ -82,6 +84,13 @@ int get_pot_0_scaled(int scaleFactor, float period_over_255)
return (int)0; return (int)0;
} }
//This code creates a limit on the amount of power durring calibration
if (!is_calibration_complete()){
if (potval > CALIBRATION_MAX_PWM){
return CALIBRATION_MAX_PWM;
}
}
return (int)potval; return (int)potval;
} }
......
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