Commit 33850668 authored by mattdr's avatar mattdr
Browse files

added the main back in

parent 058d5751
{
"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:\\Program Files\\PuTTY\\;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:\\Program Files\\PuTTY\\;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
#include <Arduino.h>
#include "motor_ctrl.h"
#include "encoder.h"
#include "utils.h"
//BE AWARE COGGING POINTS MAY BE INBETWEEN STATES
//(THIS OFFSET MAY IMPACT THE HARD CODED POSITION)
void setup()
{
// Pin Jumper to decide whether we print our options or skip straight to
// Precalculated Butt Control
checkDebugJumper();
motor_setup();
encoder_setup();
//deal with serial (might want this faster)
Serial.begin(9600);//Serial.begin(2000000); //FASTER!
// Hit space bar to start calibration
// Hit 'z' to run get hard coded offset
char prompt[] = ("\
SPACE TO START CALIBRATION AND NORMAL OPERATIONS, \n\
Z TO GET HARDCODED OFFSET \n\
O TO START OPEN LOOP CONTROL\n\
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\n\
Y TO DEBUG LOW STATE BY STATE\n\
U TO DEBUG_POT_0_SCALED\n\
K TO DEBUG ENCODER\n\
H TO TO SEND SPECIFIC PHASES DEBUG MOTOR\n");
short incomingByte = 0;
while(1)
{
if(!getDebugOn()) {
charge_bootstrap_capacitors();
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'
{
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();
int calibration_return = calibrate_encoder();
if(calibration_return == -1)
{
while(1){//error out
delay(900);
Serial.println("CALIBRATION FAILED, REBOOT");
}
}
Serial.println("CALIBRATION COMPLETE");
return;
}
void loop()
{
//hold on to the old phase number
static int last_phase = 0;
// get the current encoder tics (this does the math to offset)
int position = get_wheel_position_ticks();
// get position within current electrical revolution
int ele_position = get_elec_rev_position_ticks(position);
// get the phase number that corresponds to this ele position
int phase = get_phase_number(ele_position);
phase = (phase % 6) + 1;
//if we have a new phase, set the new phase
set_block_phase(phase);
}
\ No newline at end of file
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