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@1:1ad84260ff59, 2015-05-18 (annotated)
- Committer:
- ms523
- Date:
- Mon May 18 09:06:07 2015 +0000
- Revision:
- 1:1ad84260ff59
- Parent:
- 0:7ce0bc67f60f
- Child:
- 2:dc684c402296
current latest code - not revision controlled
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| ms523 | 0:7ce0bc67f60f | 1 | #include "mbed.h" |
| ms523 | 0:7ce0bc67f60f | 2 | #include "iC_MU.h" |
| ms523 | 0:7ce0bc67f60f | 3 | #include "rtos.h" |
| ms523 | 0:7ce0bc67f60f | 4 | #include "Classic_PID.h" |
| ms523 | 0:7ce0bc67f60f | 5 | |
| ms523 | 0:7ce0bc67f60f | 6 | extern Serial pc; |
| ms523 | 0:7ce0bc67f60f | 7 | extern Classic_PID PanVelocityPID; |
| ms523 | 0:7ce0bc67f60f | 8 | extern Classic_PID TiltVelocityPID; |
| ms523 | 0:7ce0bc67f60f | 9 | |
| ms523 | 0:7ce0bc67f60f | 10 | extern bool joystick; |
| ms523 | 0:7ce0bc67f60f | 11 | |
| ms523 | 0:7ce0bc67f60f | 12 | // Returns the new set point entered via the keyboard |
| ms523 | 0:7ce0bc67f60f | 13 | int ServiceKeyboard () |
| ms523 | 0:7ce0bc67f60f | 14 | { |
| ms523 | 0:7ce0bc67f60f | 15 | int key; // The keypress by the user |
| ms523 | 0:7ce0bc67f60f | 16 | int value = 0; // The variable to return |
| ms523 | 0:7ce0bc67f60f | 17 | |
| ms523 | 0:7ce0bc67f60f | 18 | key = pc.getc(); // Read the intial keypress |
| ms523 | 0:7ce0bc67f60f | 19 | |
| ms523 | 0:7ce0bc67f60f | 20 | if (key == 'j') { |
| ms523 | 0:7ce0bc67f60f | 21 | joystick = !joystick; |
| ms523 | 0:7ce0bc67f60f | 22 | if(joystick) { |
| ms523 | 1:1ad84260ff59 | 23 | pc.printf("\n\r Under Joystick Control"); |
| ms523 | 0:7ce0bc67f60f | 24 | } else { |
| ms523 | 1:1ad84260ff59 | 25 | // Stop both axes |
| ms523 | 1:1ad84260ff59 | 26 | PanVelocityPID.setSetPoint(0); |
| ms523 | 1:1ad84260ff59 | 27 | TiltVelocityPID.setSetPoint(0); |
| ms523 | 1:1ad84260ff59 | 28 | pc.printf("\n\r Under PC Control"); |
| ms523 | 0:7ce0bc67f60f | 29 | } |
| ms523 | 0:7ce0bc67f60f | 30 | } |
| ms523 | 0:7ce0bc67f60f | 31 | // Set Velocity for Pan and Tilt here... |
| ms523 | 0:7ce0bc67f60f | 32 | else if(key == 'p') { |
| ms523 | 0:7ce0bc67f60f | 33 | // We are going to set the speed of pan... |
| ms523 | 0:7ce0bc67f60f | 34 | pc.printf("\n\r New Pan Vel: "); |
| ms523 | 0:7ce0bc67f60f | 35 | key = pc.getc(); |
| ms523 | 0:7ce0bc67f60f | 36 | if (key == 0x1B) { |
| ms523 | 0:7ce0bc67f60f | 37 | if(pc.getc() == 0x4F) { |
| ms523 | 0:7ce0bc67f60f | 38 | if(pc.getc() == 0x53) { |
| ms523 | 0:7ce0bc67f60f | 39 | pc.printf("-"); |
| ms523 | 0:7ce0bc67f60f | 40 | do { |
| ms523 | 0:7ce0bc67f60f | 41 | key = pc.getc(); // Wait for a keypress |
| ms523 | 0:7ce0bc67f60f | 42 | if(key >= '0' && key <= '9') { // Check it is a number |
| ms523 | 0:7ce0bc67f60f | 43 | value *= 10; // Index the old number |
| ms523 | 0:7ce0bc67f60f | 44 | value += (key - '0'); // Add on the new number |
| ms523 | 0:7ce0bc67f60f | 45 | pc.printf("%c",key); // Display the new number |
| ms523 | 0:7ce0bc67f60f | 46 | } |
| ms523 | 0:7ce0bc67f60f | 47 | } while(key != 0x0D); |
| ms523 | 0:7ce0bc67f60f | 48 | PanVelocityPID.setSetPoint(value * -1); |
| ms523 | 0:7ce0bc67f60f | 49 | } |
| ms523 | 0:7ce0bc67f60f | 50 | } |
| ms523 | 0:7ce0bc67f60f | 51 | } else if(key >= '0' && key <= '9') { // Check it is a number |
| ms523 | 0:7ce0bc67f60f | 52 | pc.printf("%c",key); |
| ms523 | 0:7ce0bc67f60f | 53 | value = (key - '0'); |
| ms523 | 0:7ce0bc67f60f | 54 | do { |
| ms523 | 0:7ce0bc67f60f | 55 | key = pc.getc(); // Wait for a keypress |
| ms523 | 0:7ce0bc67f60f | 56 | if(key >= '0' && key <= '9') { // Check it is a number |
| ms523 | 0:7ce0bc67f60f | 57 | value *= 10; // Index the old number |
| ms523 | 0:7ce0bc67f60f | 58 | value += (key - '0'); // Add on the new number |
| ms523 | 0:7ce0bc67f60f | 59 | pc.printf("%c",key); // Display the new number |
| ms523 | 0:7ce0bc67f60f | 60 | } |
| ms523 | 0:7ce0bc67f60f | 61 | } while(key != 0x0D); |
| ms523 | 0:7ce0bc67f60f | 62 | PanVelocityPID.setSetPoint(value); |
| ms523 | 0:7ce0bc67f60f | 63 | } |
| ms523 | 0:7ce0bc67f60f | 64 | } else if(key == 't') { |
| ms523 | 0:7ce0bc67f60f | 65 | // We are going to set the speed of tilt... |
| ms523 | 0:7ce0bc67f60f | 66 | pc.printf("\n\r New Tilt Vel: "); |
| ms523 | 0:7ce0bc67f60f | 67 | key = pc.getc(); |
| ms523 | 0:7ce0bc67f60f | 68 | if (key == 0x1B) { |
| ms523 | 0:7ce0bc67f60f | 69 | if(pc.getc() == 0x4F) { |
| ms523 | 0:7ce0bc67f60f | 70 | if(pc.getc() == 0x53) { |
| ms523 | 0:7ce0bc67f60f | 71 | pc.printf("-"); |
| ms523 | 0:7ce0bc67f60f | 72 | do { |
| ms523 | 0:7ce0bc67f60f | 73 | key = pc.getc(); // Wait for a keypress |
| ms523 | 0:7ce0bc67f60f | 74 | if(key >= '0' && key <= '9') { // Check it is a number |
| ms523 | 0:7ce0bc67f60f | 75 | value *= 10; // Index the old number |
| ms523 | 0:7ce0bc67f60f | 76 | value += (key - '0'); // Add on the new number |
| ms523 | 0:7ce0bc67f60f | 77 | pc.printf("%c",key); // Display the new number |
| ms523 | 0:7ce0bc67f60f | 78 | } |
| ms523 | 0:7ce0bc67f60f | 79 | } while(key != 0x0D); |
| ms523 | 0:7ce0bc67f60f | 80 | TiltVelocityPID.setSetPoint(value * -1); |
| ms523 | 0:7ce0bc67f60f | 81 | } |
| ms523 | 0:7ce0bc67f60f | 82 | } |
| ms523 | 0:7ce0bc67f60f | 83 | } else if(key >= '0' && key <= '9') { // Check it is a number |
| ms523 | 0:7ce0bc67f60f | 84 | pc.printf("%c",key); |
| ms523 | 0:7ce0bc67f60f | 85 | value = (key - '0'); |
| ms523 | 0:7ce0bc67f60f | 86 | do { |
| ms523 | 0:7ce0bc67f60f | 87 | key = pc.getc(); // Wait for a keypress |
| ms523 | 0:7ce0bc67f60f | 88 | if(key >= '0' && key <= '9') { // Check it is a number |
| ms523 | 0:7ce0bc67f60f | 89 | value *= 10; // Index the old number |
| ms523 | 0:7ce0bc67f60f | 90 | value += (key - '0'); // Add on the new number |
| ms523 | 0:7ce0bc67f60f | 91 | pc.printf("%c",key); // Display the new number |
| ms523 | 0:7ce0bc67f60f | 92 | } |
| ms523 | 0:7ce0bc67f60f | 93 | } while(key != 0x0D); |
| ms523 | 0:7ce0bc67f60f | 94 | TiltVelocityPID.setSetPoint(value); |
| ms523 | 0:7ce0bc67f60f | 95 | } |
| ms523 | 0:7ce0bc67f60f | 96 | } |
| ms523 | 0:7ce0bc67f60f | 97 | return(1); |
| ms523 | 1:1ad84260ff59 | 98 | } |