Module: NXT::Command::Output
- Extended by:
- Utils::Accessors
- Includes:
- Base
- Included in:
- NXT::Connector::Output::Motor
- Defined in:
- lib/nxt/commands/output.rb
Overview
An implementation of all the output related NXT commands:
-
setoutputstate
-
getoutputstate
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.
This class does not actually talk to the chosen interface for the NXT brick. Instead, it outputs messages in byte arrays ready to be serialised to the brick over the appropriate interface from within the Brick class.
Constant Summary collapse
- MODE =
The mode enum. This is a list of possible values when setting the mode byte.
Reference: Appendix 2, Page 6
{ # Motor will rotate freely. # NOTE: This is not documented in the Appendixes. coast: 0x00, # Turn on the specified motor. motor_on: 0x01, # Use run/brake instead of run/float in PWM. This means the voltage is # not allowed to float between PWM pulses, improving accuracy at the # expense of greater power usage. brake: 0x02, # Turns on the regulation. This is required when setting a regulation # mode setting. regulated: 0x04 }.freeze
- REGULATION_MODE =
The regulation mode enum. This is a list of possible values when setting the regulation mode byte.
Reference: Appendix 2, Page 6
{ # No regulation will be enabled. idle: 0x00, # Power control will be enabled on specific output. motor_speed: 0x01, # Synchronisation will be enabled. This requires two output ports to # have this enabled before it will work. motor_sync: 0x02 }.freeze
- RUN_STATE =
The run state enum. This is a list of possible values when setting the run state byte.
Reference: Appendix 2, Page 6
{ # Output will be idle. idle: 0x00, # Output will ramp-up to the desired speed. ramp_up: 0x10, # Output will be running. running: 0x20, # Output will ramp-down to the desired speed. ramp_down: 0x40 }.freeze
- @@command_type =
COMMAND_TYPES[:direct]
- @@command_identifier =
0x04
Instance Method Summary collapse
Methods included from Utils::Accessors
Instance Method Details
#set_output_state(response_required = false) ⇒ Object
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/nxt/commands/output.rb', line 85 def set_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 = [self.tacho_limit].pack('V').unpack('C4') @interface.send_and_receive([ @@command_type, @@command_identifier, port_as_byte(self.port), self.power, MODE[self.mode], REGULATION_MODE[self.regulation_mode], 0, # turn ratio RUN_STATE[self.run_state] ] + tacho_limit_as_bytes, response_required) end |