Xiaohai Li
/
RPi_MOT_HAT
Raspberry Pi MOT HAT Based on STM32F030R8. The clock needs to be changed to 8MHz after export.
AplicationLayer/SelfTest.cpp@3:171f4d0ca77b, 2015-08-20 (annotated)
- Committer:
- nightseas
- Date:
- Thu Aug 20 11:36:01 2015 +0000
- Revision:
- 3:171f4d0ca77b
- Parent:
- 2:cff0fa966e58
- Child:
- 4:fb5235d39a9c
Add debug commander tool.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
nightseas | 0:633cef71e6ba | 1 | #include "SysConfig.h" |
nightseas | 0:633cef71e6ba | 2 | |
nightseas | 1:a6bcf44b90df | 3 | void SpeedTest(void) |
nightseas | 1:a6bcf44b90df | 4 | { |
nightseas | 3:171f4d0ca77b | 5 | uart_db.printf("[Speed Test]\n\rMOT1 = %drpm, MOT2 = %drpm, MOT3 = %drpm, MOT4 = %drpm.\n\r", Mot_GetSpeed(1), Mot_GetSpeed(2), Mot_GetSpeed(3), Mot_GetSpeed(4)); |
nightseas | 1:a6bcf44b90df | 6 | } |
nightseas | 1:a6bcf44b90df | 7 | |
nightseas | 1:a6bcf44b90df | 8 | void VoltageTest(void) |
nightseas | 1:a6bcf44b90df | 9 | { |
nightseas | 3:171f4d0ca77b | 10 | uart_db.printf("[Voltage Test]\n\rVBAT = %.2fV, VDD12V = %.2fV, VDD5V = %.2fV, VDD3V3 = %.2fV.\n\r", Vmon_ReadVolt(1), Vmon_ReadVolt(2), Vmon_ReadVolt(3), Vmon_ReadVolt(4)); |
nightseas | 1:a6bcf44b90df | 11 | } |
nightseas | 1:a6bcf44b90df | 12 | |
nightseas | 1:a6bcf44b90df | 13 | void MotTest(void) |
nightseas | 1:a6bcf44b90df | 14 | { |
nightseas | 1:a6bcf44b90df | 15 | int dir, turn; |
nightseas | 3:171f4d0ca77b | 16 | uart_db.printf("\n\r==== Motor Test ====\n\r"); |
nightseas | 1:a6bcf44b90df | 17 | for(int i=0; i<100; i+=20) |
nightseas | 1:a6bcf44b90df | 18 | { |
nightseas | 3:171f4d0ca77b | 19 | uart_db.printf("\n\rMotor speed set to %d%%.\n\r", i); |
nightseas | 3:171f4d0ca77b | 20 | uart_db.printf("-->Motor will move forward.\n\r"); |
nightseas | 1:a6bcf44b90df | 21 | dir = 'f'; |
nightseas | 1:a6bcf44b90df | 22 | |
nightseas | 3:171f4d0ca77b | 23 | uart_db.printf("---->Motor will move straight.\n\r"); |
nightseas | 1:a6bcf44b90df | 24 | turn = 'm'; |
nightseas | 1:a6bcf44b90df | 25 | Mot_Ctrl(dir, turn, (float)i / 100.0); |
nightseas | 1:a6bcf44b90df | 26 | SpeedTest(); |
nightseas | 1:a6bcf44b90df | 27 | VoltageTest(); |
nightseas | 1:a6bcf44b90df | 28 | LedToggle(0); |
nightseas | 1:a6bcf44b90df | 29 | wait(3); |
nightseas | 1:a6bcf44b90df | 30 | |
nightseas | 3:171f4d0ca77b | 31 | uart_db.printf("---->Motor will turn left.\n\r"); |
nightseas | 1:a6bcf44b90df | 32 | turn = 'l'; |
nightseas | 1:a6bcf44b90df | 33 | Mot_Ctrl(dir, turn, (float)i / 100.0); |
nightseas | 1:a6bcf44b90df | 34 | SpeedTest(); |
nightseas | 1:a6bcf44b90df | 35 | VoltageTest(); |
nightseas | 1:a6bcf44b90df | 36 | LedToggle(0); |
nightseas | 1:a6bcf44b90df | 37 | wait(3); |
nightseas | 1:a6bcf44b90df | 38 | |
nightseas | 3:171f4d0ca77b | 39 | uart_db.printf("---->Motor will turn right.\n\r"); |
nightseas | 1:a6bcf44b90df | 40 | turn = 'r'; |
nightseas | 1:a6bcf44b90df | 41 | Mot_Ctrl(dir, turn, (float)i / 100.0); |
nightseas | 1:a6bcf44b90df | 42 | SpeedTest(); |
nightseas | 1:a6bcf44b90df | 43 | VoltageTest(); |
nightseas | 1:a6bcf44b90df | 44 | LedToggle(0); |
nightseas | 1:a6bcf44b90df | 45 | wait(3); |
nightseas | 1:a6bcf44b90df | 46 | |
nightseas | 3:171f4d0ca77b | 47 | uart_db.printf("-->Motor will move forward.\n\r"); |
nightseas | 1:a6bcf44b90df | 48 | dir = 'b'; |
nightseas | 1:a6bcf44b90df | 49 | |
nightseas | 3:171f4d0ca77b | 50 | uart_db.printf("---->Motor will move straight.\n\r"); |
nightseas | 1:a6bcf44b90df | 51 | turn = 'm'; |
nightseas | 1:a6bcf44b90df | 52 | Mot_Ctrl(dir, turn, (float)i / 100.0); |
nightseas | 1:a6bcf44b90df | 53 | SpeedTest(); |
nightseas | 1:a6bcf44b90df | 54 | VoltageTest(); |
nightseas | 1:a6bcf44b90df | 55 | LedToggle(0); |
nightseas | 1:a6bcf44b90df | 56 | wait(3); |
nightseas | 1:a6bcf44b90df | 57 | |
nightseas | 3:171f4d0ca77b | 58 | uart_db.printf("---->Motor will turn left.\n\r"); |
nightseas | 1:a6bcf44b90df | 59 | turn = 'l'; |
nightseas | 1:a6bcf44b90df | 60 | Mot_Ctrl(dir, turn, (float)i / 100.0); |
nightseas | 1:a6bcf44b90df | 61 | SpeedTest(); |
nightseas | 1:a6bcf44b90df | 62 | VoltageTest(); |
nightseas | 1:a6bcf44b90df | 63 | LedToggle(0); |
nightseas | 1:a6bcf44b90df | 64 | wait(3); |
nightseas | 1:a6bcf44b90df | 65 | |
nightseas | 3:171f4d0ca77b | 66 | uart_db.printf("---->Motor will turn right.\n\r"); |
nightseas | 1:a6bcf44b90df | 67 | turn = 'r'; |
nightseas | 1:a6bcf44b90df | 68 | Mot_Ctrl(dir, turn, (float)i / 100.0); |
nightseas | 1:a6bcf44b90df | 69 | SpeedTest(); |
nightseas | 1:a6bcf44b90df | 70 | VoltageTest(); |
nightseas | 1:a6bcf44b90df | 71 | LedToggle(0); |
nightseas | 1:a6bcf44b90df | 72 | wait(3); |
nightseas | 1:a6bcf44b90df | 73 | } |
nightseas | 1:a6bcf44b90df | 74 | } |
nightseas | 1:a6bcf44b90df | 75 | |
nightseas | 0:633cef71e6ba | 76 | void SelfTest(void) |
nightseas | 1:a6bcf44b90df | 77 | #if 1 |
nightseas | 1:a6bcf44b90df | 78 | { |
nightseas | 3:171f4d0ca77b | 79 | uart_db.printf("Starting motor velocimeter...\n\r"); |
nightseas | 1:a6bcf44b90df | 80 | Mot_StartVelocimeter(); |
nightseas | 3:171f4d0ca77b | 81 | MotTest(); |
nightseas | 3:171f4d0ca77b | 82 | Mot_StopVelocimeter(); |
nightseas | 1:a6bcf44b90df | 83 | } |
nightseas | 1:a6bcf44b90df | 84 | #elif |
nightseas | 0:633cef71e6ba | 85 | { |
nightseas | 0:633cef71e6ba | 86 | //Breath LED |
nightseas | 0:633cef71e6ba | 87 | int i, j; |
nightseas | 0:633cef71e6ba | 88 | led_mb = 0; |
nightseas | 0:633cef71e6ba | 89 | while(1) |
nightseas | 0:633cef71e6ba | 90 | { |
nightseas | 0:633cef71e6ba | 91 | for(j=0;j<=100;j++) |
nightseas | 0:633cef71e6ba | 92 | { |
nightseas | 0:633cef71e6ba | 93 | for(i=0;i<=100;i++) |
nightseas | 0:633cef71e6ba | 94 | { |
nightseas | 0:633cef71e6ba | 95 | led_mb = 1; |
nightseas | 0:633cef71e6ba | 96 | wait_us(j); |
nightseas | 0:633cef71e6ba | 97 | led_mb = 0; |
nightseas | 0:633cef71e6ba | 98 | wait_us(100-j); |
nightseas | 0:633cef71e6ba | 99 | } |
nightseas | 0:633cef71e6ba | 100 | } |
nightseas | 0:633cef71e6ba | 101 | for(j=100;j>=0;j--) |
nightseas | 0:633cef71e6ba | 102 | { |
nightseas | 0:633cef71e6ba | 103 | for(i=0;i<=100;i++) |
nightseas | 0:633cef71e6ba | 104 | { |
nightseas | 0:633cef71e6ba | 105 | led_mb = 1; |
nightseas | 0:633cef71e6ba | 106 | wait_us(j); |
nightseas | 0:633cef71e6ba | 107 | led_mb = 0; |
nightseas | 0:633cef71e6ba | 108 | wait_us(100-j); |
nightseas | 0:633cef71e6ba | 109 | } |
nightseas | 0:633cef71e6ba | 110 | } |
nightseas | 0:633cef71e6ba | 111 | wait_ms(200); |
nightseas | 0:633cef71e6ba | 112 | } |
nightseas | 1:a6bcf44b90df | 113 | } |
nightseas | 3:171f4d0ca77b | 114 | #endif |