How to Make a LEGO Mindstorms NXT Alpha Rex Avoid Objects
Programming the LEGO Mindstorms NXT robots is a fairly simple project, which uses a visual style 1. If you have made a robot before, you likely have some experience working with the programming language. To program your Mindstorms Alpha Rex, you will need to know some of the basics of Mindstorms programming, including programming motors and sensors and making subroutines.
Build the LEGO Mindstorms Alpha Rex model according to the directions 1. The directions for the model are listed under References.
Connect the LEGO NXT brick to your computer using the Bluetooth or included USB cable. Run the NXT programming software.
Program three subroutines, one for walking forward, one for turning left, and one for turning right. To walk, use move blocks to program one leg to move and the motor on the back to tilt in the direction of the opposite leg. Repeat with the other legs to create walking movement. To turn, program one leg to move at a time. You may find it helpful to tilt the robot in the same direction as the tuning leg. If you have built the model before, you may already have these routines saved.
Program the robot to walk forward until the IR sensor picks up an obstacle. You can set the distance to be as close or far as you prefer.
Place a switch block on the end of the line. Program the block to randomly choose one of the two paths which it selects as an option.
Place the left and right turn blocks on the two branches of the switch block. This makes it so that the robot will randomly turn left or right when it detects an obstacle.
Place the entire program inside a loop. If you set the loop to infinite, the robot will walk forward indefinitely and turn when it sees obstacles. You can also set it to perform this only a few times.
For more information on the individual blocks in the programming language or for basic information on NXT programming, consult the websites under Resources.
- Koichi Kamoshida/Getty Images News/Getty Images