N K
/
analoghalls_part_4
yup
Fork of analoghalls by
util.cpp
- Committer:
- bwang
- Date:
- 2015-02-21
- Revision:
- 1:70eed554399b
- Parent:
- 0:9753f3c2e5ca
- Child:
- 2:b5c19d4eddcc
File content as of revision 1:70eed554399b:
#include "constants.h" #include "shared.h" #include "isr.h" #include <stdlib.h> void initTimers() { dtc_upd_ticker.attach_us(&dtc_update, 200); throttle_upd_ticker.attach_us(&throttle_update, 100000); pha.period_us(200); phb.period_us(200); phc.period_us(200); pha = 0; phb = 1.0f; phc = 0; } void initPins() { en = 0; } void initData() { motor = (Motor*) malloc(sizeof(Motor)); motor->sensor_phase = SENSOR_PHASE; motor->halt = 1; motor->angle =0; float throttle_raw; do { throttle_raw = throttle; throttle_raw = (throttle_raw - THROTTLE_DB) / (1.0f - THROTTLE_DB); if (throttle_raw < 0.0f) throttle_raw = 0.0f; } while (throttle_raw > 0.05f); motor->throttle = (1.0f - THROTTLE_LPF) * throttle_raw + THROTTLE_LPF * motor->throttle; if (motor->throttle < 0.05f) { motor->halt = 1; } else { motor->halt = 0; } }