module NXT::Command::Output

An implementation of all the output related NXT commands:

This is used predominantly to interface with the servo-motor connectors that come prepackaged with NXT kits.

This class can also be used to talk to other third-party accessories connected in the output ports on the NXT brick.

Constants

COMMAND_IDENTIFIER
MODE

The mode enum. This is a list of possible values when setting the mode byte.

Reference: Appendix 2, Page 6

REGULATION_MODE

The regulation mode enum. This is a list of possible values when setting the regulation mode byte.

Reference: Appendix 2, Page 6

RUN_STATE

The run state enum. This is a list of possible values when setting the run state byte.

Reference: Appendix 2, Page 6

Public Instance Methods

command_type() click to toggle source
# File lib/nxt/commands/output.rb, line 86
def command_type
  COMMAND_TYPES[:direct]
end
output_state() click to toggle source
# File lib/nxt/commands/output.rb, line 106
def output_state
  # TODO: Parse this response and return hash or something similar.
  send_and_receive(COMMAND_IDENTIFIER[:get_output_state])
end
update_output_state(response_required: false) click to toggle source
# File lib/nxt/commands/output.rb, line 90
def update_output_state(response_required: false)
  # Pack this value into a 32-bit unsigned little-endian binary string,
  # then unpack it into 4 8 bit unsigned integer chunks. We are
  # converting the passed in value to a little endian, unsigned long
  # value.
  tacho_limit_as_bytes = [tacho_limit].pack('V').unpack('C4')

  send_and_receive(COMMAND_IDENTIFIER[:set_output_state], [
    power,
    MODE[mode],
    REGULATION_MODE[regulation_mode],
    0, # turn ratio
    RUN_STATE[run_state]
  ] + tacho_limit_as_bytes, response_required)
end