module Motor: sig .. end
Output ports.
type port
The three motor ports (immutable). For more readability of
your program, it is recommended you give appropriate aliases
to the ports of interest at the beginning of your program,
e.g. let motor_right = Mindstorm.Motor.a.
val a : port
The motor port A.
val b : port
The motor port B.
val c : port
The motor port C.
val all : port
Special value representing all 3 ports.
type regulation = [ `Idle | `Motor_speed | `Motor_sync ]
Regulation mode.
`Idle: No regulation will be enabled.
`Motor_speed: enable power control: auto adjust PWM duty
cycle if motor is affected by physical load.
`Motor_sync: enable synchronization: attempt to keep
rotation in sync with another motor. You typically use this
mode is to maintain a straight path for a vehicle robot
automatically. You also can use this mode with the
Mindstorm.Motor.state turn_ratio property to provide
proportional turning. You must set `Motor_sync on at
least two motor ports to have the desired affect. If it is
set on all three motor ports, only the first two (A and B)
are synchronized. .
type run_state = [ `Idle | `Ramp_down | `Ramp_up | `Running ]
Specifies how to perform the transition to the new
speed
given in
Mindstorm.Motor.state.
`Idle: The motor is not run.
`Running enables power to any output device connected to
the specified port(s).
`Ramp_up enables automatic ramping to a new speed
set-point that is greater than the current speed set-point.
When you use `Ramp_up in conjunction with appropriate
tach_limit and speed values, the NXT firmware attempts
to increase the actual power smoothly to the speed
set-point over the number of degrees specified by
tach_limit.
`Ramp_down enables automatic ramping to a new speed
set-point that is less than the current speed set-point.
When you use `Ramp_down in conjunction with appropriate
tach_limit and speed values, the NXT firmware attempts
to smoothly decrease the actual power to the speed
set-point over the number of degrees specified by
tach_limit.
type state = {
|
speed : int; |
|
motor_on : bool; |
|
brake : bool; |
|
regulation : regulation; |
|
turn_ratio : int; |
|
run_state : run_state; |
|
tach_limit : int; |
}
The absolute value of
speed is used as a percentage of the
full power capabilities of the motor. The sign of
speed
specifies rotation direction. You must set some other
properties appropriately for the
speed set-point to have the
desired effect:
motor_on must be true.
run_state must be set to a non-`Idle value.
If
not motor_on && not brake, motors are in COAST mode:
motors connected to the specified port(s) will rotate
freely.
val speed : ?tach_limit:int ->
?brake:bool -> ?sync:bool -> ?turn_ratio:int -> int -> state
speed s returns a state where speed is s, motor_on is
true if and only if s <> 0, and run_state
= `Running.
tach_limit : set the number of degrees to rotate.
The movement is unfortunately not fully accurate.
Default 0 which means "no limit".
brake : turns on brake. Default true.
sync : turn on `Motor_sync. Default false.
turn_ratio : set a turn-ratio. Default 0.
val set : ?check_status:bool ->
'a Mindstorm.conn -> port -> state -> unit
set conn p st sets the state of the motor connected to the
port p to st.
val get : 'a Mindstorm.conn ->
port -> state * int * int * int
get conn p returns
(state, tach_count, block_tach_count,
rotation_count) where
state is the current state of the motors;
tach_count is the number of counts since the last reset of the
motor counter (the reset occurs when Mindstorm.Motor.set is
issued);
block_tach_count is the current position relative to the
last programmed movement.
rotation_count is the program-relative position counter
relative to the last reset of the rotation sensor for motor p.
val reset_pos : ?check_status:bool ->
'a Mindstorm.conn -> ?relative:bool -> port -> unit
reset_pos conn p resets the rotation count (given by the
rotation_count field of
Mindstorm.Motor.get) of the motor
connected to port
p.
relative : if true, relative to the last movement,
otherwise absolute position. Default: false.