// WebRCX NQC code ( 1 / 3 ) // // Accepts simple numeric messages and twitches the camera in the // appropriate direction. // // webrcx1.nqc: Move the camera in incremental steps // webrcx2.nqc: Move the camera to preset positions // webrcx3.nqc: Filtered commands // // Copyright (c) 2001 Scott Ireland // Timing and sensor value settings. Actual settings will vary // depending on hardware design. #define TIME_RESET 10 * 600 // Neutral reset timeout -- 600 = 1 minute #define VALUE_PAN 80 // Pan rotation sensor move value 16 = 3 deg #define LIMIT_PAN_LEFT -480 // Pan rotation sensor left limit value #define LIMIT_PAN_RIGHT 480 // Pan rotation sensor right limit value #define NEUTRAL_PAN 0 // Pan rotation sensor neutral value #define VALUE_TILT 80 // Tilt rotation sensor move value 16 = 3 deg #define LIMIT_TILT_UP -240 // Tilt rotation sensor up limit value #define LIMIT_TILT_DOWN 240 // Tilt rotation sensor down limit value #define NEUTRAL_TILT 0 // Tilt rotation sensor neutral value // Input and Output device ports. No changes needed, // unless you use different ports. #define SENSOR_PAN SENSOR_1 #define LIGHT_SENSOR SENSOR_2 #define SENSOR_TILT SENSOR_3 #define MOTOR_PAN OUT_A #define MOTOR_TILT OUT_C // Pan the camera to the desired position. void pan(int value) { // This adjusts for motor drift value = ((((value * 10) / VALUE_PAN) + (sign(value) * 5)) / 10) * VALUE_PAN; if (OutputStatus (0) > 0x7F) { Off(MOTOR_PAN); } else if (SENSOR_PAN < value && value <= LIMIT_PAN_RIGHT) { // Move Right OnFwd(MOTOR_PAN); until (SENSOR_PAN >= value); Off(MOTOR_PAN); } else if (SENSOR_PAN > value && value >= LIMIT_PAN_LEFT) { // Move Left OnRev(MOTOR_PAN); until (SENSOR_PAN <= value); Off(MOTOR_PAN); } } // Tilt the camera to the desired position. void tilt(int value) { // This adjusts for motor drift value = ((((value * 10) / VALUE_TILT) + (sign(value) * 5)) / 10) * VALUE_TILT; if (OutputStatus (2) > 0x7F) { Off(MOTOR_TILT); } else if (SENSOR_TILT > value && value >= LIMIT_TILT_UP) { // Move Up OnFwd(MOTOR_TILT); until (SENSOR_TILT <= value); Off(MOTOR_TILT); } else if (SENSOR_TILT < value && value <= LIMIT_TILT_DOWN) { // Move Down OnRev(MOTOR_TILT); until (SENSOR_TILT >= value); Off(MOTOR_TILT); } } // Task 0: Initialize the RCX task main() { SetSensor(LIGHT_SENSOR, SENSOR_LIGHT); SetSensor(SENSOR_PAN, SENSOR_ROTATION); SetSensor(SENSOR_TILT, SENSOR_ROTATION); SetPower(MOTOR_PAN + MOTOR_TILT, OUT_FULL); ClearSensor(SENSOR_PAN); ClearSensor(SENSOR_TILT); SetSleepTime(0); repeat (2) { PlaySound (1); Wait(100); } } // Task 1: Wait until the reset time has passed and move to neutral task timer() { ClearTimer(0); until (Timer(0) == TIME_RESET) { }; pan(NEUTRAL_PAN); tilt(NEUTRAL_TILT); } // Task 2: Move the camera UP task up() { stop timer; tilt(SENSOR_TILT - VALUE_TILT); start timer; } // Task 3: Move the camera UP and RIGHT task upright() { stop timer; pan(SENSOR_PAN + VALUE_PAN); tilt(SENSOR_TILT - VALUE_TILT); start timer; } // Task 4: Move the camera RIGHT task right() { stop timer; pan(SENSOR_PAN + VALUE_PAN); start timer; } // Task 5: Move the camera DOWN and RIGHT task downright() { stop timer; pan(SENSOR_PAN + VALUE_PAN); tilt(SENSOR_TILT + VALUE_TILT); start timer; } // Task 6: Move the camera DOWN task down() { stop timer; tilt(SENSOR_TILT + VALUE_TILT); start timer; } // Task 7: Move the camera DOWN and LEFT task downleft() { stop timer; pan(SENSOR_PAN - VALUE_PAN); tilt(SENSOR_TILT + VALUE_TILT); start timer; } // Task 8: Move the camera LEFT task left() { stop timer; pan(SENSOR_PAN - VALUE_PAN); start timer; } // Task 9: Move the camera UP and LEFT task upleft() { stop timer; pan(SENSOR_PAN - VALUE_PAN); tilt(SENSOR_TILT - VALUE_TILT); start timer; }