RobotC Sample Programs (RCX)


Motors
Sample programs using basic motor and timing commands with no sensors.

Moving Forward
Sample Programs/RCX/Motor/rcx_moving_forward.c
RCX
Make the robot run forward for 4 seconds, using motor power commands and Wait commands.

Forward and Reverse
Sample Programs/RCX/Motor/rcx_moving_forward_then_reverse.c
RCX
Make the robot run forward for 4 seconds, and then go in reverse for 4 seconds using motor power commands and Wait commands.

Point Turns
Sample Programs/RCX/Motor/rcx_point_turns.c
RCX
Make the robot turn right for 2.5 seconds, and then turn left for 2.5 seconds using motor power commands and Wait commands.

Reverse, Forward, and Turn
Sample Programs/RCX/Motor/rcx_modifiers.c
RCX
Make the robot reverse for 2 seconds, move forward for 2 seconds, and finally turn right for 2.5 seconds using motor power commands and Wait commands.


Loops
Programs showing the same repeating behavior, using different kinds of loops.

While loop
Sample Programs/RCX/Motor/RCX_loop_1_while.c
RCX
Run five laps around a square, using a while loop to continue running "while less than 20 sides of the square have been traveled".

For loop
Sample Programs/RCX/Motor/rcx_loop_2_for.c
RCX
Run five laps around a square, using a for loop to continue running "for as long as 20 sides of the square have not been traveled".

Do-While loop
Sample Programs/RCX/Motor/rcx_loop_3_do_while.c
RCX
Run five laps around a square, using a do-while loop to continue running "while less than 20 sides of the square have been traveled".


Touch Sensor
Programs using the Touch Sensor to inform and guide robot behavior.

Wait for Push
Sample Programs/RCX/Touch/rcx_wait_for_push.c
RCX
Travel forward until a Touch Sensor on Sensor Port 1 is pushed (assuming it starts "released").

Wait for Release
Sample Programs/RCX/Touch/rcx_wait_for_release.c
RCX
Travel forward until a Touch Sensor on Sensor Port 1 is released (assuming it starts "pushed in ").

Remote Control
Sample Programs/RCX/Touch/rcx_remote_control.c
RCX
Uses two Touch Sensors. Turn left if one touch sensor is pressed. Turn right if the other is pressed. Run forward if both are pressed at the same time.

Bug Bot
Sample Programs/RCX/Touch/rcx_bug_bot.c
RCX
Uses two Touch Sensors positioned so that they are "pushed" by antenna-like extensions when the antenna collides with an object. Start off moving forward. If either Touch Sensor is "pushed" by a collision-detector antenna, back up and turn away from the side that was pressed, then resume movement.


Light Sensor
Programs using the Light Sensor to inform and guide robot behavior.

Wait for Dark
Sample Programs/RCX/Light/rcx_wait_for_dark.c
RCX
Move forward until the Light Sensor on Sensor Port 1 detects a dark region (assuming it starts off seeing a light region). This is typically a downward-looking light sensor finding a piece of black tape on a light-colored table.

Wait for Light
Sample Programs/RCX/Light/rcx_wait_for_light.c
RCX
Move forward until the Light Sensor on Sensor Port 1 detects a light region (assuming it starts off seeing a dark region).

Timed Line Tracker
Sample Programs/RCX/Light/rcx_line_track_timer.c
RCX

Requires a Light Sensor on Port 1, facing down toward a dark-colored line on a light-colored surface. The robot will follow the line, using the following reasoning:

  • Aim for the left edge of the line
  • If the sensor sees dark, it means it's somewhere over the middle of the line, and should turn toward the left to get back to the left edge
  • If the sensor sees light, it means it's somewhere off the line to the left, so it should turn back to the right to get to the edge


Rotation Sensor
Programs using the Rotation Sensors to inform and guide robot behavior.

Run Straight
Sample Programs/RCX/Rotation/rcx_straight.c
RCX
Move forward until both of the motors have turned at least 320 "clicks". The actual distance covered will vary with the size of your robot's wheels.

Point Turn (distance)
Sample Programs/RCX/Rotation/rcx_point_turns.c
RCX
Turn until motor A reaches 320 "clicks", and motor B reaches -320 "clicks". The actual distance covered will vary with the size of your robot's wheels.

Line Track (distance)
Sample Programs/RCX/Rotation/rcx_line_track_rotations.c
RCX

Requires a Light Sensor on Port 1, facing down toward a dark-colored line on a light-colored surface, and a Rotation Sensor on Port 2. The robot will follow the line, using the following reasoning:

  • Aim for the left edge of the line
  • If the sensor sees dark, it means it's somewhere over the middle of the line, and should turn toward the left to get back to the left edge
  • If the sensor sees light, it means it's somewhere off the line to the left, so it should turn back to the right to get to the edge

It will follow the line until motor B reaches 320 "clicks".



Temperature Sensor
Programs using the Temperature Sensors
to inform and guide robot behavior.

Wait for Warm
Sample Programs/RCX/Temperature/rcx_wait_for_warm.c
RCX
Move forward until the temperature sensor reaches a value greater than "30".

Wait for Cool
Sample Programs/RCX/Temperature/rcx_wait_for_cool.c
RCX
Move forward until the temperature sensor reaches a value lower than "25".