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.
Dependencies: Classic_PID iC_MU mbed-rtos mbed
main.cpp@4:4dafa4113982, 2015-06-25 (annotated)
- Committer:
- acodd
- Date:
- Thu Jun 25 09:41:26 2015 +0000
- Revision:
- 4:4dafa4113982
- Parent:
- 3:f8a5c1cee1fa
Test Harness for a single axis
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
acodd | 4:4dafa4113982 | 1 | // For testing Tilt on an Aluminium unit. |
acodd | 2:dc684c402296 | 2 | // AC 19/05/2015. Based on MS NewMotorVelLoop |
acodd | 2:dc684c402296 | 3 | |
acodd | 2:dc684c402296 | 4 | |
ms523 | 0:7ce0bc67f60f | 5 | #include "mbed.h" |
ms523 | 0:7ce0bc67f60f | 6 | #include "iC_MU.h" |
ms523 | 0:7ce0bc67f60f | 7 | #include "rtos.h" |
ms523 | 0:7ce0bc67f60f | 8 | #include "Classic_PID.h" |
ms523 | 0:7ce0bc67f60f | 9 | |
ms523 | 0:7ce0bc67f60f | 10 | #define _Kp 0.18 // Kp.Freq product |
ms523 | 0:7ce0bc67f60f | 11 | #define _Ki 0.006 // Ki.Freq product |
ms523 | 0:7ce0bc67f60f | 12 | |
ms523 | 0:7ce0bc67f60f | 13 | Serial pc(USBTX,USBRX); |
ms523 | 0:7ce0bc67f60f | 14 | |
ms523 | 0:7ce0bc67f60f | 15 | // iC-MU Encoder Objects |
ms523 | 0:7ce0bc67f60f | 16 | iC_MU tilt_ic_mu(p5,p6,p7,p8); |
ms523 | 0:7ce0bc67f60f | 17 | iC_MU TiltPos(p5,p6,p7,p11); |
ms523 | 0:7ce0bc67f60f | 18 | iC_MU pan_ic_mu(p5,p6,p7,p12); |
ms523 | 0:7ce0bc67f60f | 19 | iC_MU PanPos(p5,p6,p7,p13); |
ms523 | 1:1ad84260ff59 | 20 | |
ms523 | 1:1ad84260ff59 | 21 | #ifdef TARGET_LPC4088 |
ms523 | 0:7ce0bc67f60f | 22 | // Tilt Motor |
ms523 | 0:7ce0bc67f60f | 23 | PwmOut Tilt_Motor_PWM(p27); // Purple wire |
ms523 | 0:7ce0bc67f60f | 24 | DigitalOut Tilt_Motor_Direction(p28); // Yellow wire |
ms523 | 0:7ce0bc67f60f | 25 | // Pan Motor |
ms523 | 0:7ce0bc67f60f | 26 | PwmOut Pan_Motor_PWM(p25); // Purple wire |
ms523 | 0:7ce0bc67f60f | 27 | DigitalOut Pan_Motor_Direction(p26); // Yellow wire |
ms523 | 1:1ad84260ff59 | 28 | #endif |
ms523 | 1:1ad84260ff59 | 29 | |
ms523 | 1:1ad84260ff59 | 30 | #ifdef TARGET_LPC1768 |
ms523 | 0:7ce0bc67f60f | 31 | // Tilt Motor |
ms523 | 0:7ce0bc67f60f | 32 | PwmOut Tilt_Motor_PWM(p23); // Purple wire |
ms523 | 0:7ce0bc67f60f | 33 | DigitalOut Tilt_Motor_Direction(p24); // Yellow wire |
ms523 | 0:7ce0bc67f60f | 34 | // Pan Motor |
ms523 | 0:7ce0bc67f60f | 35 | PwmOut Pan_Motor_PWM(p21); // Purple wire |
ms523 | 0:7ce0bc67f60f | 36 | DigitalOut Pan_Motor_Direction(p22); // Yellow wire |
acodd | 4:4dafa4113982 | 37 | // Button |
acodd | 4:4dafa4113982 | 38 | DigitalIn Fademe(p14); |
ms523 | 1:1ad84260ff59 | 39 | #endif |
ms523 | 0:7ce0bc67f60f | 40 | |
ms523 | 0:7ce0bc67f60f | 41 | // Joystick stuff |
ms523 | 0:7ce0bc67f60f | 42 | AnalogIn Pan_Joystick(p16); |
ms523 | 0:7ce0bc67f60f | 43 | AnalogIn Tilt_Joystick(p17); |
ms523 | 0:7ce0bc67f60f | 44 | AnalogIn Zoom_Joystick(p18); |
ms523 | 0:7ce0bc67f60f | 45 | AnalogIn Focus_Pot(p19); // The top Pot (Pot 1) |
acodd | 4:4dafa4113982 | 46 | AnalogIn Setspeed(p20); // The bottom Pot (Pot 2) |
ms523 | 0:7ce0bc67f60f | 47 | |
ms523 | 0:7ce0bc67f60f | 48 | // Camera Stuff |
ms523 | 0:7ce0bc67f60f | 49 | Serial Camera(p9,p10); |
ms523 | 0:7ce0bc67f60f | 50 | InterruptIn Switch(p14); |
ms523 | 1:1ad84260ff59 | 51 | #ifdef TARGET_LPC4088 |
ms523 | 1:1ad84260ff59 | 52 | DigitalOut led4(LED1),led2(LED2), led3(LED3), led1(LED4); |
ms523 | 1:1ad84260ff59 | 53 | #endif |
ms523 | 1:1ad84260ff59 | 54 | #ifdef TARGET_LPC1768 |
ms523 | 0:7ce0bc67f60f | 55 | DigitalOut led1(LED1),led2(LED2), led3(LED3), led4(LED4); |
ms523 | 1:1ad84260ff59 | 56 | #endif |
ms523 | 1:1ad84260ff59 | 57 | |
ms523 | 1:1ad84260ff59 | 58 | |
ms523 | 0:7ce0bc67f60f | 59 | #define AUTO 1 |
ms523 | 0:7ce0bc67f60f | 60 | #define MANUAL 0 |
ms523 | 0:7ce0bc67f60f | 61 | |
ms523 | 0:7ce0bc67f60f | 62 | /* Kp = 0.00018, Ki = 0.000006, Kd = 0.0, 0.0001 */ |
ms523 | 0:7ce0bc67f60f | 63 | Classic_PID PanVelocityPID(0.00018, 0.000006, 0.0, 0.0001); //Kp, ki, kd, kvelff |
acodd | 4:4dafa4113982 | 64 | Classic_PID TiltVelocityPID(4, 0.000000, 0.0, 1); //Kp, ki, kd, kvelff1 |
ms523 | 0:7ce0bc67f60f | 65 | |
ms523 | 0:7ce0bc67f60f | 66 | // Globals |
ms523 | 1:1ad84260ff59 | 67 | int ZoomPos = 10248; // Strat off at max Zoom position to avoid jerks on startup |
ms523 | 0:7ce0bc67f60f | 68 | bool AutofocusFlag = true; |
ms523 | 0:7ce0bc67f60f | 69 | bool ManualfocusFlag = false; |
ms523 | 0:7ce0bc67f60f | 70 | bool Mode = AUTO; |
acodd | 3:f8a5c1cee1fa | 71 | bool joystick = false; |
acodd | 2:dc684c402296 | 72 | bool scoping = false; |
ms523 | 0:7ce0bc67f60f | 73 | |
ms523 | 0:7ce0bc67f60f | 74 | extern int LastPanPosition; |
acodd | 3:f8a5c1cee1fa | 75 | extern int Last_M_Position; |
acodd | 2:dc684c402296 | 76 | float Pan_JoyStickDem = 0.8; |
acodd | 2:dc684c402296 | 77 | float Tilt_JoyStickDem = 0.8; |
acodd | 2:dc684c402296 | 78 | float Demand_Count_Rate = 0.0; |
acodd | 2:dc684c402296 | 79 | float Actual_Motor_Speed = 0.0; //counts/ms |
acodd | 2:dc684c402296 | 80 | float Velocity_Error = 0.0; // count/ms |
acodd | 2:dc684c402296 | 81 | float P_Error = 0.0; // degrees |
acodd | 2:dc684c402296 | 82 | extern float Tilt_motor_max_count_rate; //encoder counts / ms |
acodd | 2:dc684c402296 | 83 | |
acodd | 2:dc684c402296 | 84 | extern float T_Position; // True Tilt Position (Degrees) |
acodd | 3:f8a5c1cee1fa | 85 | extern float T_Encoder_sf; // counts per degree |
acodd | 2:dc684c402296 | 86 | extern int DoMove; |
acodd | 2:dc684c402296 | 87 | extern float s_profile; |
acodd | 2:dc684c402296 | 88 | extern float P_vel; |
acodd | 2:dc684c402296 | 89 | extern float real_time; |
acodd | 2:dc684c402296 | 90 | extern float T_Joy; |
acodd | 4:4dafa4113982 | 91 | float Joy_DeadBand = 15; |
acodd | 4:4dafa4113982 | 92 | float Joy_Zoom = 1; // valid numbers from 1 - 9 |
acodd | 2:dc684c402296 | 93 | float Time = 0.0; |
acodd | 4:4dafa4113982 | 94 | extern double P; |
ms523 | 0:7ce0bc67f60f | 95 | |
ms523 | 0:7ce0bc67f60f | 96 | void PanVelocityLoop(void const *args); |
ms523 | 0:7ce0bc67f60f | 97 | void TiltVelocityLoop(void const *args); |
acodd | 2:dc684c402296 | 98 | void Profile(void const *args); |
ms523 | 1:1ad84260ff59 | 99 | int ServiceKeyboard(); |
ms523 | 0:7ce0bc67f60f | 100 | void UpdateCamera(float, float); |
ms523 | 0:7ce0bc67f60f | 101 | |
ms523 | 0:7ce0bc67f60f | 102 | void isr_Switch(void) |
ms523 | 0:7ce0bc67f60f | 103 | { |
ms523 | 0:7ce0bc67f60f | 104 | wait_ms(1); // Wait 1ms and check if the switch is still pressed |
ms523 | 0:7ce0bc67f60f | 105 | if (Switch) { |
ms523 | 0:7ce0bc67f60f | 106 | wait_ms(1); // Wait another 1ms and double check the switch |
ms523 | 0:7ce0bc67f60f | 107 | if (Switch) { |
ms523 | 0:7ce0bc67f60f | 108 | Mode = !Mode; |
ms523 | 0:7ce0bc67f60f | 109 | if(Mode == AUTO) { |
ms523 | 0:7ce0bc67f60f | 110 | AutofocusFlag = true; |
ms523 | 0:7ce0bc67f60f | 111 | } else { |
ms523 | 0:7ce0bc67f60f | 112 | ManualfocusFlag = true; |
ms523 | 0:7ce0bc67f60f | 113 | } |
ms523 | 0:7ce0bc67f60f | 114 | } |
ms523 | 0:7ce0bc67f60f | 115 | } |
ms523 | 1:1ad84260ff59 | 116 | } |
ms523 | 0:7ce0bc67f60f | 117 | |
ms523 | 0:7ce0bc67f60f | 118 | void Anti_Lock(void const *args) |
ms523 | 0:7ce0bc67f60f | 119 | { |
ms523 | 0:7ce0bc67f60f | 120 | Pan_Motor_Direction = !Pan_Motor_Direction.read(); // Toggle motor direction to overcome lock protection |
ms523 | 0:7ce0bc67f60f | 121 | Tilt_Motor_Direction = !Tilt_Motor_Direction.read(); |
ms523 | 0:7ce0bc67f60f | 122 | wait_us(10); |
ms523 | 0:7ce0bc67f60f | 123 | Pan_Motor_Direction = !Pan_Motor_Direction.read(); |
ms523 | 0:7ce0bc67f60f | 124 | Tilt_Motor_Direction = !Tilt_Motor_Direction.read(); |
ms523 | 0:7ce0bc67f60f | 125 | } |
ms523 | 0:7ce0bc67f60f | 126 | |
ms523 | 1:1ad84260ff59 | 127 | |
ms523 | 1:1ad84260ff59 | 128 | // IRQ for Rx camera interrupt |
ms523 | 1:1ad84260ff59 | 129 | void UART3_rxInterrupt(void) |
ms523 | 1:1ad84260ff59 | 130 | { |
ms523 | 1:1ad84260ff59 | 131 | // Create an array to read the whole message |
ms523 | 1:1ad84260ff59 | 132 | static int index = 0; |
ms523 | 1:1ad84260ff59 | 133 | static char msg[8] = {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}; |
ms523 | 1:1ad84260ff59 | 134 | |
ms523 | 1:1ad84260ff59 | 135 | NVIC_DisableIRQ(UART3_IRQn); // Disable the interrupt |
ms523 | 1:1ad84260ff59 | 136 | uint32_t IRR3 = LPC_UART3->IIR; |
ms523 | 1:1ad84260ff59 | 137 | msg[index] = LPC_UART3->RBR; // Read the byte and put it into the next available element of the array |
ms523 | 1:1ad84260ff59 | 138 | |
ms523 | 1:1ad84260ff59 | 139 | // Check to see if that is the end of the message |
ms523 | 1:1ad84260ff59 | 140 | if(msg[index] == 0xFF) { |
ms523 | 1:1ad84260ff59 | 141 | // Check to see if the response is zoom data i.e. 7 bytes long and starts with 0x90, 0x50... |
ms523 | 1:1ad84260ff59 | 142 | if(index == 6 && msg[0] == 0x90 && msg[1] == 0x50) { |
ms523 | 1:1ad84260ff59 | 143 | ZoomPos = (msg[2] & 0x0F) << 12; |
ms523 | 1:1ad84260ff59 | 144 | ZoomPos += (msg[3] & 0x0F) << 8; |
ms523 | 1:1ad84260ff59 | 145 | ZoomPos += (msg[4] & 0x0F) << 4; |
ms523 | 1:1ad84260ff59 | 146 | ZoomPos += (msg[5] & 0x0F); |
ms523 | 1:1ad84260ff59 | 147 | } |
ms523 | 1:1ad84260ff59 | 148 | index = 0; |
ms523 | 1:1ad84260ff59 | 149 | } else { |
ms523 | 1:1ad84260ff59 | 150 | index++; |
ms523 | 1:1ad84260ff59 | 151 | } |
ms523 | 1:1ad84260ff59 | 152 | |
ms523 | 1:1ad84260ff59 | 153 | led3 = !led3; // Flash the LED |
ms523 | 1:1ad84260ff59 | 154 | NVIC_EnableIRQ(UART3_IRQn); // Enable the interrupt again |
ms523 | 1:1ad84260ff59 | 155 | } |
ms523 | 1:1ad84260ff59 | 156 | |
ms523 | 0:7ce0bc67f60f | 157 | int main() |
ms523 | 0:7ce0bc67f60f | 158 | { |
ms523 | 0:7ce0bc67f60f | 159 | // Increase the Camera baud rate |
ms523 | 0:7ce0bc67f60f | 160 | Camera.baud(38400); |
ms523 | 1:1ad84260ff59 | 161 | |
ms523 | 1:1ad84260ff59 | 162 | // Set up the Camera Rx Interrupt |
ms523 | 1:1ad84260ff59 | 163 | Camera.attach(&UART3_rxInterrupt,Serial::RxIrq); |
ms523 | 0:7ce0bc67f60f | 164 | |
ms523 | 0:7ce0bc67f60f | 165 | // Set up the switch to toggle autofocus |
ms523 | 0:7ce0bc67f60f | 166 | Switch.mode(PullDown); //Set the internal pull down resistor |
ms523 | 0:7ce0bc67f60f | 167 | Switch.rise(&isr_Switch); //ISR for the switch |
ms523 | 0:7ce0bc67f60f | 168 | led4 = 1; // We start in autofocus mode |
ms523 | 0:7ce0bc67f60f | 169 | led1 = 1; // Turn all other LEDs off |
ms523 | 0:7ce0bc67f60f | 170 | led2 = 1; |
ms523 | 0:7ce0bc67f60f | 171 | led3 = 0; |
ms523 | 1:1ad84260ff59 | 172 | |
ms523 | 0:7ce0bc67f60f | 173 | // Set up the Pan motor |
ms523 | 0:7ce0bc67f60f | 174 | Pan_Motor_PWM.period_us(50); // Set PWM to 20 kHz |
ms523 | 0:7ce0bc67f60f | 175 | Pan_Motor_PWM = 1; // Start with motor static |
ms523 | 0:7ce0bc67f60f | 176 | |
ms523 | 0:7ce0bc67f60f | 177 | // Set up the Tilt motor |
ms523 | 0:7ce0bc67f60f | 178 | Tilt_Motor_PWM.period_us(50); // Set PWM to 20 kHz |
ms523 | 0:7ce0bc67f60f | 179 | Tilt_Motor_PWM = 1; // Start with motor static |
ms523 | 0:7ce0bc67f60f | 180 | |
ms523 | 0:7ce0bc67f60f | 181 | // Initalise Pan Velocity loop RtosTimer thread |
ms523 | 0:7ce0bc67f60f | 182 | RtosTimer PanVelocityLoop_timer(PanVelocityLoop, osTimerPeriodic); |
ms523 | 0:7ce0bc67f60f | 183 | PanVelocityLoop_timer.start(1); // Run at 1kHz |
ms523 | 0:7ce0bc67f60f | 184 | |
ms523 | 0:7ce0bc67f60f | 185 | // Initalise Tilt Velocity loop RtosTimer thread |
ms523 | 0:7ce0bc67f60f | 186 | RtosTimer TiltVelocityLoop_timer(TiltVelocityLoop, osTimerPeriodic); |
ms523 | 0:7ce0bc67f60f | 187 | TiltVelocityLoop_timer.start(1); // Run at 1kHz |
ms523 | 0:7ce0bc67f60f | 188 | |
ms523 | 0:7ce0bc67f60f | 189 | // Initalise Pan PID Loop |
ms523 | 0:7ce0bc67f60f | 190 | PanVelocityPID.setProcessLimits(1.0, -1.0); |
ms523 | 0:7ce0bc67f60f | 191 | PanVelocityPID.setSetPoint(0); |
ms523 | 0:7ce0bc67f60f | 192 | LastPanPosition = pan_ic_mu.ReadPOSITION() >> 1; |
ms523 | 0:7ce0bc67f60f | 193 | |
ms523 | 0:7ce0bc67f60f | 194 | // Initalise Tilt PID Loop |
acodd | 2:dc684c402296 | 195 | TiltVelocityPID.setProcessLimits(Tilt_motor_max_count_rate, (Tilt_motor_max_count_rate*-1)); |
ms523 | 0:7ce0bc67f60f | 196 | TiltVelocityPID.setSetPoint(0); |
acodd | 3:f8a5c1cee1fa | 197 | Last_M_Position = tilt_ic_mu.ReadPOSITION() >> 1; |
ms523 | 0:7ce0bc67f60f | 198 | |
ms523 | 0:7ce0bc67f60f | 199 | // Initalise Anti-Lock RtosTimer thread |
ms523 | 0:7ce0bc67f60f | 200 | RtosTimer Anti_Lock_timer(Anti_Lock, osTimerPeriodic); |
ms523 | 0:7ce0bc67f60f | 201 | Anti_Lock_timer.start(1000); // Run at 1Hz |
acodd | 2:dc684c402296 | 202 | |
acodd | 2:dc684c402296 | 203 | pc.baud(921600); |
acodd | 4:4dafa4113982 | 204 | |
acodd | 3:f8a5c1cee1fa | 205 | T_Position = 360 - (TiltPos.ReadPOSITION()/T_Encoder_sf); // Prime the system on startup, this is not used once running. |
acodd | 2:dc684c402296 | 206 | P = T_Position; // Priming |
acodd | 2:dc684c402296 | 207 | pc.printf("\n\r Startup: T_Position = %f, P = %f, \n\r", T_Position, P); |
acodd | 4:4dafa4113982 | 208 | |
ms523 | 0:7ce0bc67f60f | 209 | while(1) { |
ms523 | 1:1ad84260ff59 | 210 | // Check to see if a key has been pressed |
ms523 | 1:1ad84260ff59 | 211 | if(pc.readable()) { |
ms523 | 1:1ad84260ff59 | 212 | ServiceKeyboard(); |
ms523 | 1:1ad84260ff59 | 213 | } |
acodd | 3:f8a5c1cee1fa | 214 | //T_Position = TiltPos.ReadPOSITION()/T_Encoder_sf; |
acodd | 2:dc684c402296 | 215 | Demand_Count_Rate = TiltVelocityPID.getSetPoint(); |
acodd | 2:dc684c402296 | 216 | |
acodd | 2:dc684c402296 | 217 | if(1==0) { |
acodd | 2:dc684c402296 | 218 | Velocity_Error = Demand_Count_Rate - Actual_Motor_Speed; |
acodd | 2:dc684c402296 | 219 | pc.printf("\n\r Demand Ms = %f, V Error = %f, Pos = %f, Demand P = %f",Demand_Count_Rate, Velocity_Error, T_Position, P); |
acodd | 2:dc684c402296 | 220 | } |
acodd | 4:4dafa4113982 | 221 | |
acodd | 4:4dafa4113982 | 222 | if(scoping) { |
acodd | 4:4dafa4113982 | 223 | P_Error = P - T_Position; |
acodd | 4:4dafa4113982 | 224 | pc.printf("\n\r %f, %f, %f, %f, %f, %f, %f, %f", Time, Tilt_JoyStickDem, P_Error, T_Position, P, Actual_Motor_Speed, s_profile, real_time); |
acodd | 4:4dafa4113982 | 225 | Time = Time + 0.1; |
acodd | 2:dc684c402296 | 226 | } |
acodd | 2:dc684c402296 | 227 | |
acodd | 4:4dafa4113982 | 228 | Thread::wait(50); |
acodd | 4:4dafa4113982 | 229 | |
acodd | 4:4dafa4113982 | 230 | |
acodd | 4:4dafa4113982 | 231 | if (Fademe){ |
acodd | 4:4dafa4113982 | 232 | pc.printf("\n\r %i, %f", Setspeed.read(), Setspeed.read()); |
acodd | 4:4dafa4113982 | 233 | } |
acodd | 4:4dafa4113982 | 234 | |
acodd | 4:4dafa4113982 | 235 | |
acodd | 4:4dafa4113982 | 236 | |
acodd | 4:4dafa4113982 | 237 | //Update the Zoom and Focus Demands |
acodd | 4:4dafa4113982 | 238 | UpdateCamera(Zoom_Joystick.read(),Focus_Pot.read()); |
acodd | 2:dc684c402296 | 239 | |
ms523 | 1:1ad84260ff59 | 240 | //pc.printf("\n\r %d ",tiltPosition); |
acodd | 4:4dafa4113982 | 241 | Thread::wait(50); |
acodd | 2:dc684c402296 | 242 | |
ms523 | 1:1ad84260ff59 | 243 | |
acodd | 2:dc684c402296 | 244 | // Apply Offset |
acodd | 4:4dafa4113982 | 245 | Tilt_JoyStickDem = Setspeed.read() - 0.5; //Tilt_Joystick.read() - 0.5; |
acodd | 4:4dafa4113982 | 246 | Tilt_JoyStickDem = Tilt_JoyStickDem; |
acodd | 4:4dafa4113982 | 247 | |
acodd | 4:4dafa4113982 | 248 | Tilt_JoyStickDem /= (ZoomPos >> 9) + 1; // Catch divide by zeros |
acodd | 4:4dafa4113982 | 249 | |
acodd | 4:4dafa4113982 | 250 | Tilt_JoyStickDem *= 10000; // Apply scalefactor |
acodd | 4:4dafa4113982 | 251 | |
acodd | 4:4dafa4113982 | 252 | if ((Tilt_JoyStickDem * Tilt_JoyStickDem) < (Joy_DeadBand * Joy_DeadBand)) { |
acodd | 4:4dafa4113982 | 253 | Tilt_JoyStickDem = 0; //Apply Deadband |
acodd | 2:dc684c402296 | 254 | } |
acodd | 2:dc684c402296 | 255 | |
acodd | 4:4dafa4113982 | 256 | if(Tilt_JoyStickDem > 0) { |
acodd | 4:4dafa4113982 | 257 | // Check the tilt angle to see if it is within softlimits |
acodd | 4:4dafa4113982 | 258 | if(T_Position > 310) { |
acodd | 4:4dafa4113982 | 259 | Tilt_JoyStickDem = 0.0; |
acodd | 4:4dafa4113982 | 260 | } |
acodd | 4:4dafa4113982 | 261 | } else { |
acodd | 4:4dafa4113982 | 262 | // Check the tilt angle to see if it is within softlimits |
acodd | 4:4dafa4113982 | 263 | if(T_Position < 40) { |
acodd | 4:4dafa4113982 | 264 | Tilt_JoyStickDem = 0.0; |
acodd | 4:4dafa4113982 | 265 | } |
acodd | 4:4dafa4113982 | 266 | } |
acodd | 2:dc684c402296 | 267 | |
acodd | 4:4dafa4113982 | 268 | |
acodd | 2:dc684c402296 | 269 | Tilt_JoyStickDem = Tilt_JoyStickDem / Joy_Zoom; |
acodd | 4:4dafa4113982 | 270 | |
ms523 | 0:7ce0bc67f60f | 271 | if(joystick) { |
ms523 | 1:1ad84260ff59 | 272 | TiltVelocityPID.setSetPoint((int)Tilt_JoyStickDem); // Read the joystick and apply the gain |
acodd | 2:dc684c402296 | 273 | } else { |
acodd | 2:dc684c402296 | 274 | |
acodd | 4:4dafa4113982 | 275 | T_Joy = Tilt_JoyStickDem / 40; |
ms523 | 1:1ad84260ff59 | 276 | } |
ms523 | 1:1ad84260ff59 | 277 | |
ms523 | 0:7ce0bc67f60f | 278 | if(AutofocusFlag) { |
ms523 | 0:7ce0bc67f60f | 279 | // Turn on the autofocus |
ms523 | 1:1ad84260ff59 | 280 | led1 = 1; // Turn the LED on to show we are in auto-focus mode |
ms523 | 0:7ce0bc67f60f | 281 | Camera.putc(0x81); // Camera |
ms523 | 0:7ce0bc67f60f | 282 | Camera.putc(0x01); // Turn on auto-focus cmd |
ms523 | 0:7ce0bc67f60f | 283 | Camera.putc(0x04); |
ms523 | 0:7ce0bc67f60f | 284 | Camera.putc(0x38); |
ms523 | 0:7ce0bc67f60f | 285 | Camera.putc(0x02); |
ms523 | 0:7ce0bc67f60f | 286 | Camera.putc(0xFF); // Terminator |
ms523 | 0:7ce0bc67f60f | 287 | AutofocusFlag = false; |
ms523 | 0:7ce0bc67f60f | 288 | Mode = AUTO; |
ms523 | 0:7ce0bc67f60f | 289 | } |
ms523 | 0:7ce0bc67f60f | 290 | if(ManualfocusFlag) { |
ms523 | 0:7ce0bc67f60f | 291 | // Turn on Manual focus |
ms523 | 1:1ad84260ff59 | 292 | led1 = 0; // Turn the LED off to show we are in manual-focus mode |
ms523 | 0:7ce0bc67f60f | 293 | Camera.putc(0x81); // Camera |
ms523 | 0:7ce0bc67f60f | 294 | Camera.putc(0x01); // Turn on manual-focus cmd |
ms523 | 0:7ce0bc67f60f | 295 | Camera.putc(0x04); |
ms523 | 0:7ce0bc67f60f | 296 | Camera.putc(0x38); |
ms523 | 0:7ce0bc67f60f | 297 | Camera.putc(0x03); |
ms523 | 0:7ce0bc67f60f | 298 | Camera.putc(0xFF); // Terminator |
ms523 | 0:7ce0bc67f60f | 299 | ManualfocusFlag = false; |
ms523 | 0:7ce0bc67f60f | 300 | Mode = MANUAL; |
ms523 | 1:1ad84260ff59 | 301 | } |
ms523 | 0:7ce0bc67f60f | 302 | } |
ms523 | 0:7ce0bc67f60f | 303 | } |
ms523 | 0:7ce0bc67f60f | 304 | |
ms523 | 1:1ad84260ff59 | 305 | /* |
ms523 | 1:1ad84260ff59 | 306 | // Increase the serial baud rate |
ms523 | 1:1ad84260ff59 | 307 | // pc.baud(921600); |
ms523 | 0:7ce0bc67f60f | 308 | |
ms523 | 1:1ad84260ff59 | 309 | while(1) { |
ms523 | 1:1ad84260ff59 | 310 | Thread::wait(100); |
ms523 | 0:7ce0bc67f60f | 311 | |
ms523 | 1:1ad84260ff59 | 312 | if(pc.readable()) { |
ms523 | 1:1ad84260ff59 | 313 | ServiceKeyboard(); |
ms523 | 1:1ad84260ff59 | 314 | } |
ms523 | 1:1ad84260ff59 | 315 | |
ms523 | 1:1ad84260ff59 | 316 | if(Demand) { |
ms523 | 1:1ad84260ff59 | 317 | pc.printf("\n\r %0.3f ",PanVelocityPID.getSetPoint()); |
ms523 | 1:1ad84260ff59 | 318 | } |
ms523 | 1:1ad84260ff59 | 319 | } |
ms523 | 0:7ce0bc67f60f | 320 | }*/ |
acodd | 2:dc684c402296 | 321 | |
acodd | 2:dc684c402296 | 322 | |
acodd | 2:dc684c402296 | 323 | |
acodd | 4:4dafa4113982 | 324 | |
acodd | 4:4dafa4113982 | 325 |