Module Mindstorm_NXT.Sensor

module Sensor: sig .. end
Input ports.

The NXT brick also accepts the sensors for the previous version of the mindstorm brick, called RCX, so several options refer to RCX.


type t 
type port = [ `S1 | `S2 | `S3 | `S4 ] 
The four sensor ports, labeled 1 to 4 on the brick. It is recommended you give meaningful names to values of type port through let bindings.
type sensor_type = [ `Angle
| `Color_blue
| `Color_full
| `Color_green
| `Color_none
| `Color_red
| `Custom
| `Highspeed
| `Light_active
| `Light_inactive
| `Lowspeed
| `Lowspeed_9v
| `No_sensor
| `Reflection
| `Sound_db
| `Sound_dba
| `Switch
| `Temperature ]
Sensor type for a port. The sensor type primarily affects scaling factors used to calculate the normalized sensor value `Raw, but some values have other side effects.

The LEGO® NXT 2.0 (8547) includes a color sensor with a tri-color led. The following values allow to configure it. If you have an older brick, this may require that you update its firmware. Todo it under Linux, you can issue the command ./fwflash path_to_firmware.rfw (as root) where fwflash comes from libnxt. The firmware 1.28 can be dowloaded from http://legoengineering.com/library/doc_details/250-nxt-firmware-v128.html


type mode = [ `Angle_steps
| `Bool
| `Celsius
| `Fahrenheit
| `Pct_full_scale
| `Period_counter
| `Raw
| `Slope_mask
| `Transition_cnt ]
Sensor mode.
val set : ?check_status:bool ->
'a Mindstorm_NXT.conn ->
port ->
sensor_type -> mode -> unit
set conn p ty m set the sensor connected to port p to type ty and mode m.
check_status : whether to check the status returned by the brick. Default: see Mindstorm.NXT.connect_bluetooth.
type data = {
   sensor_type : sensor_type;
   mode : mode;
   valid : bool; (*true if new data value should be seen as valid*)
   raw : int; (*Raw A/D value. Device dependent. Range: 0 .. 1023*)
   normalized : int; (*Normalized A/D value. Range: 0 .. 1023*)
   scaled : int; (*Scaled value. Its range depend on the Mindstorm.NXT.Sensor.mode chosen:
  • `Raw: 0 .. 1023
  • `Boolean: 0 or 1
  • `Transition_cnt: 0 .. 65535
  • `Period_counter: 0 .. 65535
  • `Pct_full_scale: 0 .. 100
  • `Celsius: -200 .. 700 (10th of degree Celsius)
  • `Fahrenheit: -400 .. 1580 (10th of degree Fahrenheit)
  • `Angle_steps: 0 .. 65535
*)
}
Data read from sensors.
val get : 'a Mindstorm_NXT.conn ->
port -> data
get conn p returns the data read on port p. Before using this function, you must set the sensor type with Mindstorm.NXT.Sensor.set.
val color_of_data : data ->
[ `Black | `Blue | `Green | `Red | `White | `Yellow ]
Returns the color seen by the color sensor from its reading. This is usually only accurate at a distance of about 1cm.
Raises Invalid_argument if not applied to a `Color_full sensor.
val reset_scaled : ?check_status:bool ->
'a Mindstorm_NXT.conn -> port -> unit
reset_scaled conn port
check_status : whether to check the status returned by the brick. Default: see Mindstorm.NXT.connect_bluetooth.

Low speed



Commands dealing with the I2C bus available on every digital sensor. (The port number 4 may also be high speed.)
val get_status : 'a Mindstorm_NXT.conn -> port -> int
get_status conn port returns the number of bytes ready to be read.
val write : ?check_status:bool ->
'a Mindstorm_NXT.conn ->
port -> ?rx_length:int -> string -> unit
write conn port yx_data writes tx_data to lowspeed I2C sensor connected to the port. This is the protocol (e.g. for talking to the ultrasonic sensor). Communication errors will be reported by raising Error Bus_error; your application should be ready to handle such exceptions.
check_status : whether to check the status returned by the brick. Default: see Mindstorm.NXT.connect_bluetooth.
rx_length : gives the number of bytes to receive. Default: 0 i.e. no answer expected.
val read : 'a Mindstorm_NXT.conn -> port -> string
Read data from from lowspeed I2C port (e.g. for receiving data from the ultrasonic sensor). Communication errors will be reported by raising Error Bus_error; your application should be ready to handle such exceptions.

Convenience


module Ultrasonic: sig .. end
Ultrasonic sensor.