module Ultrasonic:Ultrasonic sensor. Convenience functions to interact with the ultrasonic sensor through the I2C protocol.sig
..end
type
t
val make : 'a Mindstorm.conn -> Mindstorm.Sensor.port -> t
make conn port
initialize the sensor on port port
as
being an ultrasonic one.val set : ?check_status:bool ->
t ->
[ `Event
| `Meas
| `Meas_cont
| `Meas_interval of int
| `Off
| `Reset
| `Scale_div of int
| `Scale_mul of int
| `Zero of int ] -> unit
Ultrasonic.set us cmd
set the state or parameters for the
ultrasonic sensor us
. cmd
may be:
`Off
: turns the ultrasonic sensor off.`Meas
: single shot command. In this mode, the
ultrasonic sensor will only make a new measurement every
time the command byte is send to the sensor. The sensor
will measure distances for up to 8 objects and save the
distances within the `Byte0
.. `Byte7
variables.`Meas_cont
Continuous measurement command. This is the
default mode, where the sensor continuously makes new
measurement with the specified interval (see
`Meas_interval
below).`Event
: Event capture command. 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.`Meas_interval t
: set continuous measurment interval.`Zero z
: set the actual zero.`Scale_mul m
: set the actual scale factor.`Scale_div d
: set the actual scale divisor.`Reset
: resets the ultrasonic sensor.check_status
: check the return status. Exceptionally,
the default is true
because the sensor needs to time to
set itself up anyway and this avoids Mindstorm.Buffer_full
errors if we try to get values from the sensor.val get : t ->
[ `Byte0
| `Byte1
| `Byte2
| `Byte3
| `Byte4
| `Byte5
| `Byte6
| `Byte7
| `Meas_interval
| `Scale_div
| `Scale_mul
| `Zero ] -> int
Ultrasonic.get us var
returns the content of the variable
var
on the sensor (detailed underneath). All values are
between 0 and 255. Communication errors will be reported by
raising Error Bus_error
; your application should be ready
to handle such exceptions.
`Byte0
.. `Byte7
are the 8 variables containing the
distances measured with the `Meas
or `Meas_cont
command
(in centimeters).`Meas_interval
returns the interval (in 0.01 sec)
between two consecutive measurments when the sensor is in
continuous measurment (command `Meas_cont
).`Zero
returns the value of the actual zero (settable
with the `Zero
command).`Scale_mul
(resp. `Scale_div
) return the current
scaling factor (resp. divisor). It is settable with the
`Scale_mul
(resp. `Scale_div
) command.val get_state : t ->
[ `Event | `Meas | `Meas_cont | `Off | `Reset ]
get_state us
get the current state of the ultrasonic
sensor us
.