Module Mindstorm.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
| `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.


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.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.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.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.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.Sensor.set.
val reset_scaled : ?check_status:bool -> 'a Mindstorm.conn -> port -> unit
reset_scaled conn port
check_status : whether to check the status returned by the brick. Default: see Mindstorm.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.conn -> port -> int
get_status conn port returns the number of bytes ready to be read.
val write : ?check_status:bool ->
'a Mindstorm.conn ->
port -> ?rx_length:int -> string -> unit
write conn port data writes 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.connect_bluetooth.
rx_length : gives the number of bytes to receive. Default: 0 i.e. no answer expected.
val read : 'a Mindstorm.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.