Servo Calibration with Max and Min calibration pionts
Fork of ServoProgram by
main.cpp@2:1397177768c3, 2012-11-09 (annotated)
- Committer:
- tylerjw
- Date:
- Fri Nov 09 19:58:09 2012 +0000
- Revision:
- 2:1397177768c3
- Parent:
- 1:e3c15c192f3d
working test
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tylerjw | 1:e3c15c192f3d | 1 | #include "mbed.h" |
tylerjw | 1:e3c15c192f3d | 2 | #include "Servo.h" |
tylerjw | 1:e3c15c192f3d | 3 | |
tylerjw | 1:e3c15c192f3d | 4 | Servo myservo(p23); |
tylerjw | 1:e3c15c192f3d | 5 | Serial pc(USBTX, USBRX); |
tylerjw | 1:e3c15c192f3d | 6 | |
tylerjw | 1:e3c15c192f3d | 7 | int main() { |
tylerjw | 1:e3c15c192f3d | 8 | printf("Servo Calibration Controls:\n"); |
tylerjw | 1:e3c15c192f3d | 9 | printf("1,2,3 - Position Servo (full left, middle, full right)\n"); |
tylerjw | 1:e3c15c192f3d | 10 | printf("4,5 - Increase or Decrease Max position\n"); |
tylerjw | 1:e3c15c192f3d | 11 | printf("6,7 - Increase or Decrease Min position\n"); |
tylerjw | 1:e3c15c192f3d | 12 | |
tylerjw | 1:e3c15c192f3d | 13 | float max = 0.0005; |
tylerjw | 1:e3c15c192f3d | 14 | float min = -0.0005; |
tylerjw | 1:e3c15c192f3d | 15 | float position = 0.5; |
tylerjw | 1:e3c15c192f3d | 16 | |
tylerjw | 1:e3c15c192f3d | 17 | while(1) { |
tylerjw | 1:e3c15c192f3d | 18 | switch(pc.getc()) { |
tylerjw | 1:e3c15c192f3d | 19 | case '1': position = 0.0; break; |
tylerjw | 1:e3c15c192f3d | 20 | case '2': position = 0.5; break; |
tylerjw | 1:e3c15c192f3d | 21 | case '3': position = 1.0; break; |
tylerjw | 1:e3c15c192f3d | 22 | case '4': max += 0.0001; break; |
tylerjw | 1:e3c15c192f3d | 23 | case '5': max -= 0.0001; break; |
tylerjw | 1:e3c15c192f3d | 24 | case '6': min += 0.0001; break; |
tylerjw | 1:e3c15c192f3d | 25 | case '7': min -= 0.0001; break; |
tylerjw | 1:e3c15c192f3d | 26 | } |
tylerjw | 1:e3c15c192f3d | 27 | printf("position = %.1f, max = %0.4f, min = %0.4f, range = %0.4f\n", position, max, min, (max + -min) / 2.0); |
tylerjw | 1:e3c15c192f3d | 28 | myservo.calibrate_max(max, 45.0); |
tylerjw | 1:e3c15c192f3d | 29 | myservo.calibrate_min(min, 45.0); |
tylerjw | 1:e3c15c192f3d | 30 | myservo = position; |
tylerjw | 1:e3c15c192f3d | 31 | } |
tylerjw | 1:e3c15c192f3d | 32 | } |