-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A Haskell interface to Lego Mindstorms NXT -- -- A Haskell interface to Lego Mindstorms NXT over Bluetoooth. It -- supports direct commands, messages and many sensors (also unofficial). -- It has also support for a simple message-based control of a NXT brick -- via remotely executed program (basic NXC code included). -- -- It contains three simple programs: nxt-upload for uploading -- files to a NXT brick, nxt-status for displaying a NXT brick -- status, and nxt-shutdown for remote shutdown of a NXT brick. -- -- It works on Linux, Mac OS X and Windows. -- -- Feel free to contribute additional features, interfaces for more -- sensors and propose or write other (example) programs. @package NXT @version 0.2.2 -- | This module defines an interface over Bluetooth to a NXT brick as -- defined in Lego Mindstorms NXT Bluetooth Developer Kit, Appendix 1 - -- Communication protocol and Appendix 2 - Direct commands. It also -- defines some additional functions not available directly otherwise. module Robotics.NXT -- | Function which initializes and terminates Bluetooth connection to the -- NXT brick (using initialize and terminate) and -- in-between runs given computation. It terminates Bluetooth connection -- on an exception, too, rethrowing it afterwards. withNXT :: FilePath -> NXT a -> IO a -- | Default Bluetooth serial device filename for current operating system. -- Currently always /dev/rfcomm0. defaultDevice :: FilePath -- | Sets output port (motor) state. This is the main function for -- controlling a motor. setOutputState :: OutputPort -> OutputPower -> [OutputMode] -> RegulationMode -> TurnRatio -> RunState -> TachoLimit -> NXT () -- | Same as setOutputState but also request a confirmation. Useful -- to assure the command was really accepted. In a case of an error it -- throws a NXTException. -- -- Confirmation requires a change of the direction of NXT Bluetooth -- communication which takes around 30 ms. setOutputStateConfirm :: OutputPort -> OutputPower -> [OutputMode] -> RegulationMode -> TurnRatio -> RunState -> TachoLimit -> NXT () -- | Gets output port (motor) current state. In additional to values used -- with setOutputState also TachoCount, -- BlockTachoCount and RotationCount values are available -- which tell you current position of a motor. getOutputState :: OutputPort -> NXT OutputState -- | Resets one of three position counters for a given output port. resetMotorPosition :: OutputPort -> MotorReset -> NXT () -- | Sets input port (sensor) type and mode. setInputMode :: InputPort -> SensorType -> SensorMode -> NXT () -- | Same as setInputMode but also request a confirmation. Useful to -- assure the command was really accepted. In a case of an error it -- throws a NXTException. -- -- Confirmation requires a change of the direction of NXT Bluetooth -- communication which takes around 30 ms. setInputModeConfirm :: InputPort -> SensorType -> SensorMode -> NXT () -- | Gets input port (sensor) values. This is the main function for reading -- a sensor. getInputValues :: InputPort -> NXT InputValue -- | Resets input port (sensor) scaled value. resetInputScaledValue :: InputPort -> NXT () -- | Gets firmware and protocol versions of the NXT brick. getVersion :: NXT Version -- | Gets device (the NXT brick) information: name, Bluetooth 48 bit -- address in the string format, strength of Bluetooth signal (not -- implemented in current NXT firmware versions, use -- bluetoothRSSI or bluetoothLinkQuality as an -- alternative), free space on flash. getDeviceInfo :: NXT DeviceInfo -- | Gets current battery level (in volts). getBatteryLevel :: NXT Voltage -- | Is battery used in the NXT brick rechargeable? isBatteryRechargeable :: NXT Bool -- | Sends a keep alive (turned on) packet. It prevents the NXT brick from -- automatically powering off. Other commands do not prevent that from -- hapenning so it is useful to send this packet from time to time if you -- want to prevent powering off. keepAlive :: NXT () -- | Same as keepAlive but also request a confirmation. Useful to -- assure the command was really accepted. In a case of an error it -- throws a NXTException. -- -- Confirmation requires a change of the direction of NXT Bluetooth -- communication which takes around 30 ms. keepAliveConfirm :: NXT () -- | Gets current sleep timeout setting (in seconds) after which the NXT -- brick automatically powers off if not prevented with a keep alive -- packet (use keepAlive to send one). This setting is cached. getSleepTimeout :: NXT Duration -- | When was a last keep alive packet send? getLastKeepAliveTime :: NXT (Maybe POSIXTime) -- | Helper function which stops all NXT brick activities: stops motors and -- disables sensors. stopEverything :: NXT () -- | Shutdowns (powers off) the NXT brick. You have to manually turn it on -- again. shutdown :: NXT () -- | Starts a given program on the NXT brick. startProgram :: FileName -> NXT () -- | Same as startProgram but also request a confirmation. Useful to -- assure the command was really accepted, but this does not assure that -- the program has really started successfully (especially not that it is -- already running when the confirmation is received). Use -- ensureStartProgram for that. In a case of an error it throws a -- NXTException. -- -- Confirmation requires a change of the direction of NXT Bluetooth -- communication which takes around 30 ms. startProgramConfirm :: FileName -> NXT () -- | Stops a currently running program. stopProgram :: NXT () -- | Same as stopProgram but also request a confirmation. Useful to -- assure the command was really accepted. In a case of an error it -- throws a NXTException. -- -- Confirmation requires a change of the direction of NXT Bluetooth -- communication which takes around 30 ms. stopProgramConfirm :: NXT () -- | Same as stopProgramConfirm but it also requires that the -- program was really running. It throws a NXTException otherwise. stopProgramExisting :: NXT () -- | Helper function which first ensures that no other program is running -- and then ensures that a given program is really running before it -- returns. ensureStartProgram :: FileName -> NXT () -- | Gets the name of the currently running program, if any. getCurrentProgramName :: NXT (Maybe String) -- | Writes a message to the given inbox queue of the running remote -- program. A message length is limited to 58 characters/bytes. A queue -- is limited to 5 messages. messageWrite :: Inbox -> String -> NXT () -- | Same as messageWrite but also request a confirmation. Useful to -- assure the command was really accepted. In a case of an error it -- throws a NXTException. -- -- Confirmation requires a change of the direction of NXT Bluetooth -- communication which takes around 30 ms. messageWriteConfirm :: Inbox -> String -> NXT () -- | Reads a message from the currently running program from a given remote -- inbox queue. A queue is limited to 5 messages. It throws a -- NXTException if there is no message in a remote inbox queue. messageRead :: RemoteInbox -> RemoveMessage -> NXT String -- | Same as messageWrite but returns Nothing if there is no -- message in a given remote inbox queue. maybeMessageRead :: RemoteInbox -> RemoveMessage -> NXT (Maybe String) -- | Same as messageWrite but if there is no message in a given -- remote inbox queue it retries until there is. ensureMessageRead :: RemoteInbox -> RemoveMessage -> NXT String -- | Plays a given sound file. playSoundFile :: LoopPlayback -> FileName -> NXT () -- | Same as playSoundFile but also request a confirmation. Useful -- to assure the command was really accepted. In a case of an error it -- throws a NXTException. -- -- Confirmation requires a change of the direction of NXT Bluetooth -- communication which takes around 30 ms. playSoundFileConfirm :: LoopPlayback -> FileName -> NXT () -- | Plays a tone with a given frequency (in hertz) for a given duration -- (in seconds). playTone :: Frequency -> Duration -> NXT () -- | Stops current sound file playback. stopSoundPlayback :: NXT () -- | Same as stopSoundPlayback but also request a confirmation. -- Useful to assure the command was really accepted. In a case of an -- error it throws a NXTException. -- -- Confirmation requires a change of the direction of NXT Bluetooth -- communication which takes around 30 ms. stopSoundPlaybackConfirm :: NXT () -- | Gets number of bytes available to read. lowspeedGetStatus :: InputPort -> NXT Int -- | Writes data. At most 16 bytes can be written at a time. -- -- Reply data length must be specified in the write command since reading -- from the device is done on a master-slave basis. lowspeedWrite :: InputPort -> RxDataLength -> TxData -> NXT () -- | Same as lowspeedWrite but also request a confirmation. Useful -- to assure the command was really accepted. In a case of an error it -- throws a NXTException. -- -- Confirmation requires a change of the direction of NXT Bluetooth -- communication which takes around 30 ms. lowspeedWriteConfirm :: InputPort -> RxDataLength -> TxData -> NXT () -- | Reads data. The protocol does not support variable-length return -- packages so the response always contains 16 data bytes with invalid -- data padded with zeros. lowspeedRead :: InputPort -> NXT RxData -- | Opens a given file for writing as a linked list of flash sectors. openWrite :: FileName -> FileSize -> NXT FileHandle -- | Opens a given file for writing as a linear contiguous block of flash -- memory (required for user programs and certain data files). openWriteLinear :: FileName -> FileSize -> NXT FileHandle -- | Writes data to a file. At most 61 bytes can be written at a time. write :: FileHandle -> FileData -> NXT () -- | Same as write but also request a confirmation. Useful to assure -- the command was really accepted. In a case of an error it throws a -- NXTException. -- -- Confirmation requires a change of the direction of NXT Bluetooth -- communication which takes around 30 ms. writeConfirm :: FileHandle -> FileData -> NXT () -- | Closes a file. close :: FileHandle -> NXT () -- | Same as close but also request a confirmation. Useful to assure -- the command was really accepted. In a case of an error it throws a -- NXTException. -- -- Confirmation requires a change of the direction of NXT Bluetooth -- communication which takes around 30 ms. closeConfirm :: FileHandle -> NXT () -- | Deletes a given file. delete :: FileName -> NXT () -- | Same as delete but also request a confirmation. Useful to -- assure the command was really accepted. In a case of an error it -- throws a NXTException. -- -- Confirmation requires a change of the direction of NXT Bluetooth -- communication which takes around 30 ms. deleteConfirm :: FileName -> NXT () -- | Same as deleteConfirm but it also requires that the file exists -- before deletion. It throws a NXTException otherwise. deleteExisting :: FileName -> NXT () -- | Helper function to get an ID of a module matching a given module name. -- Each module encompass some firmware functionality. Function caches IDs -- so it hopefully retrieves it from a cache of previous requests. getModuleID :: ModuleName -> NXT (Maybe ModuleID) -- | Helper function to get information about all modules matching a given -- module name (which can be a wild card). listModules :: ModuleName -> NXT [ModuleInfo] -- | Requests information about the first module matching a given module -- name (which can be a wild card). Returned module handle can be used -- for followup requests and has to be closed when not needed anymore. requestFirstModule :: ModuleName -> NXT (ModuleHandle, Maybe ModuleInfo) -- | Requests information about the next module matching previously -- requested module name (which can be a wild card). Returned module -- handle can be used for followup requests and has to be closed when not -- needed anymore. requestNextModule :: ModuleHandle -> NXT (ModuleHandle, Maybe ModuleInfo) -- | Closes module handle of previously requested module information. closeModuleHandle :: ModuleHandle -> NXT () -- | Same as closeModuleHandle but also request a confirmation. -- Useful to assure the command was really accepted. In a case of an -- error it throws a NXTException. -- -- Confirmation requires a change of the direction of NXT Bluetooth -- communication which takes around 30 ms. closeModuleHandleConfirm :: ModuleHandle -> NXT () -- | Reads data from an IO map of a given module. At most 119 bytes can be -- read at a time. -- -- You probably have to know what different values at different positions -- mean and control. The best way is to check NXT firmware source code. readIOMap :: ModuleID -> IOMapOffset -> IOMapLength -> NXT IOMapData -- | Writes data to an IO map of a given module. At most 54 bytes can be -- written at a time. -- -- You probably have to know what different values at different positions -- mean and control. The best way is to check NXT firmware source code. writeIOMap :: ModuleID -> IOMapOffset -> IOMapData -> NXT () -- | Same as writeIOMap but also request a confirmation. Useful to -- assure the command was really accepted. In a case of an error it -- throws a NXTException. -- -- Confirmation requires a change of the direction of NXT Bluetooth -- communication which takes around 30 ms. writeIOMapConfirm :: ModuleID -> IOMapOffset -> IOMapData -> NXT () -- | Opens and intializes a Bluetooth serial device communication. initialize :: FilePath -> IO NXTInternals -- | Stops all NXT activities (by calling stopEverything) and closes -- the Bluetooth serial device communication. NXTInternals token -- must not be used after that anymore. terminate :: NXTInternals -> IO () -- | Runs a computation in a context of a given NXTInternals token, -- returning a value and a new token. runNXT :: NXT a -> NXTInternals -> IO (a, NXTInternals) -- | Runs a computation in a context of a given NXTInternals token, -- returning just a new token. execNXT :: NXT a -> NXTInternals -> IO NXTInternals -- | Gets received signal strength indicator (RSSI) of the Bluetooth -- connection to the NXT brick. -- -- Currently supported only on Linux. It throws a NXTException -- otherwise. bluetoothRSSI :: NXT Int -- | Gets link quality of the Bluetooth connection to the NXT brick. -- -- Currently supported only on Linux. It throws a NXTException -- otherwise. bluetoothLinkQuality :: NXT Int -- | Monad which encompasses interface to the NXT brick. data NXT a -- | The format of version is "major.minor". To format it use -- printf "%d.%02d" major minor. data Version Version :: FirmwareVersion -> ProtocolVersion -> Version data FirmwareVersion FirmwareVersion :: Major -> Minor -> FirmwareVersion data ProtocolVersion ProtocolVersion :: Major -> Minor -> ProtocolVersion type Major = Int type Minor = Int data DeviceInfo DeviceInfo :: Name -> BTAddress -> BTStrength -> FlashFree -> DeviceInfo -- | Name of the NXT brick. type Name = String -- | Bluetooth address of the NXT brick in the string format. type BTAddress = String -- | Strength of the Bluetooth signal. Not implemented in current NXT -- firmware versions. Use bluetoothRSSI or -- bluetoothLinkQuality as an alternative. type BTStrength = Int64 -- | Free flash space on the NXT brick (in bytes). type FlashFree = Int64 data OutputState OutputState :: OutputPort -> OutputPower -> [OutputMode] -> RegulationMode -> TurnRatio -> RunState -> TachoLimit -> TachoCount -> BlockTachoCount -> RotationCount -> OutputState data OutputPort -- | Output port (motor) A. A :: OutputPort -- | Output port (motor) B. B :: OutputPort -- | Output port (motor) C. C :: OutputPort -- | Power and direction. In [-100, 100] range. type OutputPower = Int data OutputMode -- | Enables PWM power according to speed. MotorOn :: OutputMode -- | Voltage is not allowed to float between PWM pulses, improves accuracy, -- uses more power. Brake :: OutputMode -- | Required in conjunction with output regulation mode setting. Regulated :: OutputMode data RegulationMode -- | Disables regulation. RegulationModeIdle :: RegulationMode -- | Auto adjust PWM duty cycle if motor is affected by physical load. -- Really works only if there is room for that (not that motor is already -- running at the maximum power). RegulationModeMotorSpeed :: RegulationMode -- | Attempts to keep rotation in sync with another motor that has this -- set. Also involves turn ratio. RegulationModeMotorSync :: RegulationMode -- | In regulated synced mode the difference between two motors. In [-100, -- 100] range. type TurnRatio = Int data RunState -- | Disables power to motor. MotorRunStateIdle :: RunState -- | Ramping to a new speed set-point that is greater than the current -- speed set-point. MotorRunStateRampUp :: RunState -- | Enables power to motor. MotorRunStateRunning :: RunState -- | Ramping to a new speed set-point that is less than the current speed -- set-point. MotorRunStateRampDown :: RunState -- | Hold at the current position. MotorRunStateHold :: RunState -- | Target tacho limit for a motor movement. 0 means no limit. It is an -- unsigned value (you select direction of motor movement with sign of -- OutputPower value). type TachoLimit = Int64 -- | Internal (absolute) tacho counter. Number since the last reset of the -- motor tacho counter. type TachoCount = Int64 -- | Block-relative position counter. Current position relative to the last -- programmed movement. type BlockTachoCount = Int64 -- | Program-relative position counter. Current position relative to the -- last reset of the rotation sensor for this motor. type RotationCount = Int64 data MotorReset -- | Resets program-relative position counter (RotationCount). AbsolutePosition :: MotorReset -- | Resets block-relative position counter (BlockTachoCount) RelativePosition :: MotorReset -- | Resets internal movement counters (also TachoCount), cancels -- current goal and resets internal error-correction system. InternalPosition :: MotorReset data InputPort -- | Input port (sensor) 1. One :: InputPort -- | Input port (sensor) 2. Two :: InputPort -- | Input port (sensor) 3. Three :: InputPort -- | Input port (sensor) 4. Four :: InputPort data InputValue InputValue :: InputPort -> Valid -> Calibrated -> SensorType -> SensorMode -> RawADValue -> NormalizedADValue -> ScaledValue -> CalibratedValue -> InputValue -- | True if new data value should be seen as valid data. type Valid = Bool -- | True if calibration file found and used for -- CalibratedValue. type Calibrated = Bool -- | Type of the sensor currently attached to InputPort. -- NoSensor turns off the sensor. data SensorType NoSensor :: SensorType Switch :: SensorType Temperature :: SensorType Reflection :: SensorType Angle :: SensorType LightActive :: SensorType LightInactive :: SensorType SoundDB :: SensorType SoundDBA :: SensorType Custom :: SensorType Lowspeed :: SensorType Lowspeed9V :: SensorType NoOfSensorTypes :: SensorType data SensorMode -- | Reports scaled value equal to the raw value. RawMode :: SensorMode -- | Reports scaled value as 1 true or 0 false, false if raw value > 55% -- of total range, true if < 45%. BooleanMode :: SensorMode -- | Reports scaled value as number of transitions between true and false. TransitionCntMode :: SensorMode -- | Reports scaled value as number of transitions from false to true, then -- back to false. PeriodCounterMode :: SensorMode -- | Reports scaled value as % of full scale reading for a configured -- sensor type. PctFullScaleMode :: SensorMode -- | For reporting temperature in celsius. CelsiusMode :: SensorMode -- | For reporting temperature in fahrenheit. FahrenheitMode :: SensorMode -- | Reports scaled value as count of ticks on RCX-style rotation sensor. AngleStepsMode :: SensorMode -- | Raw A/D value. Device dependent. type RawADValue = Int -- | Normalized A/D value. Type dependent. In [0, 1023] range. type NormalizedADValue = Int -- | Scaled value. Mode dependent. In percent. type ScaledValue = Int -- | Value scaled according to calibration. Unused in current NXT firmware -- versions. type CalibratedValue = Int -- | Voltage value (in volts). type Voltage = Ratio Int -- | Time duration (in seconds). type Duration = NominalDiffTime -- | Inbox on the NXT brick into which the host (computer) queues messages -- for the program running there. data Inbox Inbox0 :: Inbox Inbox1 :: Inbox Inbox2 :: Inbox Inbox3 :: Inbox Inbox4 :: Inbox Inbox5 :: Inbox Inbox6 :: Inbox Inbox7 :: Inbox Inbox8 :: Inbox Inbox9 :: Inbox -- | Outbox on the NXT brick where the program running there queues -- messages for the host (computer). There is a convention that only -- RemoteInbox10 - RemoteInbox19 outboxes are used for this -- purpose so that lower ones can be used for inter-brick communication. -- But this convention is not really obeyed in practice. data RemoteInbox RemoteInbox0 :: RemoteInbox RemoteInbox1 :: RemoteInbox RemoteInbox2 :: RemoteInbox RemoteInbox3 :: RemoteInbox RemoteInbox4 :: RemoteInbox RemoteInbox5 :: RemoteInbox RemoteInbox6 :: RemoteInbox RemoteInbox7 :: RemoteInbox RemoteInbox8 :: RemoteInbox RemoteInbox9 :: RemoteInbox RemoteInbox10 :: RemoteInbox RemoteInbox11 :: RemoteInbox RemoteInbox12 :: RemoteInbox RemoteInbox13 :: RemoteInbox RemoteInbox14 :: RemoteInbox RemoteInbox15 :: RemoteInbox RemoteInbox16 :: RemoteInbox RemoteInbox17 :: RemoteInbox RemoteInbox18 :: RemoteInbox RemoteInbox19 :: RemoteInbox -- | Should the message be remove from the queue once received? type RemoveMessage = Bool -- | Loop playback of the sound file? type LoopPlayback = Bool -- | Frequency of the played tone (in hertz). type Frequency = Int -- | At most 16 data bytes can be read at a time. type RxDataLength = Int type TxData = [Word8] type RxData = [Word8] -- | Address of the device (sensor) on the I2C bus. type DeviceAddress = Word8 -- | I2C device command. type Command = Word8 -- | I2C device measurement value. type Measurement = Int -- | Filename of the file on the NXT brick filesystem. In 15.3 format. type FileName = String -- | Size of the file on the NXT brick filesystem. type FileSize = Int -- | Handle of the opened file on the NXT brick filesystem. type FileHandle = Int type FileData = [Word8] -- | Type of the IO map module information. data ModuleInfo ModuleInfo :: ModuleName -> ModuleID -> ModuleSize -> ModuleIOMapSize -> ModuleInfo -- | Module name extension is .mod. For some functions this can be -- also a wild card. type ModuleName = String type ModuleID = Int64 type ModuleSize = Int64 type ModuleIOMapSize = Int -- | Handle for traversing of modules. Only one module handle can be opened -- at a time so be careful to close them when not needed anymore. type ModuleHandle = Int type IOMapOffset = Int type IOMapLength = Int type IOMapData = [Word8] -- | Timeout exception for NXT IO operations. data TimeoutException TimoutException :: TimeoutException -- | A token used for exposed internal functions. data NXTInternals -- | Exception for NXT interface errors. Currently only one exception is -- defined which takes textual description as an argument. data NXTException NXTException :: String -> NXTException -- | 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. module Robotics.NXT.MotorControl -- | Starts MotorControl22.rxe program on the NXT brick. Program -- has to be uploaded/available on the NXT brick. startMotorControlProgram :: NXT () -- | Stops current running program on the NXT brick. Probably this means -- MotorControl22.rxe program on the NXT brick. stopMotorControlProgram :: NXT () -- | Interface to CONTROLLED_MOTORCMD command which takes care of -- precise motor movements. -- -- Requires dynamic/minimal pauses. controlledMotorCmd :: [OutputPort] -> OutputPower -> TachoLimit -> [MotorControlMode] -> NXT () data MotorControlMode -- | Keeps active brake on after the end of the movement. HoldBrake :: MotorControlMode -- | 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). SpeedRegulation :: MotorControlMode -- | Smoothly starts the movement. SmoothStart :: MotorControlMode -- | 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. resetErrorCorrection :: [OutputPort] -> NXT () -- | 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. isMotorReady :: [OutputPort] -> NXT [Bool] -- | Interface to CLASSIC_MOTORCMD command which is very similar -- to setOutputState but better interacts with -- MotorControl. -- -- Requires dynamic/minimal pauses. classicMotorCmd :: [OutputPort] -> OutputPower -> TachoLimit -> SpeedRegulation -> NXT () -- | 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). type SpeedRegulation = Bool instance Bounded MotorControlMode instance Enum MotorControlMode instance Eq MotorControlMode instance Ord MotorControlMode instance Read MotorControlMode instance Show MotorControlMode -- | A simple message-based control of the NXT brick via remotely executed -- program. The main goal of this approach is to reduce latency otherwise -- encountered when using NXT Bluetooth communication. Namely, changing -- the direction of communication takes around 30 ms. This means that one -- cycle of requesting motor status, receiving data and then sending -- motor control update takes at least 60 ms (it takes two changes of -- communication direction). And this is especially a problem if you want -- to control multiple motors at the same time (and built-in synchronize -- mechanism is not good enough for you). -- -- One solution to this problem is that Bluetooth is used only for -- communication in one direction and an additional program on the NXT -- brick is checking motor status and correcting possible errors. Of -- course this also means that information about motor position have to -- be obtained in some other way: by predicting from sent commands, or -- measuring/probing with regular NXT commands when there is time for -- that (and latency at that time is not a problem), or by using some -- external sensors attached to the controlling computer and not to the -- NXT brick (camera tracking system for example). -- -- Use NBC (http://bricxcc.sourceforge.net/nbc/) to compile basic -- NXC code (remote.nxc) included with this module into -- remote.rxe NXT program (or use already compiled version) and -- then upload it 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 less latency and more powerful control is possible. -- -- Check Robotics.NXT.MotorControl for another (more precise but -- more complex) approach to message-based control. It would be great to -- one day combine MotorControl's precision with API (especially -- interruptability) of remote.nxc. module Robotics.NXT.Remote -- | Starts remote.rxe program on the NXT brick. Program has to be -- uploaded/available on the NXT brick. startRemoteProgram :: NXT () -- | Stops current running program on the NXT brick. Probably this means -- remote.rxe program on the NXT brick. stopRemoteProgram :: NXT () -- | Sends a command to the remote.rxe program. Commands can be -- interrupted (or supplemented, for other motors) immediately by a next -- command. sendRemoteCommand :: RemoteCommand -> NXT () data RemoteCommand -- | Data type of remote command for specified output port(s). RemoteCommand :: [OutputPort] -> RemoteCommandType -> RemoteCommand data RemoteCommandType -- | Move specified motors for a given number of degrees at a given speed. MoveFor :: OutputPower -> TachoLimit -> RemoteCommandType -- | Set specified motors' position to a given offset in degrees from a -- zero position (it is assumed that motors are at zero position at -- remote.rxe program start, you can use -- resetMotorPosition to assure that, but probably not needed as -- the NXT brick resets things at program start) at a given speed. -- Probably not a good idea to mix SetTo and MoveFor on the -- same motor as MoveFor resets position. SetTo :: OutputPower -> TachoCount -> RemoteCommandType instance Eq RemoteCommandType instance Ord RemoteCommandType instance Read RemoteCommandType instance Show RemoteCommandType instance Eq RemoteCommand instance Ord RemoteCommand instance Read RemoteCommand instance Show RemoteCommand -- | This module defines an interface to CMPS-Nx digital compass -- sensor from http://www.mindsensors.com/ according to -- CMPS-Nx-V20-User-Guide.pdf documentation. module Robotics.NXT.Sensor.Compass -- | Initializes sensor on the given input port. It sets Mode to -- ResultInteger. csInit :: InputPort -> NXT () -- | Gets last measurement. Based on current Mode it return value in -- [0-255) (ResultByte mode) or [0-3600) (ResultInteger -- mode) range. csGetMeasurement :: InputPort -> NXT Measurement -- | Sets current mode of operation. csSetMode :: InputPort -> Mode -> NXT () data Mode -- | AutoTrig (continuous measuring) on. AutoTrigOn :: Mode -- | AutoTrig (continuous measuring) off. AutoTrigOff :: Mode -- | Result is a byte mapped to [0-255). ResultByte :: Mode -- | Result is an integer mapped to [0-3600). ResultInteger :: Mode -- | Sampling frequency 50 Hz (Europe standard). Frequency50 :: Mode -- | Sampling frequency 60 Hz (USA standard). Frequency60 :: Mode -- | Begin calibration mode. BeginCalibration :: Mode -- | End calibration mode. EndCalibration :: Mode -- | Reads software version string (V2.00). csGetVersion :: InputPort -> NXT String -- | Reads vendor ID string (mndsnsrs). csGetVendorID :: InputPort -> NXT String -- | Reads device ID string (CMPS). csGetDeviceID :: InputPort -> NXT String instance Bounded Mode instance Enum Mode instance Eq Mode instance Ord Mode instance Read Mode instance Show Mode -- | This module defines an interface to a digital ultrasonic sensor of the -- NXT kit. -- -- I2C communication with ultrasonics sensor is described in Lego -- Mindstorms NXT Hardware Developer Kit, Appendix 7 - Ultrasonic sensor -- I2C communication protocol. module Robotics.NXT.Sensor.Ultrasonic -- | Initializes sensor on the given input port. Default is -- ContinuousMeasurement mode. usInit :: InputPort -> NXT () -- | Gets last measurement for a given measurement number based on the -- current mode. To retrieve new SingleShot measurements first use -- usSetMode (with SingleShot as an argument) to send new -- ultrasonic ping and after approximately 20ms read the results. (Change -- of NXT Bluetooth communication direction takes around 30 ms.) In -- ContinuousMeasurement mode new measurements are made -- automatically based on the continuous measurement interval value. usGetMeasurement :: InputPort -> MeasurementNumber -> NXT (Maybe Measurement) -- | Helper function which gets all measurements available in order (closer -- first). usGetAllMeasurements :: InputPort -> NXT [Measurement] -- | Sets current mode of operation. usSetMode :: InputPort -> Mode -> NXT () -- | Gets current mode of operation. usGetMode :: InputPort -> NXT Mode data Mode -- | Turns sensor off. Off :: Mode -- | In this mode ultrasonic sensor only makes a new measurement every time -- this mode is set. The sensor measures distances for up to 8 objects (8 -- first echoes) which can be retrieved with usGetMeasurement. SingleShot :: Mode -- | In this mode the sensor continuously makes new measurement with the -- specific interval. This is the default mode. ContinuousMeasurement :: Mode -- | Within this mode the sensor will measure whether any other ultrasonic -- sensors are within the vicinity. With this information a program can -- evaluate when it is best to make a new measurement which will not -- conflict with other ultrasonic sensors. EventCapture :: Mode -- | Requests warm reset. WarmReset :: Mode -- | Sets current continuous measurement interval value. usSetContinuousInterval :: InputPort -> ContinuousInterval -> NXT () -- | Gets current continuous measurement interval value. usGetContinuousInterval :: InputPort -> NXT ContinuousInterval -- | Sets current (actual) zero value. This is used to calibrate sensor. usSetActualZero :: InputPort -> Zero -> NXT () -- | Gets current (actual) zero value. usGetActualZero :: InputPort -> NXT Zero -- | Sets current (actual) scale factor value. This is used to calibrate -- sensor. usSetActualScaleFactor :: InputPort -> ScaleFactor -> NXT () -- | Gets current (actual) scale factor value. usGetActualScaleFactor :: InputPort -> NXT ScaleFactor -- | Sets current (actual) scale divisor value. This is used to calibrate -- sensor. usSetActualScaleDivisor :: InputPort -> ScaleDivisor -> NXT () -- | Gets current (actual) scale divisor value. usGetActualScaleDivisor :: InputPort -> NXT ScaleDivisor -- | Reads software version string (V1.0). usGetVersion :: InputPort -> NXT String -- | Reads vendor ID string (LEGO). usGetVendorID :: InputPort -> NXT String -- | Reads device ID string (Sonar). usGetDeviceID :: InputPort -> NXT String -- | Reads factory zero value. usGetFactoryZero :: InputPort -> NXT Zero -- | Reads factory scale factor value. usGetFactoryScaleFactor :: InputPort -> NXT ScaleFactor -- | Reads factory scale divisor value. usGetFactoryScaleDivisor :: InputPort -> NXT ScaleDivisor -- | Reads measurement units string (10E-2m, a centimeter). usGetMeasurementUnits :: InputPort -> NXT String -- | Type of a zero value. type Zero = Int -- | Type of a scale factor value. type ScaleFactor = Int -- | Type of a scale divisor value. type ScaleDivisor = Int -- | Type of a continuous measurement interval value. This seems to be in -- the range 1-15. type ContinuousInterval = Int -- | Type of a measurement number. Sensor stores measurements (distances) -- for the first 8 echoes (numbered 0-7) it receives in SingleShot -- mode. For ContinuousMeasurement and EventCapture modes -- use first (0) measurement (distance) number. type MeasurementNumber = Int instance Bounded Mode instance Enum Mode instance Eq Mode instance Ord Mode instance Read Mode instance Show Mode