LEGO NXT Robot Programming with LabVIEW
Graphical Robot Control
Graphical robot control uses connected programming blocks to turn measurements and goals into robot actions. With LabVIEW and a LEGO NXT robot, you configure sensor inputs, calculate decisions, and command motors. The central task is connecting software values to physical behaviour: a correct calculation helps only when it reads the intended sensor, commands the intended motor, and responds at the right time.
Map the program to the hardware
Begin with a connection map. The NXT brick has sensor ports numbered 1–4 and motor ports labelled A–C. Record which device occupies each port. Your program must use that actual arrangement; a port number does not identify the attached sensor automatically.
Configure each sensor for its device type and interpret its output in the documented units. A touch reading represents a pressed or released condition, whereas a distance reading represents a numerical separation. Check a reading by changing the physical input before allowing it to control motion.
Motor configuration also matters. Select the output port, direction, command magnitude, and stopping behaviour. A motor power setting is a command level, not a speed in metres per second. Battery condition, load, regulation settings, and wheel geometry affect the resulting motion. Oppositely mounted drive motors may require different command signs to move the chassis forward.
Use measurements to decide what happens next
Feedback means using measured results to update the robot's commands. For example, an approach controller repeatedly reads the distance to an obstacle, compares it with a stopping threshold, and selects either a forward command or a stop command.
Control approach | Decision uses | Main limitation |
|---|---|---|
Timed motion | A preset duration | Travel changes when actual speed changes |
Rotation-based motion | Measured motor rotation | Wheel slip can separate rotation from ground travel |
Obstacle-based stopping | Measured obstacle distance | Invalid readings and update delays affect stopping |
For a valid distance reading r and threshold rstop, a simple rule is
Acquire a fresh reading for each decision. Repeatedly comparing a value measured only before motion begins does not respond to a changing obstacle distance. Handle invalid readings separately rather than treating them as trustworthy distances.
Convert wheel rotation into estimated travel
An NXT motor includes an encoder. Use a documented rotation measurement and subtract its starting value unless you deliberately reset that measurement. For a wheel attached directly to the motor shaft, rolling without slipping,
Here D is wheel diameter, s is travel, and Δθ is wheel rotation in degrees. The factor πD is the distance travelled in one complete revolution. Use metres for D to obtain metres for s.
If external gears connect the motor to the wheel, convert motor revolutions to wheel revolutions first. These equations estimate ground travel only under their rolling assumptions; an encoder measures rotation even when a wheel spins against the floor.
Build and test the LabVIEW controller
Choose whether the program runs on the computer through a connection or is downloaded to the brick. Confirm supported functions for that arrangement. Exact block names depend on the installed NXT module or toolkit.
Build the approach controller on LabVIEW's block diagram:
- Place a sensor-read block inside a While Loop so each iteration obtains a fresh distance. Configure its sensor port and wire its numerical output to a less-than-or-equal comparison. Wire the stopping threshold, in matching units, to the other comparison input.
- The comparison produces a Boolean that is true when the robot should stop. Combine it with operator cancellation and invalid-reading or fault indicators using Boolean OR to form a stop request.
- Wire the stop request to a Case Structure selector. In the false case, command the configured drive motors forward; in the true case, issue their stop/brake command. Also wire the stop request to the loop's conditional terminal, configured as Stop if True.
- After the loop exits, execute an explicit motor stop/brake block for the drive motors. Enforce this order with an execution dependency; placing a block visually to the right of the loop does not establish execution order.
For rotation-based stopping, read and store the starting encoder value before the loop. Inside it, wire the current reading minus that stored value into the target comparison, accounting for the chosen direction.
At constant approach speed v, an additional update delay T permits travel vT before the next decision. Braking adds further travel. Allow for both update delay and physical stopping distance. Test at low speed and verify the physical stop; brake and coast settings behave differently.
What to remember
- Match software ports, sensor types, units, and motor directions to the actual robot.
- Wire fresh measurements through comparisons to motor commands and the loop's stop condition.
- Convert rotation to travel using the wheel geometry and any external gearing.
- Explicitly stop the motors after the loop and verify delay and braking.
Example: Stop a delivery robot at a travel target
A laboratory delivery robot uses two identical, directly driven NXT wheels of diameter 56.0 mm. Both wheels rotate equally, the robot travels straight, and neither wheel slips. You want the robot to travel 0.420 m. Its relative rotation is the current encoder angle minus the recorded starting angle; the encoder does not reset or wrap during the movement.
The controller repeatedly reads the encoder, continues forward while relative rotation is below the ideal target, and issues a brake command at the first reading at or above that target. Motor directions have been checked, and all readings are valid.
a) Calculate the ideal relative rotation target in degrees, to one decimal place.
First convert the diameter to metres: D=0.0560 m. One wheel revolution covers its circumference, which is ________ to four decimal places.
The required number of wheel revolutions is ________ to four decimal places. Retain unrounded values for the final calculation.
Direct drive makes motor rotation equal to wheel rotation, so
The ideal target is 859.4° to one decimal place. This is a relative angle, rather than an absolute encoder reading.
b) The starting encoder reading is 125°. Two successive readings during motion are 970° and 1003°. Determine the command at each reading and the angular excess above the ideal target when braking is first commanded. Give the excess to one decimal place.
Subtract the starting value from each reading. The first relative rotation is ________, and the second is ________.
The first relative angle is below 859.4367…∘, so the controller continues forward. The second exceeds the target, so it issues the brake command. Comparing the absolute reading directly with the relative target would stop the robot too early.
At the second reading, the angular excess is
The commands are continue at 970° and brake at 1003°. Braking is commanded 18.6° beyond the ideal target; subsequent physical braking may add further rotation.
c) For a separate timing check on the same robot, suppose encoder reads are at most 100 ms apart and wheel speed before braking never exceeds 240°/s. Processing and command transmission are instantaneous in this model. Bound the additional ground travel caused by detecting a target crossing late. Exclude travel after the brake command and answer in millimetres to one decimal place.
Convert the maximum reading interval to seconds: it is ________. A target crossing immediately after a reading can remain undetected for almost this entire interval.
The maximum additional angle before detection is ________.
Convert that angle into rolling distance using the same wheel diameter:
The calculated upper bound is 11.7 mm, reported to one decimal place. This allowance covers detection delay only. A complete stopping budget must also include travel after the brake command.
An NXT robot travels straight on a level surface with identical 64.0 mm diameter drive wheels and no slipping. External gearing makes each motor shaft turn three revolutions for every one wheel revolution. Both motors show the same forward rotation. The monitored motor's encoder reading increases from 180° to 1620°, without resetting or wrapping between readings. What distance does the robot travel? Answer in metres to three decimal places.
A LabVIEW controller uses a light sensor to adjust two NXT drive motors. For a valid light reading L, expressed as a percentage of full scale, it calculates
The commands uL and uR are dimensionless forward command levels. Motor direction mapping has already been verified. If the touch sensor is pressed or the light reading is invalid, the controller instead commands zero to both motors, overriding the formulas. Treat every row as an independent update. Enter the exact integer left and right commands for each row.
| Update | Light reading (%) | Light valid | Touch pressed | Left command | Right command |
| A | 40 | yes | no | ||
| B | 50 | yes | no | ||
| C | 65 | yes | no | ||
| D | 40 | yes | yes | ||
| E | 50 | no | no |