Commit 74412b09 authored by mattdr's avatar mattdr
Browse files

code cleanup, removed auto calibration

parent a064c813
{
"terminal.integrated.env.windows": {
"PATH": "C:\\Users\\zatar\\.platformio\\penv\\Scripts;C:\\Users\\zatar\\.platformio\\penv;C:\\ProgramData\\Anaconda3;C:\\ProgramData\\Anaconda3\\Library\\mingw-w64\\bin;C:\\ProgramData\\Anaconda3\\Library\\usr\\bin;C:\\ProgramData\\Anaconda3\\Library\\bin;C:\\ProgramData\\Anaconda3\\Scripts;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Users\\zatar\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\zatar\\AppData\\Local\\GitHubDesktop\\bin;C:\\Users\\zatar\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\zatar\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;c:\\Cygwin64\\bin;;C:\\ProgramData\\Anaconda3;C:\\ProgramData\\Anaconda3\\Library\\mingw-w64\\bin;C:\\ProgramData\\Anaconda3\\Library\\usr\\bin;C:\\ProgramData\\Anaconda3\\Library\\bin;C:\\ProgramData\\Anaconda3\\Scripts;C:\\Program Files (x86)\\Common Files\\Oracle\\Java\\javapath;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;C:\\Program Files\\MiKTeX 2.9\\miktex\\bin\\x64\\;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Users\\zatar\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\zatar\\AppData\\Local\\GitHubDesktop\\bin;C:\\Users\\zatar\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Users\\zatar\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;c:\\Cygwin64\\bin;",
"PATH": "C:\\Users\\Matt\\.platformio\\penv\\Scripts;C:\\Users\\Matt\\.platformio\\penv;C:\\Program Files\\Dell\\DW WLAN Card;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;c:\\Program Files\\WIDCOMM\\Bluetooth Software\\;c:\\Program Files\\WIDCOMM\\Bluetooth Software\\syswow64;C:\\WINDOWS\\system32\\config\\systemprofile\\.dnx\\bin;C:\\Program Files\\Microsoft DNX\\Dnvm\\;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\PuTTY\\;C:\\Program Files (x86)\\Xoreax\\IncrediBuild;C:\\Program Files\\MATLAB\\R2017b\\runtime\\win64;C:\\Program Files\\MATLAB\\R2017b\\bin;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\Git\\mingw64\\bin;C:\\Program Files\\Git\\usr\\bin;C:\\Program Files (x86)\\Microsoft VS Code\\bin;C:\\Users\\Matt\\Anaconda3;C:\\Users\\Matt\\Anaconda3\\Library\\mingw-w64\\bin;C:\\Users\\Matt\\Anaconda3\\Library\\usr\\bin;C:\\Users\\Matt\\Anaconda3\\Library\\bin;C:\\Users\\Matt\\Anaconda3\\Scripts;C:\\Users\\Matt\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Program Files (x86)\\Microsoft VS Code\\bin;C:\\Users\\Matt\\AppData\\Local\\Programs\\Microsoft VS Code\\bin;C:\\Program Files\\Dell\\DW WLAN Card;C:\\WINDOWS\\system32;C:\\WINDOWS;C:\\WINDOWS\\System32\\Wbem;C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\;c:\\Program Files\\WIDCOMM\\Bluetooth Software\\;c:\\Program Files\\WIDCOMM\\Bluetooth Software\\syswow64;C:\\WINDOWS\\system32\\config\\systemprofile\\.dnx\\bin;C:\\Program Files\\Microsoft DNX\\Dnvm\\;C:\\Program Files (x86)\\Windows Kits\\8.1\\Windows Performance Toolkit\\;C:\\Program Files\\Microsoft SQL Server\\130\\Tools\\Binn\\;C:\\Program Files\\PuTTY\\;C:\\Program Files (x86)\\Xoreax\\IncrediBuild;C:\\Program Files\\MATLAB\\R2017b\\runtime\\win64;C:\\Program Files\\MATLAB\\R2017b\\bin;C:\\WINDOWS\\System32\\OpenSSH\\;C:\\Program Files\\Git\\cmd;C:\\Program Files\\Git\\mingw64\\bin;C:\\Program Files\\Git\\usr\\bin;C:\\Program Files (x86)\\Microsoft VS Code\\bin;C:\\Users\\Matt\\Anaconda3;C:\\Users\\Matt\\Anaconda3\\Library\\mingw-w64\\bin;C:\\Users\\Matt\\Anaconda3\\Library\\usr\\bin;C:\\Users\\Matt\\Anaconda3\\Library\\bin;C:\\Users\\Matt\\Anaconda3\\Scripts;C:\\Users\\Matt\\AppData\\Local\\Microsoft\\WindowsApps;C:\\Program Files (x86)\\Microsoft VS Code\\bin;C:\\Users\\Matt\\AppData\\Local\\Programs\\Microsoft VS Code\\bin",
"PLATFORMIO_CALLER": "vscode"
}
}
\ No newline at end of file
......@@ -66,7 +66,7 @@ void encoder_setup(void)
//xPosn.zeroFTM(); //This zeros the counter
//setup the speed timer to run ever 1 sec
speed_timer.begin(print_speed_ISR, 100000);
speed_timer.begin(print_speed_ISR, 1000000);
delay(5000); //sit tight for a bit
}
......@@ -189,12 +189,13 @@ int calibrate_encoder(void)
//worst case needs 6 full electrical rotations
Serial.println("STARTING CALIBRATION");
while(1){
for(int p = 1; p <= 6; p++)
{
set_block_phase(p);
int myDelay = 28500;
delayMicroseconds(myDelay);
}
// for(int p = 1; p <= 6; p++)
// {
// set_block_phase(p);
// int myDelay = 28500;
// delayMicroseconds(myDelay);
// }
turn_all_off();
if(calibrated == true){
//ditch the interrupt
......
......@@ -23,30 +23,45 @@ L TO LOCATE STATE POSITIONS\n\
D TO START DIRECT POSITION CONTROL\n\
B TO START BUTT CONTROL (NON-OPTIMIZED)\n\
S TO START BUTT CONTROL (OPTIMIZED)\n");
int choice = get_input(prompt);
if(choice == 2){
do_hard_coded_offset();// run the set zero
}
if(choice == 3)
{
open_loop_control();
}
if(choice == 4)
{
locate_state_positions();
}
if(choice == 5)
{
direct_position_control();
}
if(choice == 6)
{
motor_butt_control_inefficient();
}
if(choice == 7)
short incomingByte = 0;
while(1)
{
motor_butt_control_precalculated();
Serial.println(prompt);
delay(200); // do not go too fast!
if (Serial.available()) {
incomingByte = Serial.read();
}
if(incomingByte == ' ')//space bar
{
break;
}
else if(incomingByte == 'z') //'z'
{
do_hard_coded_offset();// run the set zero
}
else if(incomingByte == 'o') //'o'
{
open_loop_control();
}
else if(incomingByte == 'l') //'l'
{
locate_state_positions();
}
else if (incomingByte == 'd') //'d'
{
direct_position_control();
}
else if (incomingByte == 'b') //'b'
{
motor_butt_control_inefficient();
}
else if (incomingByte == 's') //'s'
{
motor_butt_control_precalculated();
}
}
int calibration_return = calibrate_encoder();
if(calibration_return == -1)
{
......
......@@ -16,8 +16,11 @@
const int led = LED_BUILTIN;
//This scale factor scales the potentiometer
int const SCALE_FACTOR = 20;
void turn_all_off();
int one_to_255(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_block_phase(int phase);
void motor_butt_control_inefficient(void);
......@@ -57,14 +60,13 @@ void turn_all_off() {
digitalWrite(L3, LOW);
}
int one_to_255(int x)
int one_to_scaleFactor(int x)
{
if (x == 1)
{
float potval = analogRead(A0);
potval = potval/1024;
potval = potval * 20;
return (int)potval; //read from pot
// NOTE: The scale factor of is the max value we want out of
// the potentiometer
return get_pot_0_scaled(SCALE_FACTOR);
}
else{
return 0;
......@@ -109,11 +111,12 @@ void set_block_phase(int phase)
return;
}
// This function takes in a seris of
void set_phase(int high1, int high2, int high3, int low1, int low2, int low3)
{
high1 = one_to_255(high1);
high2 = one_to_255(high2);
high3 = one_to_255(high3);
high1 = one_to_scaleFactor(high1);
high2 = one_to_scaleFactor(high2);
high3 = one_to_scaleFactor(high3);
digitalWrite(L1, low1);
digitalWrite(L2, low2);
......@@ -126,9 +129,9 @@ void set_phase(int high1, int high2, int high3, int low1, int low2, int low3)
void set_phase_float(float f1, float f2, float f3)
{
//deal with the potentiometer first
float potval = analogRead(A0);
potval = potval/1024;
potval = potval * 20;
// NOTE: The scale factor of is the max value we want out of
// the potentiometer
int potval = get_pot_0_scaled(SCALE_FACTOR);
f1 = (f1 * potval);
f2 = (f2 * potval);
......@@ -212,16 +215,16 @@ void open_loop_control(void)
{
set_block_phase(p);
//What's going on with this math, explination:
// The get_speed will return an int 0-100
// The get_pot_1_inv will return an int 0-100
// We want the minimum speed to be 1 sec per phase
// we want the maximum speed to be 2800 us per phase
// the max speed corresponds to 5 rev/sec
// we know we need to go faster but this is just testing
volatile int myDelay = 1500 + (get_speed() * 300);
volatile int myDelay = 1500 + (get_pot_1_inv() * 300);
// Serial.println("my delay:");
// Serial.println(myDelay);
// Serial.println("my speed:");
// Serial.println(get_speed());
// Serial.println(get_pot_1_inv());
delayMicroseconds(myDelay);
}
}
......
......@@ -22,7 +22,8 @@ void block_until_spacebar(void)
}
//reads potentiometer on pin A1 and scales it 0-100
int get_speed(void)
//The value is inverted so the value is 100-0
int get_pot_1_inv(void)
{
volatile float potval = analogRead(A1);
potval = potval/1024;
......@@ -31,50 +32,18 @@ int get_speed(void)
return (int)potval; //read from pot
}
// returns 1 if user sends space bar
// returns 2 if user sends 'z'
int get_input(char * prompt)
//reads potentiometer on pin A0 and scales by scale_factor
//NOTE: scale factor should only be 0-255!
int get_pot_0_scaled(int scaleFactor)
{
short incomingByte = 0;
while(1)
{
Serial.println(prompt);
delay(200); // do not go too fast!
if (Serial.available()) {
incomingByte = Serial.read();
}
if(incomingByte == 32)//space bar
{
return 1;
}
else if(incomingByte == 122) //'z'
{
return 2;
}
else if(incomingByte == 111) //'o'
{
return 3;
}
else if(incomingByte == 108) //'l'
{
return 4;
}
else if (incomingByte == 100) //'d'
{
return 5;
}
else if (incomingByte == 'b') //'b'
{
return 6;
}
else if (incomingByte == 's') //'b'
{
return 7;
}
}
volatile float potval = analogRead(A0);
potval = potval/1024;
potval = potval * scaleFactor;
return (int)potval;
}
// This function just rotates the motor to position CB, waits until
// everything stops moving, takes a read of what the encoder has
// prints it to the command line and then turns everything off
......
......@@ -2,9 +2,9 @@
#define UTILS_H_
void block_until_spacebar(void);
int get_input(char * prompt);
void do_hard_coded_offset(void);
int get_speed(void);
int get_pot_1_inv(void);
int get_pot_0_scaled(int scaleFactor);
void locate_state_positions(void);
void direct_position_control(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