26 #define MOTOR_POWER_FAST 75
27 #define MOTOR_POWER_MODERATE 75
28 #define MOTOR_POWER_SLOW 30
31 #define MOTOR_TILT OUT_C
32 #define MOTOR_STRIDE OUT_B
35 #define TOUCH_SENSOR IN_1
36 #define LIGHT_SENSOR IN_3
39 #define LIGHT_SENSOR_PROXIMITY_THRESHOLD 40
42 #define CALIBERATION_ERROR_TOLERANCE 90
44 int GetSensorProximity (
int sensor)
46 if (sensor == TOUCH_SENSOR)
47 return Sensor(TOUCH_SENSOR);
48 if (Sensor(LIGHT_SENSOR) < LIGHT_SENSOR_PROXIMITY_THRESHOLD)
54 int CaliberateMotorArc(
int motor,
int power,
int sensor,
55 int postAlignmentAngle)
57 if (!GetSensorProximity(sensor))
60 while (!GetSensorProximity(sensor)) Wait(20);
63 RotateMotor(motor, power, postAlignmentAngle);
85 OnFwd(motor, MOTOR_POWER_FAST);
88 while (GetSensorProximity(sensor));
91 while (!GetSensorProximity(sensor));
94 extremeTachoMin = GetOutput(motor, TachoCount);
95 cycleCountMin = extremeTachoMin;
98 while (GetSensorProximity(sensor));
101 extremeTachoMax = GetOutput(motor, TachoCount);
104 while (!GetSensorProximity(sensor));
107 cycleCountMax = GetOutput(motor, TachoCount);
113 cycleCount = cycleCountMax - cycleCountMin;
114 int errorCycleCount = cycleCount % CALIBERATION_ERROR_TOLERANCE;
115 if (errorCycleCount < CALIBERATION_ERROR_TOLERANCE/2)
116 cycleCount -= errorCycleCount;
118 cycleCount += CALIBERATION_ERROR_TOLERANCE - errorCycleCount;
122 alignDegrees = (cycleCount * postAlignmentPercentage)/100 +
123 (extremeTachoMax - extremeTachoMin)/2;
124 RotateMotor(motor, MOTOR_POWER_FAST, alignDegrees);
132 int tiltCycleCount, strideCycleCount;
133 int currentPositionTilt = 0, currentPositionStride = 0;
135 SetSensorTouch(TOUCH_SENSOR);
136 SetSensorLight(LIGHT_SENSOR);
139 TextOut(0, LCD_LINE1, NumToStr(tiltCycleCount),
true);
142 TextOut(0, LCD_LINE2, NumToStr(strideCycleCount),
false);
144 RotateMotor(MOTOR_STRIDE, MOTOR_POWER_FAST, strideCycleCount/8);
145 RotateMotor(MOTOR_TILT, MOTOR_POWER_FAST, tiltCycleCount/4);
int CaliberateMotor(int motor, int sensor, int postAlignmentPercentage)
Caliberates a rotary motor setup that has a sensor attached to detect a cyclic position.