Aaron Lamoreaux
/
avc
AVC Code
main.cpp@7:6efd4f07ae00, 2019-03-09 (annotated)
- Committer:
- lamoreauxaj
- Date:
- Sat Mar 09 22:17:08 2019 +0000
- Revision:
- 7:6efd4f07ae00
- Parent:
- 5:12eddb3cacc9
k
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
lamoreauxaj | 0:8a7153ecd2bc | 1 | /* mbed Microcontroller Library |
lamoreauxaj | 0:8a7153ecd2bc | 2 | * Copyright (c) 2018 ARM Limited |
lamoreauxaj | 0:8a7153ecd2bc | 3 | * SPDX-License-Identifier: Apache-2.0 |
lamoreauxaj | 0:8a7153ecd2bc | 4 | */ |
lamoreauxaj | 0:8a7153ecd2bc | 5 | |
lamoreauxaj | 0:8a7153ecd2bc | 6 | #include "mbed.h" |
lamoreauxaj | 1:5a458b26e64d | 7 | #include "TFC.h" |
lamoreauxaj | 2:9bd28448e604 | 8 | #include <cmath> |
lamoreauxaj | 0:8a7153ecd2bc | 9 | |
lamoreauxaj | 0:8a7153ecd2bc | 10 | DigitalOut led1(LED1); |
lamoreauxaj | 1:5a458b26e64d | 11 | Serial pc(USBTX, USBRX); |
lamoreauxaj | 0:8a7153ecd2bc | 12 | |
lamoreauxaj | 2:9bd28448e604 | 13 | float lastStatusUpdate = 0; |
lamoreauxaj | 2:9bd28448e604 | 14 | float batteryVoltage; |
lamoreauxaj | 2:9bd28448e604 | 15 | void updateStatus (float delta, float currTime) { |
lamoreauxaj | 2:9bd28448e604 | 16 | if (currTime - lastStatusUpdate > 1) { |
lamoreauxaj | 2:9bd28448e604 | 17 | lastStatusUpdate = currTime; |
lamoreauxaj | 2:9bd28448e604 | 18 | pc.printf("Battery Voltage: %.2f\r\n", batteryVoltage); |
lamoreauxaj | 2:9bd28448e604 | 19 | } |
lamoreauxaj | 2:9bd28448e604 | 20 | } |
lamoreauxaj | 2:9bd28448e604 | 21 | |
lamoreauxaj | 2:9bd28448e604 | 22 | |
lamoreauxaj | 2:9bd28448e604 | 23 | void updateBattery (float delta, float currTime) { |
JamsRamen | 3:9338aee2dd2d | 24 | float maxVoltage = 3.0f; |
lamoreauxaj | 2:9bd28448e604 | 25 | batteryVoltage = TFC_ReadBatteryVoltage(); |
lamoreauxaj | 2:9bd28448e604 | 26 | float fractionCharged = TFC_ReadBatteryVoltage() / maxVoltage; |
lamoreauxaj | 2:9bd28448e604 | 27 | |
lamoreauxaj | 2:9bd28448e604 | 28 | int level = floor(4*fractionCharged + 0.5f); |
lamoreauxaj | 2:9bd28448e604 | 29 | |
lamoreauxaj | 2:9bd28448e604 | 30 | if (level < 0) level = 0; |
lamoreauxaj | 2:9bd28448e604 | 31 | if (level > 4) level = 4; |
lamoreauxaj | 2:9bd28448e604 | 32 | |
lamoreauxaj | 2:9bd28448e604 | 33 | TFC_SetBatteryLED_Level(level); |
lamoreauxaj | 2:9bd28448e604 | 34 | } |
lamoreauxaj | 0:8a7153ecd2bc | 35 | |
JamsRamen | 5:12eddb3cacc9 | 36 | |
lamoreauxaj | 1:5a458b26e64d | 37 | void update(float delta, float currTime) { |
lamoreauxaj | 2:9bd28448e604 | 38 | // pc.printf("Camera1: %d; Camera2 %d\r\n", camera1.read(), camera2.read()); |
lamoreauxaj | 2:9bd28448e604 | 39 | TFC_HBRIDGE_ENABLE; |
JamsRamen | 5:12eddb3cacc9 | 40 | TFC_SetMotorPWM(0.2f, 0.2f); |
JamsRamen | 5:12eddb3cacc9 | 41 | TFC_SetServo(0, 0); |
lamoreauxaj | 2:9bd28448e604 | 42 | updateBattery(delta, currTime); |
lamoreauxaj | 2:9bd28448e604 | 43 | |
lamoreauxaj | 2:9bd28448e604 | 44 | updateStatus(delta, currTime); |
lamoreauxaj | 1:5a458b26e64d | 45 | } |
lamoreauxaj | 0:8a7153ecd2bc | 46 | |
lamoreauxaj | 1:5a458b26e64d | 47 | int main() { |
lamoreauxaj | 2:9bd28448e604 | 48 | TFC_Init(); |
lamoreauxaj | 1:5a458b26e64d | 49 | int startClock = 0; |
lamoreauxaj | 1:5a458b26e64d | 50 | float lastTime = 0; |
lamoreauxaj | 1:5a458b26e64d | 51 | |
lamoreauxaj | 0:8a7153ecd2bc | 52 | while (true) { |
lamoreauxaj | 1:5a458b26e64d | 53 | |
lamoreauxaj | 1:5a458b26e64d | 54 | float currTime = float(clock() - startClock) / CLOCKS_PER_SEC; |
lamoreauxaj | 1:5a458b26e64d | 55 | update(currTime - lastTime, currTime); |
lamoreauxaj | 1:5a458b26e64d | 56 | lastTime = currTime; |
lamoreauxaj | 1:5a458b26e64d | 57 | |
lamoreauxaj | 0:8a7153ecd2bc | 58 | } |
lamoreauxaj | 0:8a7153ecd2bc | 59 | } |