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
ServiceKeyboard.cpp
00001 #include "mbed.h" 00002 #include "iC_MU.h" 00003 #include "rtos.h" 00004 #include "Classic_PID.h" 00005 00006 extern Serial pc; 00007 extern Classic_PID PanVelocityPID; 00008 extern Classic_PID TiltVelocityPID; 00009 void Profile(void); 00010 extern float Demand_Count_Rate; 00011 00012 extern bool joystick; 00013 extern bool scoping; 00014 00015 extern float fade_tilt; 00016 extern float fade_time; 00017 extern float D; 00018 extern float T; 00019 extern float ts; 00020 extern int DoMove; 00021 extern float T_Position; 00022 extern float T_Kp; 00023 extern float Vff; 00024 float setting; 00025 extern float Time; 00026 00027 extern float Joy_Zoom; 00028 00029 extern double drive; 00030 00031 // Returns the new set point entered via the keyboard 00032 int ServiceKeyboard () 00033 { 00034 int key; // The keypress by the user 00035 int value = 0; // The variable to return 00036 00037 key = pc.getc(); // Read the intial keypress 00038 00039 switch (key) { 00040 // List keypresses used: 00041 case 'q': 00042 pc.printf("\n\r Toggle joystick = j \n\r Scope = s \n\r Fade = f \n\r Stop = c \n\r Set POS gains k, v, \n\r Set Vel Vff, kp: l, m \n\r Set fade time: t \n\r Save Shot = 1"); 00043 pc.printf("\n\r Zoom Value (1-10) = z \n\r Drive const speed = d"); 00044 break; 00045 // Save a shot position: 00046 case '1': 00047 00048 fade_tilt = T_Position; 00049 pc.printf("\n\r Saving this postion as %f", fade_tilt); 00050 break; 00051 // Switch Joystick Mode on and off 00052 case 'j': 00053 joystick = !joystick; 00054 if(joystick) { 00055 pc.printf("\n\r Under Joystick Control"); 00056 } else { 00057 // Stop both axes 00058 //PanVelocityPID.setSetPoint(0); 00059 //TiltVelocityPID.setSetPoint(0); 00060 pc.printf("\n\r Under Full Profiler Control"); 00061 pc.printf("\n\r"); 00062 } 00063 break; 00064 // Turn on Scope Tool: 00065 case 's': 00066 if (!scoping) { 00067 Time = 0; 00068 pc.printf("\n\r Time, Tilt_JoyStickDem, P_Error, T_Position, P, Motor_Speed, Demand_Speed"); 00069 00070 scoping = true; 00071 } else { 00072 scoping = false; 00073 } 00074 00075 break; 00076 // Calling A Fade: 00077 case 'f': 00078 if (DoMove == 0) { 00079 //fade_time = 15; 00080 Profile(); 00081 pc.printf("\n\r Fade Distance: %f", D); 00082 pc.printf("\n\r Fade Time = %f, Ramp segment = %f",T, ts); 00083 DoMove = 1; 00084 } 00085 break; 00086 // We are going to set the fade time... 00087 case 't': 00088 pc.printf("\n\r New Fade Time: "); 00089 key = pc.getc(); 00090 do { 00091 key = pc.getc(); // Wait for a keypress 00092 if(key >= '0' && key <= '9') { // Check it is a number 00093 value *= 10; // Index the old number 00094 value += (key - '0'); // Add on the new number 00095 pc.printf("%c",key); // Display the new number 00096 } 00097 } while(key != 0x0D); 00098 setting = value; 00099 fade_time = (setting); 00100 pc.printf("\n\r"); 00101 break; 00102 // Stop a fade 00103 case 'c': 00104 if (DoMove == 1) { 00105 pc.printf("\n\r Fade Stop"); 00106 DoMove = 0; 00107 //TiltVelocityPID.setSetPoint(0); 00108 } 00109 break; 00110 // Set Tilt Kp 00111 case 'k': 00112 pc.printf("\n\r New Tilt Pos Kp (Multiply by 100): "); 00113 key = pc.getc(); 00114 do { 00115 key = pc.getc(); // Wait for a keypress 00116 if(key >= '0' && key <= '9') { // Check it is a number 00117 value *= 10; // Index the old number 00118 value += (key - '0'); // Add on the new number 00119 pc.printf("%c",key); // Display the new number 00120 } 00121 } while(key != 0x0D); 00122 setting = value; 00123 T_Kp = (setting/100); 00124 //TiltVelocityPID.setKp(value); 00125 pc.printf("\n\r"); 00126 break; 00127 // We are going to set Pos Feedforward gain for tilt... 00128 case 'v': 00129 pc.printf("\n\r New Tilt Pos Vff (Multiply by 100): "); 00130 key = pc.getc(); 00131 do { 00132 key = pc.getc(); // Wait for a keypress 00133 if(key >= '0' && key <= '9') { // Check it is a number 00134 value *= 10; // Index the old number 00135 value += (key - '0'); // Add on the new number 00136 pc.printf("%c",key); // Display the new number 00137 } 00138 } while(key != 0x0D); 00139 setting = value; 00140 Vff = (setting/100); 00141 pc.printf("\n\r"); 00142 break; 00143 // We are going to set Kvelff gain for tilt... 00144 case 'l': 00145 pc.printf("\n\r New Tilt Velocity Vff (Multiply by 100): "); 00146 key = pc.getc(); 00147 do { 00148 key = pc.getc(); // Wait for a keypress 00149 if(key >= '0' && key <= '9') { // Check it is a number 00150 value *= 10; // Index the old number 00151 value += (key - '0'); // Add on the new number 00152 pc.printf("%c",key); // Display the new number 00153 } 00154 } while(key != 0x0D); 00155 setting = value; 00156 TiltVelocityPID.setKvelff(setting/100); 00157 pc.printf("\n\r"); 00158 break; 00159 // Set Tilt Velocity Kp 00160 case 'm': 00161 pc.printf("\n\r New Tilt Velocity Kp (Multiply by 100): "); 00162 key = pc.getc(); 00163 do { 00164 key = pc.getc(); // Wait for a keypress 00165 if(key >= '0' && key <= '9') { // Check it is a number 00166 value *= 10; // Index the old number 00167 value += (key - '0'); // Add on the new number 00168 pc.printf("%c",key); // Display the new number 00169 } 00170 } while(key != 0x0D); 00171 setting = value; 00172 TiltVelocityPID.setKp(setting/100); 00173 pc.printf("\n\r"); 00174 break; 00175 // Set Zoom level for Zoom proportional 00176 case 'z': 00177 pc.printf("\n\r Set Zoom Scalar Low 1-9 High): "); 00178 key = pc.getc(); 00179 do { 00180 key = pc.getc(); // Wait for a keypress 00181 if(key >= '0' && key <= '9') { // Check it is a number 00182 value *= 10; // Index the old number 00183 value += (key - '0'); // Add on the new number 00184 pc.printf("%c",key); // Display the new number 00185 } 00186 } while(key != 0x0D); 00187 setting = value; 00188 Joy_Zoom = (setting); 00189 pc.printf("\n\r"); 00190 break; 00191 // We are going to set Pos Feedforward gain for tilt... 00192 case 'd': 00193 pc.printf("\n\r Drive const speed (Multiply by 100): "); 00194 key = pc.getc(); 00195 do { 00196 key = pc.getc(); // Wait for a keypress 00197 if(key >= '0' && key <= '9') { // Check it is a number 00198 value *= 10; // Index the old number 00199 value += (key - '0'); // Add on the new number 00200 pc.printf("%c",key); // Display the new number 00201 } 00202 } while(key != 0x0D); 00203 setting = value; 00204 drive = setting; 00205 pc.printf("\n\r New Speed is = %f", (drive/100)); 00206 break; 00207 } 00208 return(1); 00209 } 00210 00211 00212 00213 00214 00215
Generated on Wed Nov 16 2022 12:14:25 by
1.7.2