package mindstorm

  1. Overview
  2. Docs

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 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.

The motor port A.

val b : port

The motor port A.

The motor port B.

val c : port

The motor port B.

The motor port C.

val all : port

The motor port C.

Special value representing all 3 ports.

type regulation = [
  1. | `Idle
  2. | `Motor_speed
  3. | `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 = [
  1. | `Idle
  2. | `Ramp_up
  3. | `Running
  4. | `Ramp_down
]

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. .

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 = {
  1. speed : int;
    (*

    Power set-point. Range: -100 .. 100. Values larger than 100 will be taken as 100 and values less than -100 will be takes as -100.

    *)
  2. motor_on : bool;
    (*

    if true, turns the motor on: enables pulse-width modulation (PWM) power according to speed.

    *)
  3. brake : bool;
    (*

    Use run/brake instead of run/float. "Braking" in this sense means that the output voltage is not allowed to float between active PWM pulses. Electronic braking improves the accuracy (and is necessary to see a rotation at small speeds) of motor output, but uses slightly more battery power.

    *)
  4. regulation : regulation;
    (*

    Turns on the chosen regulation.

    *)
  5. turn_ratio : int;
    (*

    Range: -100 .. 100. See Mindstorm.Motor.regulation.

    *)
  6. run_state : run_state;
  7. tach_limit : int;
    (*

    Number of degrees to rotate; 0: run forever. Range: 0 .. 4294967295 (unsigned 32 bits). See also Mindstorm.Motor.run_state.

    *)
}

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.

  • parameter tach_limit

    set the number of degrees to rotate. The movement is unfortunately not fully accurate. Default 0 which means "no limit".

  • parameter brake

    turns on brake. Default true.

  • parameter sync

    turn on `Motor_sync. Default false.

  • parameter turn_ratio

    set a turn-ratio. Default 0.

val set : ?check_status:bool -> 'a conn -> port -> state -> unit

set conn p st sets the state of the motor connected to the port p to st.

val get : 'a 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 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.

  • parameter relative

    if true, relative to the last movement, otherwise absolute position. Default: false.

OCaml

Innovation. Community. Security.