Bayley Wang
/
foc-ed_in_the_bot_compact
robot
Diff: main.cpp
- Revision:
- 84:dd32640942a4
- Parent:
- 83:eb3704d4943f
- Child:
- 86:b059f637e9ac
diff -r eb3704d4943f -r dd32640942a4 main.cpp --- a/main.cpp Sat Mar 11 08:51:04 2017 +0000 +++ b/main.cpp Sun Mar 12 06:49:10 2017 +0000 @@ -10,11 +10,11 @@ #include "ThrottleMapper.h" #include "PreferenceWriter.h" #include "CommandProcessor.h" +#include "Preferences.h" #include "BREMSStructs.h" #include "BREMSConfig.h" -#include "config.h" #include "config_motor.h" #include "config_loop.h" #include "config_pins.h" @@ -51,7 +51,7 @@ void commutate() { /*safety checks, do we do anything this cycle?*/ - if (!control.enabled && io.throttle_in->get_enabled() && io.pos->IsValid() && is_driving()) { + if (!control.enabled && checks_passed()) { go_enabled(); } @@ -76,6 +76,22 @@ clarke(foc.ia, foc.ib, &foc.alpha, &foc.beta); park(foc.alpha, foc.beta, sin_p, cos_p, &foc.d, &foc.q); + /*run additional controllers; the output of every controller is a torque percent*/ + switch (BREMS_op) { + case OP_TORQUE: + control.torque_percent = control.user_cmd; + break; + case OP_DRIVING: + control.torque_percent = th->map(control.user_cmd, read.w); + break; + case OP_SPEED: + //set velocity setpoint here; + break; + case OP_POSITION: + //set pos setpoint here; + break; + } + /*get references*/ /*happens here, as we may want other controllers running each cycle*/ dq->map(control.torque_percent, read.w, &control.d_ref, &control.q_ref); @@ -117,15 +133,29 @@ vc = vc - voff; /*safety checks, reset integral*/ - if (!io.throttle_in->get_enabled() || !io.pos->IsValid() || !is_driving()) { - /*do this even in disabled state, to keep integral down*/ + if (!checks_passed()) { go_disabled(); } /*output to timers*/ - set_dtc(io.a, 0.5f + 0.5f * va); - set_dtc(io.b, 0.5f + 0.5f * vb); - set_dtc(io.c, 0.5f + 0.5f * vc); + switch (BREMS_mode) { + case MODE_CFG: + set_dtc(io.a, 0.5f); + set_dtc(io.b, 0.5f); + set_dtc(io.c, 0.5f); + break; + case MODE_RUN: + set_dtc(io.a, 0.5f + 0.5f * va); + set_dtc(io.b, 0.5f + 0.5f * vb); + set_dtc(io.c, 0.5f + 0.5f * vc); + break; + case MODE_ZERO: + //zeroing code here; + break; + case MODE_CHR: + //i have no idea lol; + break; + } } void slow_loop() { @@ -144,20 +174,6 @@ //these sources are updated asynchronously via interrupts break; } - switch (BREMS_op) { - case OP_TORQUE: - control.torque_percent = control.user_cmd; - break; - case OP_DRIVING: - control.torque_percent = th->map(control.user_cmd, read.w); - break; - case OP_SPEED: - //set velocity setpoint here; - break; - case OP_POSITION: - //set pos setpoint here; - break; - } } int main() {