Bayley Wang
/
foc-ed_in_the_bot_compact
robot
Diff: main.cpp
- Revision:
- 75:591556ce033d
- Parent:
- 74:f10cb573d7ca
- Child:
- 76:c66014e50384
diff -r f10cb573d7ca -r 591556ce033d main.cpp --- a/main.cpp Fri Feb 24 13:03:34 2017 +0000 +++ b/main.cpp Fri Feb 24 21:37:14 2017 +0000 @@ -47,7 +47,7 @@ read.w = update_filter(read.w, w_raw, W_FILTER_STRENGTH); } -void commutate() { +void commutate() { /*safety checks, do we do anything this cycle?*/ if (!control_enabled && io.throttle_in->get_enabled() && io.pos->IsValid() && is_driving()) { go_enabled(); @@ -124,11 +124,8 @@ void slow_loop() { float x = io.throttle_in->get_throttle(); - if (x < THROTTLE_FILTER_THRESHOLD) { - control.torque_percent = update_filter(control.torque_percent, th->map(io.throttle_in->get_throttle(), read.w), THROTTLE_FILTER_STRENGTH_LOW); - } else { - control.torque_percent = update_filter(control.torque_percent, th->map(io.throttle_in->get_throttle(), read.w), THROTTLE_FILTER_STRENGTH_HI); - } + control.torque_percent = update_filter(control.torque_percent, th->map(io.throttle_in->get_throttle(), read.w), THROTTLE_FILTER_STRENGTH); + dq->map(control.torque_percent, read.w, &control.d_ref, &control.q_ref); } @@ -155,12 +152,13 @@ void log() { //io.pc->printf("%d,%d,%d,%d,%d,%d,%d,%d\n", (int) read.w, (int) control.d_ref, (int) control.d_filtered, (int) control.q_ref, (int) control.q_filtered, (int) (255 * control.torque_percent), // (int) (255 * foc.vd), (int) (255 * foc.vq)); - io.pc->printf("%d\n", (int) (255 * control.torque_percent)); + io.pc->printf("%d\n", io.throttle_in->get_usecs()); wait(1.0f / LOG_FREQUENCY); } extern "C" void TIM1_UP_TIM10_IRQHandler(void) { + int start_state = io.throttle_in->state(); if (TIM1->SR & TIM_SR_UIF ) { ADC1->CR2 |= 0x40000000; volatile int delay; @@ -170,6 +168,8 @@ commutate(); } TIM1->SR = 0x00; + int end_state = io.throttle_in->state(); + if (start_state != end_state) io.throttle_in->block(); } int main() {