NXT-0.2.3: A Haskell interface to Lego Mindstorms NXT

Safe HaskellNone




A message-based control of a NXT brick via remotely executed MotorControl program. The main goal of this approach is to achieve better precision of motor movements as program monitors and adapts motor commands on the NXT brick itself. For example, common motor's overshoot is thus removed in most cases.

You should download/compile MotorControl program from http://www.mindstorms.rwth-aachen.de/trac/wiki/MotorControl and upload it to the NXT brick with nxt-upload program. This module will then run that program and sends it messages to control the NXT brick. Because commands will be executed and controlled directly on the NXT brick more powerful and precise control is possible.

Please refer to original documentation of MotorControl program for more information, description of commands and explanations how to use them. This interface also implements static pauses between commands mentioned there and required by MotorControl. This means functions calls will block for this time so consider using special Haskell thread for communication with the NXT brick. Dynamic/minimal pauses are not implemented and have to be taken care of by user of this interface.

Check Robotics.NXT.Remote for another (simpler) approach to message-based control. It would be great to one day combine MotorControl's precision with API (especially interruptability) of remote.nxc.



startMotorControlProgram :: NXT ()Source

Starts MotorControl22.rxe program on the NXT brick. Program has to be uploaded/available on the NXT brick.

stopMotorControlProgram :: NXT ()Source

Stops current running program on the NXT brick. Probably this means MotorControl22.rxe program on the NXT brick.


controlledMotorCmd :: [OutputPort] -> OutputPower -> TachoLimit -> [MotorControlMode] -> NXT ()Source

Interface to CONTROLLED_MOTORCMD command which takes care of precise motor movements.

Requires dynamic/minimal pauses.

data MotorControlMode Source



Keeps active brake on after the end of the movement.


In a case of a load on the motor adapt motor power to retain the same speed. Really works only if there is room for that (not that motor is already running at the maximum power).


Smoothly starts the movement.

resetErrorCorrection :: [OutputPort] -> NXT ()Source

Interface to RESET_ERROR_CORRECTION command which can be used to reset the NXT brick's internal error correction mechanism (and motor position information at the same time).

The same thing can be achieved by using resetMotorPosition with InternalPosition argument.

isMotorReady :: [OutputPort] -> NXT [Bool]Source

Interface to ISMOTORREADY command which determine the state of a motor: is it currently executing a command (for example, moving) or is it ready to accept new commands?

Implements static pauses.

classicMotorCmd :: [OutputPort] -> OutputPower -> TachoLimit -> SpeedRegulation -> NXT ()Source

Interface to CLASSIC_MOTORCMD command which is very similar to setOutputState but better interacts with MotorControl.

Requires dynamic/minimal pauses.


type SpeedRegulation = BoolSource

Should in a case of a load on the motor its power be adapted to retain the same speed? Really works only if there is room for that (not that motor is already running at the maximum power).