As used for BB testing April / May 2016 (with the odd mod to the scope outputs)
Dependencies: iC_MU mbed-rtos mbed
Fork of SweptSine by
main.cpp@3:4deb86f4ccfe, 2016-06-08 (annotated)
- Committer:
- acodd
- Date:
- Wed Jun 08 13:53:50 2016 +0000
- Revision:
- 3:4deb86f4ccfe
- Parent:
- 2:be3b6a72f823
As used for much of head tuning process documented in "T3 head Tuning" document.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ms523 | 0:3a132f85c1a8 | 1 | #include "mbed.h" |
ms523 | 1:0f0423207b62 | 2 | #include "iC_MU.h" |
ms523 | 1:0f0423207b62 | 3 | #include "rtos.h" |
acodd | 3:4deb86f4ccfe | 4 | #include "MyAxis.h" |
ms523 | 1:0f0423207b62 | 5 | |
ms523 | 1:0f0423207b62 | 6 | // iC-MU Encoder Objects |
acodd | 3:4deb86f4ccfe | 7 | iC_MU tilt_Motor(p5,p6,p7,p8); |
acodd | 3:4deb86f4ccfe | 8 | iC_MU TiltPos(p5,p6,p7,p11); |
acodd | 3:4deb86f4ccfe | 9 | iC_MU pan_Motor(p5,p6,p7,p12); |
acodd | 3:4deb86f4ccfe | 10 | iC_MU PanPos(p5,p6,p7,p13); |
ms523 | 1:0f0423207b62 | 11 | |
acodd | 3:4deb86f4ccfe | 12 | // Tilt Motor |
acodd | 3:4deb86f4ccfe | 13 | PwmOut Tilt_Motor_PWM(p23); // Purple wire |
acodd | 3:4deb86f4ccfe | 14 | DigitalOut Tilt_Motor_Direction(p24); // Yellow wire |
ms523 | 1:0f0423207b62 | 15 | // Pan Motor |
ms523 | 1:0f0423207b62 | 16 | PwmOut Pan_Motor_PWM(p21); // Purple wire |
ms523 | 1:0f0423207b62 | 17 | DigitalOut Pan_Motor_Direction(p22); // Yellow wire |
ms523 | 1:0f0423207b62 | 18 | |
ms523 | 1:0f0423207b62 | 19 | // Serial objects |
ms523 | 0:3a132f85c1a8 | 20 | Serial pc (USBTX,USBRX); |
ms523 | 1:0f0423207b62 | 21 | |
acodd | 3:4deb86f4ccfe | 22 | int ServiceKeyboard(); |
acodd | 3:4deb86f4ccfe | 23 | |
acodd | 3:4deb86f4ccfe | 24 | // Global Variables for sinusoidrun |
acodd | 3:4deb86f4ccfe | 25 | float run_time = 10.0; |
ms523 | 1:0f0423207b62 | 26 | float start_Hz = 1.0, stop_Hz = 2.0; |
acodd | 3:4deb86f4ccfe | 27 | extern float amplitude; |
acodd | 3:4deb86f4ccfe | 28 | bool sinusoid = 0; |
acodd | 3:4deb86f4ccfe | 29 | extern float a; |
acodd | 3:4deb86f4ccfe | 30 | extern float Hz; |
acodd | 3:4deb86f4ccfe | 31 | |
acodd | 3:4deb86f4ccfe | 32 | // Global variables for auto gearbox calculator |
acodd | 3:4deb86f4ccfe | 33 | bool ratiocalc = 0; |
acodd | 3:4deb86f4ccfe | 34 | |
ms523 | 1:0f0423207b62 | 35 | |
ms523 | 1:0f0423207b62 | 36 | // External variables |
ms523 | 1:0f0423207b62 | 37 | extern int LasticMuPosition; |
ms523 | 1:0f0423207b62 | 38 | |
ms523 | 1:0f0423207b62 | 39 | // Functions |
acodd | 3:4deb86f4ccfe | 40 | void PanAxisInitialise(); |
acodd | 3:4deb86f4ccfe | 41 | void TiltAxisInitialise(); |
acodd | 3:4deb86f4ccfe | 42 | void AxisControlLoop(MyAxis& Axis); |
acodd | 3:4deb86f4ccfe | 43 | |
acodd | 3:4deb86f4ccfe | 44 | |
acodd | 3:4deb86f4ccfe | 45 | void RunLoop(void const *args) |
acodd | 3:4deb86f4ccfe | 46 | { |
acodd | 3:4deb86f4ccfe | 47 | AxisControlLoop(Pan); |
acodd | 3:4deb86f4ccfe | 48 | AxisControlLoop(Tilt); |
acodd | 3:4deb86f4ccfe | 49 | } |
ms523 | 0:3a132f85c1a8 | 50 | |
ms523 | 0:3a132f85c1a8 | 51 | int main() |
ms523 | 0:3a132f85c1a8 | 52 | { |
ms523 | 1:0f0423207b62 | 53 | // Initalise Pan Velocity loop RtosTimer thread |
acodd | 3:4deb86f4ccfe | 54 | //Startme(); |
ms523 | 1:0f0423207b62 | 55 | pc.baud(921600); |
acodd | 3:4deb86f4ccfe | 56 | pc.printf("\n\r AH-10 Full Test V2 \n\r"); |
acodd | 3:4deb86f4ccfe | 57 | pc.printf("\n\r Press q for menu \n\r"); |
acodd | 3:4deb86f4ccfe | 58 | PanAxisInitialise(); |
acodd | 3:4deb86f4ccfe | 59 | TiltAxisInitialise(); |
acodd | 3:4deb86f4ccfe | 60 | RtosTimer RunLoop_timer(RunLoop, osTimerPeriodic); |
acodd | 3:4deb86f4ccfe | 61 | RunLoop_timer.start(1); // Run at 1kHz |
ms523 | 1:0f0423207b62 | 62 | |
ms523 | 1:0f0423207b62 | 63 | |
ms523 | 1:0f0423207b62 | 64 | while(1) { |
acodd | 3:4deb86f4ccfe | 65 | |
acodd | 3:4deb86f4ccfe | 66 | if(pc.readable()) { |
acodd | 3:4deb86f4ccfe | 67 | ServiceKeyboard(); |
acodd | 3:4deb86f4ccfe | 68 | } |
acodd | 3:4deb86f4ccfe | 69 | |
acodd | 3:4deb86f4ccfe | 70 | if (sinusoid) { |
acodd | 3:4deb86f4ccfe | 71 | sinusoid = false; |
acodd | 3:4deb86f4ccfe | 72 | |
acodd | 3:4deb86f4ccfe | 73 | // Prompt the user to enter the test parameters |
acodd | 3:4deb86f4ccfe | 74 | pc.printf("\n\r Enter Start frequency (Hz): "); |
acodd | 3:4deb86f4ccfe | 75 | pc.scanf("%f", &start_Hz); |
acodd | 3:4deb86f4ccfe | 76 | pc.printf("%f",start_Hz); |
acodd | 3:4deb86f4ccfe | 77 | |
acodd | 3:4deb86f4ccfe | 78 | pc.printf("\n\r Enter Stop frequency (Hz): "); |
acodd | 3:4deb86f4ccfe | 79 | pc.scanf("%f", &stop_Hz); |
acodd | 3:4deb86f4ccfe | 80 | pc.printf("%f",stop_Hz); |
acodd | 3:4deb86f4ccfe | 81 | |
acodd | 3:4deb86f4ccfe | 82 | pc.printf("\n\r Enter Amplitude (encoder counts): "); |
acodd | 3:4deb86f4ccfe | 83 | pc.scanf("%f", &litude); |
acodd | 3:4deb86f4ccfe | 84 | pc.printf("%f",amplitude); |
acodd | 3:4deb86f4ccfe | 85 | |
acodd | 3:4deb86f4ccfe | 86 | pc.printf("\n\r Enter Time (s): "); |
acodd | 3:4deb86f4ccfe | 87 | pc.scanf("%f", &run_time); |
acodd | 3:4deb86f4ccfe | 88 | pc.printf("%f",run_time); |
acodd | 3:4deb86f4ccfe | 89 | |
acodd | 3:4deb86f4ccfe | 90 | pc.printf("\n\n\r Press any key to start test..."); |
acodd | 3:4deb86f4ccfe | 91 | pc.getc(); |
acodd | 3:4deb86f4ccfe | 92 | |
acodd | 3:4deb86f4ccfe | 93 | a = (stop_Hz - start_Hz) / (run_time * 1000); // This is the incrementor |
acodd | 3:4deb86f4ccfe | 94 | pc.printf("\n\n\n\r ********************************************* \n\n\n\r *************************************************"); |
acodd | 3:4deb86f4ccfe | 95 | // pc.printf("\n\n\r Time (ms),input,output,frequency (Hz)"); |
acodd | 3:4deb86f4ccfe | 96 | pc.printf("\n\n\r Time (ms),Motor,System,frequency (Hz x 100),Demand"); |
acodd | 3:4deb86f4ccfe | 97 | |
acodd | 3:4deb86f4ccfe | 98 | Pan.start_SysPos = Pan.System_position; |
acodd | 3:4deb86f4ccfe | 99 | Pan.start_MotPos = Pan.Motor_position; |
acodd | 3:4deb86f4ccfe | 100 | |
acodd | 3:4deb86f4ccfe | 101 | Tilt.start_SysPos = Tilt.System_position; |
acodd | 3:4deb86f4ccfe | 102 | Tilt.start_MotPos = Tilt.Motor_position; |
acodd | 3:4deb86f4ccfe | 103 | |
acodd | 3:4deb86f4ccfe | 104 | // Set the test running# |
acodd | 3:4deb86f4ccfe | 105 | if (Pan.jog > 0){ |
acodd | 3:4deb86f4ccfe | 106 | Pan.sinusoidrun = 1; |
acodd | 3:4deb86f4ccfe | 107 | } |
acodd | 3:4deb86f4ccfe | 108 | if (Tilt.jog > 0) { |
acodd | 3:4deb86f4ccfe | 109 | Tilt.sinusoidrun = 1; |
acodd | 3:4deb86f4ccfe | 110 | } |
acodd | 3:4deb86f4ccfe | 111 | } |
acodd | 3:4deb86f4ccfe | 112 | |
acodd | 3:4deb86f4ccfe | 113 | if (ratiocalc) { |
acodd | 3:4deb86f4ccfe | 114 | ratiocalc = false; |
acodd | 3:4deb86f4ccfe | 115 | |
acodd | 3:4deb86f4ccfe | 116 | Pan.start_SysPos = Pan.System_position; |
acodd | 3:4deb86f4ccfe | 117 | Pan.start_MotPos = Pan.Motor_position; |
acodd | 3:4deb86f4ccfe | 118 | |
acodd | 3:4deb86f4ccfe | 119 | Pan.calcmyratio = true; |
acodd | 3:4deb86f4ccfe | 120 | |
acodd | 3:4deb86f4ccfe | 121 | Tilt.start_SysPos = Tilt.System_position; |
acodd | 3:4deb86f4ccfe | 122 | Tilt.start_MotPos = Tilt.Motor_position; |
acodd | 3:4deb86f4ccfe | 123 | |
acodd | 3:4deb86f4ccfe | 124 | Tilt.calcmyratio = true; |
acodd | 3:4deb86f4ccfe | 125 | } |
ms523 | 0:3a132f85c1a8 | 126 | } |
ms523 | 0:3a132f85c1a8 | 127 | |
ms523 | 0:3a132f85c1a8 | 128 | } |