Bayley Wang
/
flash_configuration
flash based config testing
Revision 1:df6bbacb7bb9, committed 2017-03-02
- Comitter:
- bwang
- Date:
- Thu Mar 02 07:04:47 2017 +0000
- Parent:
- 0:941e150e78b6
- Child:
- 2:cfc39b0843ae
- Commit message:
- now with configuration terminal!
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CommandProcessor/CommandProcessor.cpp Thu Mar 02 07:04:47 2017 +0000 @@ -0,0 +1,207 @@ +#include "mbed.h" +#include "CommandProcessor.h" +#include "PreferenceWriter.h" + +#include "config.h" +#include "config_driving.h" +#include "config_inverter.h" +#include "config_logging.h" +#include "config_loop.h" +#include "config_motor.h" +#include "config_pins.h" +#include "config_table.h" + +void cmd_ls(Serial *pc) { + DPRINT(TORQUE_MODE); + FPRINT(MAX_TQPCT_PLUS); + FPRINT(MAX_TQPCT_MINUS); + FPRINT(TORQUE_MAX); + FPRINT(W_MAX); + FPRINT(BUS_VOLTAGE); + FPRINT(F_SW); + FPRINT(K_LOOP_D); + FPRINT(KI_BASE_D); + FPRINT(K_LOOP_Q); + FPRINT(KI_BASE_Q); + FPRINT(F_SLOW_LOOP); + FPRINT(INTEGRAL_MAX); + FPRINT(W_FILTER_STRENGTH); + FPRINT(DQ_FILTER_STRENGTH); + FPRINT(THROTTLE_FILTER_STRENGTH); + FPRINT(KP_D); + FPRINT(KI_D); + FPRINT(KP_Q); + FPRINT(KI_Q); + FPRINT(SLOW_LOOP_COUNTER); + FPRINT(POLE_PAIRS); + FPRINT(POS_OFFSET); + FPRINT(RESOLVER_LOBES); + DPRINT(CPR); + FPRINT(Ld); + FPRINT(Lq); + FPRINT(FLUX_LINKAGE); + FPRINT(Rs); + FPRINT(KT); + FPRINT(W_SAFE); + FPRINT(W_CRAZY); + DPRINT(TH_LIMIT_LOW); + DPRINT(TH_LIMIT_HIGH); + DPRINT(TH_LIMIT_CRAZY); + DPRINT(ROWS); + DPRINT(COLUMNS); + FPRINT(W_STEP); +} + +void cmd_ls2(Serial *pc, char *buf) { + float *fptr = checkf(buf); + if (fptr != NULL) pc->printf("%s: %f\n", buf, *fptr); + int *nptr = NULL; + if (fptr == NULL) nptr = checkn(buf); + if (nptr != NULL) pc->printf("%s: %d\n", buf, *nptr); + if (nptr == NULL && fptr == NULL) pc->printf("%s\n", "No Such Parameter"); +} + +void cmd_defaults(Serial *pc) { + DEFAULT(TORQUE_MODE); + DEFAULT(MAX_TQPCT_PLUS); + DEFAULT(MAX_TQPCT_MINUS); + DEFAULT(TORQUE_MAX); + DEFAULT(W_MAX); + DEFAULT(BUS_VOLTAGE); + DEFAULT(F_SW); + DEFAULT(K_LOOP_D); + DEFAULT(KI_BASE_D); + DEFAULT(K_LOOP_Q); + DEFAULT(KI_BASE_Q); + DEFAULT(F_SLOW_LOOP); + DEFAULT(INTEGRAL_MAX); + DEFAULT(W_FILTER_STRENGTH); + DEFAULT(DQ_FILTER_STRENGTH); + DEFAULT(THROTTLE_FILTER_STRENGTH); + DEFAULT(KP_D); + DEFAULT(KI_D); + DEFAULT(KP_Q); + DEFAULT(KI_Q); + DEFAULT(SLOW_LOOP_COUNTER); + DEFAULT(POLE_PAIRS); + DEFAULT(POS_OFFSET); + DEFAULT(RESOLVER_LOBES); + DEFAULT(CPR); + DEFAULT(Ld); + DEFAULT(Lq); + DEFAULT(FLUX_LINKAGE); + DEFAULT(Rs); + DEFAULT(KT); + DEFAULT(W_SAFE); + DEFAULT(W_CRAZY); + DEFAULT(TH_LIMIT_LOW); + DEFAULT(TH_LIMIT_HIGH); + DEFAULT(TH_LIMIT_CRAZY); + DEFAULT(ROWS); + DEFAULT(COLUMNS); + DEFAULT(W_STEP); + pc->printf("Defaults Loaded\n"); +} + +void cmd_reload(Serial *pc, PreferenceWriter *pref) { + pref->load(); + pc->printf("Flash Values Loaded\n"); +} + +void cmd_set(Serial *pc, char *buf, char *val) { + float *fptr = checkf(buf); + if (fptr != NULL) *fptr = (float) (atof(val)); + int *nptr = NULL; + if (fptr == NULL) nptr = checkn(buf); + if (nptr != NULL) *nptr = (int) (atoi(val)); + cmd_ls2(pc, buf); + if (nptr == NULL && fptr == NULL) pc->printf("%s\n", "No Such Parameter"); +} + +void cmd_flush(Serial *pc, PreferenceWriter *pref) { + if (!pref->ready()) pref->open(); + pref->flush(); +} + +void processCmd(Serial *pc, PreferenceWriter *pref, char *buf) { + char *tokens[10]; + int len = tokenize(buf, tokens, 10); + + switch (len) { + case 1: + if (strcmp(tokens[0], "ls") == 0) cmd_ls(pc); + if (strcmp(tokens[0], "defaults") == 0) cmd_defaults(pc); + if (strcmp(tokens[0], "reload") == 0) cmd_reload(pc, pref); + if (strcmp(tokens[0], "load") == 0) cmd_reload(pc, pref); + if (strcmp(tokens[0], "flush") == 0) cmd_flush(pc, pref); + break; + case 2: + if (strcmp(tokens[0], "ls") == 0) cmd_ls2(pc, tokens[1]); + if (strcmp(tokens[0], "get") == 0) cmd_ls2(pc, tokens[1]); + break; + case 3: + if (strcmp(tokens[0], "set") == 0) cmd_set(pc, tokens[1], tokens[2]); + default: + break; + } +} + +int tokenize(char *buf, char **out, int max) { + char* tok; + int k = 0; + + tok = strtok(buf, " "); + + while(tok != NULL && k < max) { + out[k] = tok; + k++; + tok = strtok(NULL, " "); + } + return k; +} + +#define __check(x) if(strcmp(s, #x) == 0) return &_##x +float* checkf(char *s) { + __check(MAX_TQPCT_PLUS); + __check(MAX_TQPCT_MINUS); + __check(TORQUE_MAX); + __check(W_MAX); + __check(BUS_VOLTAGE); + __check(F_SW); + __check(K_LOOP_D); + __check(KI_BASE_D); + __check(K_LOOP_Q); + __check(KI_BASE_Q); + __check(F_SLOW_LOOP); + __check(INTEGRAL_MAX); + __check(W_FILTER_STRENGTH); + __check(DQ_FILTER_STRENGTH); + __check(THROTTLE_FILTER_STRENGTH); + __check(KP_D); + __check(KI_D); + __check(KP_Q); + __check(KI_Q); + __check(POLE_PAIRS); + __check(POS_OFFSET); + __check(RESOLVER_LOBES); + __check(Ld); + __check(Lq); + __check(FLUX_LINKAGE); + __check(Rs); + __check(KT); + __check(W_SAFE); + __check(W_CRAZY); + __check(W_STEP); + return NULL; +} + +int* checkn(char *s) { + __check(TORQUE_MODE); + __check(CPR); + __check(TH_LIMIT_LOW); + __check(TH_LIMIT_HIGH); + __check(TH_LIMIT_CRAZY); + __check(ROWS); + __check(COLUMNS); + return NULL; +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/CommandProcessor/CommandProcessor.h Thu Mar 02 07:04:47 2017 +0000 @@ -0,0 +1,19 @@ +#ifndef __COMMAND_PROCESSOR_H +#define __COMMAND_PROCESSOR_H + +#include "mbed.h" +#include "PreferenceWriter.h" + +float *checkf(char *s); +int *checkn(char *s); + +void processCmd(Serial *pc, PreferenceWriter *pref, char *buf); +void cmd_ls(Serial *pc); +void cmd_ls2(Serial *pc, char *buf); +void cmd_defaults(Serial *pc); +void cmd_reload(Serial *pc, PreferenceWriter *pref); +void cmd_flush(Serial *pc, PreferenceWriter *pref); + +int tokenize(char *buf, char **out, int max); + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Defaults/config_driving.h Thu Mar 02 07:04:47 2017 +0000 @@ -0,0 +1,18 @@ +#ifndef __CONFIG_DRIVING +#define __CONFIG_DRIVING + +#define TORQUE_MODE true + +/*forward torque scaling*/ +#define MAX_TQPCT_PLUS 1.0f + +/*reverse/regen torque scaling*/ +#define MAX_TQPCT_MINUS 0.3f + +/*maximum torque for approximate methods*/ +#define TORQUE_MAX 75.0f + +/*max speed, including any field weakening, rad/s*/ +#define W_MAX 1000.0f + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Defaults/config_inverter.h Thu Mar 02 07:04:47 2017 +0000 @@ -0,0 +1,10 @@ +#ifndef __CONFIG_INVERTER_H +#define __CONFIG_INVERTER_H + +/*DC link voltage, volts*/ +#define BUS_VOLTAGE 160.0f + +/*switching frequency, hertz*/ +#define F_SW 5000.0f + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Defaults/config_logging.h Thu Mar 02 07:04:47 2017 +0000 @@ -0,0 +1,7 @@ +#ifndef __CONFIG_LOGGING +#define __CONFIG_LOGGING + +#define ENABLE_LOGGING true +#define LOG_FREQUENCY 100.f + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Defaults/config_loop.h Thu Mar 02 07:04:47 2017 +0000 @@ -0,0 +1,32 @@ +#ifndef __CONFIG_LOOP_H +#define __CONFIG_LOOP_H + +#include "config_inverter.h" + +#define K_LOOP_D 2.5f +#define KI_BASE_D 0.025f + +#define K_LOOP_Q 6.0f +#define KI_BASE_Q 0.01f + +#define F_SLOW_LOOP 100.0f + +#define INTEGRAL_MAX 1.0f + +/*filter strengths, 0-1.0 + higher = stronger filtering*/ +#define W_FILTER_STRENGTH 0.99f +#define DQ_FILTER_STRENGTH 0.95f +#define THROTTLE_FILTER_STRENGTH 0.0f + + +/*internally computed*/ +#define KP_D (K_LOOP_D / BUS_VOLTAGE) +#define KI_D (KI_BASE_D * K_LOOP_D / BUS_VOLTAGE * 5000.0f / F_SW) + +#define KP_Q (K_LOOP_Q / BUS_VOLTAGE) +#define KI_Q (KI_BASE_Q * K_LOOP_Q / BUS_VOLTAGE * 5000.0f / F_SW) + +#define SLOW_LOOP_COUNTER ((int) (F_SW / F_SLOW_LOOP)) + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Defaults/config_motor.h Thu Mar 02 07:04:47 2017 +0000 @@ -0,0 +1,40 @@ +#ifndef __CONFIG_MOTOR_H +#define __CONFIG_MOTOR_H + +/*# of pole pairs*/ +#define POLE_PAIRS 3.0f + +/*mechanical position offset, + measured as +a, -b, -c (radians)*/ +#define POS_OFFSET 5.88f + +/*# of resolver lobes*/ +#define RESOLVER_LOBES 3.0f + +/*CPR of encoder or encoder emulator*/ +#define CPR 4096 + +/*d and q axis inductances, henries*/ +#define Ld 0.000876f +#define Lq 0.002068f + +/*PM flux linkage, volt-seconds*/ +#define FLUX_LINKAGE 0.06f + +/*single phase resistance, ohms*/ +#define Rs 0.05f + +/*torque/phase amp for approximate models*/ +#define KT 0.3f + +/*a safe speed below which you + never need to field weaken*/ +#define W_SAFE 100.0f + +/*maximum sane mechanical speed, + used to filter velocity (rad/s)*/ +#define W_CRAZY 1500.0f + +#define PI 3.141593f + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Defaults/config_pins.h Thu Mar 02 07:04:47 2017 +0000 @@ -0,0 +1,29 @@ +#ifndef __CONFIG_PINS_H +#define __CONFIG_PINS_H + +#define PWMA PA_8 +#define PWMB PA_9 +#define PWMC PA_10 +#define EN PB_15 + +#define IA PA_4 +#define IB PB_0 + +#define TH_PIN PB_8 + +#define TH_LIMIT_LOW 1100 //uS +#define TH_LIMIT_HIGH 1750 +#define TH_LIMIT_CRAZY 2000 + +#define I_SCALE_RAW 25.0f //mv/A +#define R_UP 12000.0f //ohms +#define R_DOWN 3600.0f //ohms +#define R_BIAS 3600.0f //ohms +#define AVDD 3300.0f //mV + +#define I_OFFSET (AVDD * R_DOWN * R_UP / (R_DOWN * R_UP + R_BIAS * (R_DOWN + R_UP))) +#define I_SCALE (R_BIAS * R_DOWN * I_SCALE_RAW / (R_DOWN * R_UP + R_BIAS * (R_DOWN + R_UP))) + +#define set_dtc(phase, value) *phase = (value) + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Defaults/config_table.h Thu Mar 02 07:04:47 2017 +0000 @@ -0,0 +1,9 @@ +#ifndef __CONFIG_TABLE_H +#define __CONFIG_TABLE_H + +#define ROWS 121 +#define COLUMNS 49 + +#define W_STEP 25.f + +#endif \ No newline at end of file
--- a/PreferenceWriter.h Wed Mar 01 00:52:47 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,21 +0,0 @@ -#ifndef __PREFERENCE_WRITER_H -#define __PREFERENCE_WRITER_H - -#include "mbed.h" -#include "FlashWriter.h" - -class PreferenceWriter { -public: - PreferenceWriter(uint32_t sector); - void open(); - void write(int x, int index); - void write(float x, int index); - void flush(); - void load(); - void close(); -private: - FlashWriter *writer; - uint32_t __sector; -}; - -#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PreferenceWriter/PreferenceWriter.h Thu Mar 02 07:04:47 2017 +0000 @@ -0,0 +1,23 @@ +#ifndef __PREFERENCE_WRITER_H +#define __PREFERENCE_WRITER_H + +#include "mbed.h" +#include "FlashWriter.h" + +class PreferenceWriter { +public: + PreferenceWriter(uint32_t sector); + void open(); + bool ready(); + void write(int x, int index); + void write(float x, int index); + void flush(); + void load(); + void close(); +private: + FlashWriter *writer; + uint32_t __sector; + bool __ready; +}; + +#endif \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PreferenceWriter/PrefrenceWriter.cpp Thu Mar 02 07:04:47 2017 +0000 @@ -0,0 +1,50 @@ +#include "PreferenceWriter.h" +#include "FlashWriter.h" +#include "config.h" + +PreferenceWriter::PreferenceWriter(uint32_t sector) { + writer = new FlashWriter(sector); + __sector = sector; + __ready = false; +} + +void PreferenceWriter::open() { + writer->open(); + __ready = true; +} + +bool PreferenceWriter::ready() { + return __ready; +} + +void PreferenceWriter::write(int x, int index) { + __int_reg[index] = x; +} + +void PreferenceWriter::write(float x, int index) { + __float_reg[index] = x; +} + +void PreferenceWriter::flush() { + int offs; + for (offs = 0; offs < 64; offs++) { + writer->write(offs, __int_reg[offs]); + } + for (; offs < 128; offs++) { + writer->write(offs, __float_reg[offs - 64]); + } +} + +void PreferenceWriter::load() { + int offs; + for (offs = 0; offs < 64; offs++) { + __int_reg[offs] = flashReadInt(__sector, offs); + } + for(; offs < 128; offs++) { + __float_reg[offs - 64] = flashReadFloat(__sector, offs); + } +} + +void PreferenceWriter::close() { + writer->close(); +} \ No newline at end of file
--- a/PrefrenceWriter.cpp Wed Mar 01 00:52:47 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,44 +0,0 @@ -#include "PreferenceWriter.h" -#include "FlashWriter.h" -#include "config.h" - -PreferenceWriter::PreferenceWriter(uint32_t sector) { - writer = new FlashWriter(sector); - __sector = sector; -} - -void PreferenceWriter::open() { - writer->open(); -} - -void PreferenceWriter::write(int x, int index) { - __int_reg[index] = x; -} - -void PreferenceWriter::write(float x, int index) { - __float_reg[index] = x; -} - -void PreferenceWriter::flush() { - int offs; - for (offs = 0; offs < 64; offs++) { - writer->write(offs, __int_reg[offs]); - } - for (; offs < 128; offs++) { - writer->write(offs, __float_reg[offs - 64]); - } -} - -void PreferenceWriter::load() { - int offs; - for (offs = 0; offs < 64; offs++) { - __int_reg[offs] = flashReadInt(__sector, offs); - } - for(; offs < 128; offs++) { - __float_reg[offs - 64] = flashReadFloat(__sector, offs); - } -} - -void PreferenceWriter::close() { - writer->close(); -} \ No newline at end of file
--- a/config.h Wed Mar 01 00:52:47 2017 +0000 +++ b/config.h Thu Mar 02 07:04:47 2017 +0000 @@ -1,6 +1,8 @@ #ifndef __CONFIG_H #define __CONFIG_H +#include "mbed.h" + /*---driving---*/ #define _TORQUE_MODE __int_reg[0] #define _MAX_TQPCT_PLUS __float_reg[0] @@ -68,7 +70,7 @@ extern int __int_reg[]; #define DEFAULT(a) _##a = a -#define FPRINT(a) pc.printf("%s: %f\n", #a, _##a) -#define DPRINT(a) pc.printf("%s: %d\n", #a, _##a) +#define FPRINT(a) pc->printf("%s: %f\n", #a, _##a) +#define DPRINT(a) pc->printf("%s: %d\n", #a, _##a) #endif \ No newline at end of file
--- a/config_driving.h Wed Mar 01 00:52:47 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,18 +0,0 @@ -#ifndef __CONFIG_DRIVING -#define __CONFIG_DRIVING - -#define TORQUE_MODE true - -/*forward torque scaling*/ -#define MAX_TQPCT_PLUS 1.0f - -/*reverse/regen torque scaling*/ -#define MAX_TQPCT_MINUS 0.3f - -/*maximum torque for approximate methods*/ -#define TORQUE_MAX 75.0f - -/*max speed, including any field weakening, rad/s*/ -#define W_MAX 1000.0f - -#endif \ No newline at end of file
--- a/config_inverter.h Wed Mar 01 00:52:47 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,10 +0,0 @@ -#ifndef __CONFIG_INVERTER_H -#define __CONFIG_INVERTER_H - -/*DC link voltage, volts*/ -#define BUS_VOLTAGE 160.0f - -/*switching frequency, hertz*/ -#define F_SW 5000.0f - -#endif \ No newline at end of file
--- a/config_logging.h Wed Mar 01 00:52:47 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,7 +0,0 @@ -#ifndef __CONFIG_LOGGING -#define __CONFIG_LOGGING - -#define ENABLE_LOGGING true -#define LOG_FREQUENCY 100.f - -#endif \ No newline at end of file
--- a/config_loop.h Wed Mar 01 00:52:47 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,32 +0,0 @@ -#ifndef __CONFIG_LOOP_H -#define __CONFIG_LOOP_H - -#include "config_inverter.h" - -#define K_LOOP_D 2.5f -#define KI_BASE_D 0.025f - -#define K_LOOP_Q 6.0f -#define KI_BASE_Q 0.01f - -#define F_SLOW_LOOP 100.0f - -#define INTEGRAL_MAX 1.0f - -/*filter strengths, 0-1.0 - higher = stronger filtering*/ -#define W_FILTER_STRENGTH 0.99f -#define DQ_FILTER_STRENGTH 0.95f -#define THROTTLE_FILTER_STRENGTH 0.0f - - -/*internally computed*/ -#define KP_D (K_LOOP_D / BUS_VOLTAGE) -#define KI_D (KI_BASE_D * K_LOOP_D / BUS_VOLTAGE * 5000.0f / F_SW) - -#define KP_Q (K_LOOP_Q / BUS_VOLTAGE) -#define KI_Q (KI_BASE_Q * K_LOOP_Q / BUS_VOLTAGE * 5000.0f / F_SW) - -#define SLOW_LOOP_COUNTER ((int) (F_SW / F_SLOW_LOOP)) - -#endif \ No newline at end of file
--- a/config_motor.h Wed Mar 01 00:52:47 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -#ifndef __CONFIG_MOTOR_H -#define __CONFIG_MOTOR_H - -/*# of pole pairs*/ -#define POLE_PAIRS 3.0f - -/*mechanical position offset, - measured as +a, -b, -c (radians)*/ -#define POS_OFFSET 5.88f - -/*# of resolver lobes*/ -#define RESOLVER_LOBES 3.0f - -/*CPR of encoder or encoder emulator*/ -#define CPR 4096 - -/*d and q axis inductances, henries*/ -#define Ld 0.000876f -#define Lq 0.002068f - -/*PM flux linkage, volt-seconds*/ -#define FLUX_LINKAGE 0.06f - -/*single phase resistance, ohms*/ -#define Rs 0.05f - -/*torque/phase amp for approximate models*/ -#define KT 0.3f - -/*a safe speed below which you - never need to field weaken*/ -#define W_SAFE 100.0f - -/*maximum sane mechanical speed, - used to filter velocity (rad/s)*/ -#define W_CRAZY 1500.0f - -#define PI 3.141593f - -#endif \ No newline at end of file
--- a/config_pins.h Wed Mar 01 00:52:47 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,29 +0,0 @@ -#ifndef __CONFIG_PINS_H -#define __CONFIG_PINS_H - -#define PWMA PA_8 -#define PWMB PA_9 -#define PWMC PA_10 -#define EN PB_15 - -#define IA PA_4 -#define IB PB_0 - -#define TH_PIN PB_8 - -#define TH_LIMIT_LOW 1100 //uS -#define TH_LIMIT_HIGH 1750 -#define TH_LIMIT_CRAZY 2000 - -#define I_SCALE_RAW 25.0f //mv/A -#define R_UP 12000.0f //ohms -#define R_DOWN 3600.0f //ohms -#define R_BIAS 3600.0f //ohms -#define AVDD 3300.0f //mV - -#define I_OFFSET (AVDD * R_DOWN * R_UP / (R_DOWN * R_UP + R_BIAS * (R_DOWN + R_UP))) -#define I_SCALE (R_BIAS * R_DOWN * I_SCALE_RAW / (R_DOWN * R_UP + R_BIAS * (R_DOWN + R_UP))) - -#define set_dtc(phase, value) *phase = (value) - -#endif \ No newline at end of file
--- a/config_table.h Wed Mar 01 00:52:47 2017 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,9 +0,0 @@ -#ifndef __CONFIG_TABLE_H -#define __CONFIG_TABLE_H - -#define ROWS 121 -#define COLUMNS 49 - -#define W_STEP 25.f - -#endif \ No newline at end of file
--- a/main.cpp Wed Mar 01 00:52:47 2017 +0000 +++ b/main.cpp Thu Mar 02 07:04:47 2017 +0000 @@ -1,113 +1,42 @@ #include "mbed.h" -#include "config.h" -#include "config_driving.h" -#include "config_inverter.h" -#include "config_logging.h" -#include "config_loop.h" -#include "config_motor.h" -#include "config_pins.h" -#include "config_table.h" + #include "PreferenceWriter.h" #include "FlashWriter.h" +#include "CommandProcessor.h" Serial pc(USBTX, USBRX); PreferenceWriter pref(6); +int index = 0; +char linebuf[128]; + +void rxCallback() { + while (pc.readable()) { + char c = pc.getc(); + if (c != 127 && c != '\r' && c != '\t') { + linebuf[index] = c; + index++; + pc.putc(c); + } else if (c == 127) { + if (index > 0) { + index--; + pc.putc(c); + } + } else if (c == '\r') { + linebuf[index] = 0; + pc.putc(c); + processCmd(&pc, &pref, linebuf); + index = 0; + pc.putc('>'); + } + } +} + int main() { pc.baud(115200); + pc.attach(rxCallback); pc.printf("%s\n", "Serial Configuration Test"); - - /* - DEFAULT(TORQUE_MODE); - DEFAULT(MAX_TQPCT_PLUS); - DEFAULT(MAX_TQPCT_MINUS); - DEFAULT(TORQUE_MAX); - DEFAULT(W_MAX); - DEFAULT(BUS_VOLTAGE); - DEFAULT(F_SW); - DEFAULT(K_LOOP_D); - DEFAULT(KI_BASE_D); - DEFAULT(K_LOOP_Q); - DEFAULT(KI_BASE_Q); - DEFAULT(F_SLOW_LOOP); - DEFAULT(INTEGRAL_MAX); - DEFAULT(W_FILTER_STRENGTH); - DEFAULT(DQ_FILTER_STRENGTH); - DEFAULT(THROTTLE_FILTER_STRENGTH); - DEFAULT(KP_D); - DEFAULT(KI_D); - DEFAULT(KP_Q); - DEFAULT(KI_Q); - DEFAULT(SLOW_LOOP_COUNTER); - DEFAULT(POLE_PAIRS); - DEFAULT(POS_OFFSET); - DEFAULT(RESOLVER_LOBES); - DEFAULT(CPR); - DEFAULT(Ld); - DEFAULT(Lq); - DEFAULT(FLUX_LINKAGE); - DEFAULT(Rs); - DEFAULT(KT); - DEFAULT(W_SAFE); - DEFAULT(W_CRAZY); - DEFAULT(TH_LIMIT_LOW); - DEFAULT(TH_LIMIT_HIGH); - DEFAULT(TH_LIMIT_CRAZY); - DEFAULT(ROWS); - DEFAULT(COLUMNS); - DEFAULT(W_STEP); - - pref.open(); - pref.flush(); - pref.close(); - - int offs; - for (offs = 0; offs < 64; offs++) { - __float_reg[offs] = 0.0f; - __int_reg[offs] = 0; - } - */ - - pref.load(); - - DPRINT(TORQUE_MODE); - FPRINT(MAX_TQPCT_PLUS); - FPRINT(MAX_TQPCT_MINUS); - FPRINT(TORQUE_MAX); - FPRINT(W_MAX); - FPRINT(BUS_VOLTAGE); - FPRINT(F_SW); - FPRINT(K_LOOP_D); - FPRINT(KI_BASE_D); - FPRINT(K_LOOP_Q); - FPRINT(KI_BASE_Q); - FPRINT(F_SLOW_LOOP); - FPRINT(INTEGRAL_MAX); - FPRINT(W_FILTER_STRENGTH); - FPRINT(DQ_FILTER_STRENGTH); - FPRINT(THROTTLE_FILTER_STRENGTH); - FPRINT(KP_D); - FPRINT(KI_D); - FPRINT(KP_Q); - FPRINT(KI_Q); - FPRINT(SLOW_LOOP_COUNTER); - FPRINT(POLE_PAIRS); - FPRINT(POS_OFFSET); - FPRINT(RESOLVER_LOBES); - DPRINT(CPR); - FPRINT(Ld); - FPRINT(Lq); - FPRINT(FLUX_LINKAGE); - FPRINT(Rs); - FPRINT(KT); - FPRINT(W_SAFE); - FPRINT(W_CRAZY); - DPRINT(TH_LIMIT_LOW); - DPRINT(TH_LIMIT_HIGH); - DPRINT(TH_LIMIT_CRAZY); - DPRINT(ROWS); - DPRINT(COLUMNS); - FPRINT(W_STEP); + pc.printf("%s", ">"); for(;;) { }