Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of analoghalls by
util.cpp@1:70eed554399b, 2015-02-21 (annotated)
- Committer:
- bwang
- Date:
- Sat Feb 21 21:39:33 2015 +0000
- Revision:
- 1:70eed554399b
- Parent:
- 0:9753f3c2e5ca
- Child:
- 2:b5c19d4eddcc
potato
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| nki | 0:9753f3c2e5ca | 1 | #include "constants.h" |
| nki | 0:9753f3c2e5ca | 2 | #include "shared.h" |
| nki | 0:9753f3c2e5ca | 3 | #include "isr.h" |
| nki | 0:9753f3c2e5ca | 4 | #include <stdlib.h> |
| nki | 0:9753f3c2e5ca | 5 | |
| nki | 0:9753f3c2e5ca | 6 | void initTimers() { |
| bwang | 1:70eed554399b | 7 | dtc_upd_ticker.attach_us(&dtc_update, 200); |
| bwang | 1:70eed554399b | 8 | throttle_upd_ticker.attach_us(&throttle_update, 100000); |
| bwang | 1:70eed554399b | 9 | |
| nki | 0:9753f3c2e5ca | 10 | pha.period_us(200); |
| nki | 0:9753f3c2e5ca | 11 | phb.period_us(200); |
| nki | 0:9753f3c2e5ca | 12 | phc.period_us(200); |
| nki | 0:9753f3c2e5ca | 13 | pha = 0; |
| nki | 0:9753f3c2e5ca | 14 | phb = 1.0f; |
| nki | 0:9753f3c2e5ca | 15 | phc = 0; |
| nki | 0:9753f3c2e5ca | 16 | |
| nki | 0:9753f3c2e5ca | 17 | } |
| nki | 0:9753f3c2e5ca | 18 | |
| bwang | 1:70eed554399b | 19 | void initPins() { |
| nki | 0:9753f3c2e5ca | 20 | en = 0; |
| nki | 0:9753f3c2e5ca | 21 | } |
| nki | 0:9753f3c2e5ca | 22 | |
| nki | 0:9753f3c2e5ca | 23 | void initData() { |
| nki | 0:9753f3c2e5ca | 24 | motor = (Motor*) malloc(sizeof(Motor)); |
| nki | 0:9753f3c2e5ca | 25 | motor->sensor_phase = SENSOR_PHASE; |
| nki | 0:9753f3c2e5ca | 26 | motor->halt = 1; |
| bwang | 1:70eed554399b | 27 | motor->angle =0; |
| bwang | 1:70eed554399b | 28 | |
| nki | 0:9753f3c2e5ca | 29 | float throttle_raw; |
| nki | 0:9753f3c2e5ca | 30 | do { |
| nki | 0:9753f3c2e5ca | 31 | throttle_raw = throttle; |
| nki | 0:9753f3c2e5ca | 32 | throttle_raw = (throttle_raw - THROTTLE_DB) / (1.0f - THROTTLE_DB); |
| nki | 0:9753f3c2e5ca | 33 | if (throttle_raw < 0.0f) throttle_raw = 0.0f; |
| nki | 0:9753f3c2e5ca | 34 | } while (throttle_raw > 0.05f); |
| nki | 0:9753f3c2e5ca | 35 | |
| nki | 0:9753f3c2e5ca | 36 | motor->throttle = (1.0f - THROTTLE_LPF) * throttle_raw + THROTTLE_LPF * motor->throttle; |
| nki | 0:9753f3c2e5ca | 37 | if (motor->throttle < 0.05f) { |
| nki | 0:9753f3c2e5ca | 38 | motor->halt = 1; |
| nki | 0:9753f3c2e5ca | 39 | } else { |
| nki | 0:9753f3c2e5ca | 40 | motor->halt = 0; |
| nki | 0:9753f3c2e5ca | 41 | } |
| nki | 0:9753f3c2e5ca | 42 | } |
