Thrifty Nova
  • Software Resources
    • Getting Started
    • Configure Controller Settings
      • Factory Default
      • Motor Type - Minion Setting
      • Inverting the Motor
      • Brake Mode
      • Maximum Output
      • Ramp Up/Ramp Down
      • Current Limiting
      • Soft Limits
      • Hard Limits
      • Setting Encoder Position
      • Follower Mode
    • Configure Onboard PID
    • Configure CAN Frequency
    • IO Signal Management
    • Set Output
    • Logging
    • Get Feedback
    • Unit Conversions
    • Subsystem Examples
      • Simple Elevator Example
      • Swerve Module Example
      • Simple Arm Example
  • Electrical Resources
    • Wiring the Thrifty Nova
    • LED Color Codes
    • Brushless Hall Sensor Connector
    • USB Communications
    • 10 Pin Data Connector
      • Intro to Sensors
      • Sensor Hat
      • Motor Runner Board
    • Hard Reset
  • Mechanical
    • Mounting Options
  • Software Releases
    • Software Releases
  • Thrifty Config
    • Thrifty Config Demo Video
Powered by GitBook
On this page
  • IO and Signal Management for ThriftyNova
  • Overview
  • Understanding IO States
  • IO State Methods
  • Encoder Position Handling
  • Best Practices for IO Signal Usage
  • Quick Tips for Encoder and IO Usage

Was this helpful?

Export as PDF
  1. Software Resources

IO Signal Management

IO and Signal Management for ThriftyNova

Overview

The ThriftyNova controller provides comprehensive access to input/output signals and status information. These features allow you to monitor limit switches, encoder indexes, and other digital signals to coordinate robot actions effectively.

Understanding IO States

The ThriftyNova tracks six digital input signals that can be accessed individually or as a group. Each represents a different signal available on the controller's inputs.

IO State Methods

Getting the Complete IO State

/**
 * Gets the complete IO state of the motor controller as a boolean array.
 * 
 * 
 * @return An array of boolean values representing the state of each IO signal.
 */
public boolean[] getIOState() { ... }

The boolean array returned by the getIOState method provides the current state of each digital input on the motor controller. Here's a breakdown of each index:

  • Index 0: Represents the state of the forward limit switch (FWD_LIMIT).

  • Index 1: Corresponds to the quadrature encoder index (QUAD_INDEX).

  • Index 2: Indicates the state of the reverse limit switch (REV_LIMIT).

  • Index 3: Reflects the alternate quadrature index (ALT_QUAD_INDEX).

  • Index 4: Signifies the status of the quadrature encoder A signal (QUAD_A).

  • Index 5: Represents the quadrature encoder B signal (QUAD_B).

Example Usage:

boolean[] ioStates = motor.getIOState();
if (ioStates[0]) {
    // Forward limit switch is active
    // Take appropriate action
}

Individual IO Signal Access

/**
 * Gets the forward limit switch state.
 * 
 * <p>This method provides a BooleanSupplier that can be used in conditions or
 * passed to other WPILib components that accept suppliers.</p>
 * 
 * @return A BooleanSupplier that returns true when the forward limit switch is active.
 */
public BooleanSupplier getForwardLimit() { ... }

/**
 * Gets the reverse limit switch state.
 * 
 * @return A BooleanSupplier that returns true when the reverse limit switch is active.
 */
public BooleanSupplier getReverseLimit() { ... }

Example Usage:

// Using in a condition
if (motor.getForwardLimit().getAsBoolean()) {
    // Forward limit is activated
}

// With Command-based framework
new ConditionalCommand(
    new StopCommand(),
    new MoveCommand(),
    motor.getForwardLimit()
);

Analog Input Support

The ThriftyNova includes support for analog input sensors through a 12-bit ADC (Analog-to-Digital Converter). This provides 4096 discrete levels of resolution, making it suitable for a wide range of analog sensors including potentiometers, distance sensors, and analog absolute encoders. The analog input can be used for position feedback or other sensor applications where continuous variable measurement is required.

/**
 * Gets the analog input reading from the sensor connected to the analog input port.
 * 
 * <p>The ThriftyNova uses a 12-bit ADC, providing values from 0-4095.</p>
 * 
 * @return The current analog reading (0-4095)
 */
public int getAnalogInput() { ... }

/**
 * Gets the analog input reading scaled to a position value.
 * 
 * <p>This can be used when an analog sensor (like a potentiometer) is being
 * used as a position feedback device.</p>
 * 
 * @return The position value derived from the analog input
 */
public double getPositionAnalog() { ... }

Encoder Signal Access

The ThriftyNova also exposes encoder signals as digital inputs. These are primarily intended for monitoring the state of the encoder lines, not for position or velocity tracking.

Note: For tracking encoder position and velocity, use the dedicated methods like getPosition() and getVelocity() rather than these boolean suppliers. These methods provide the actual encoder values that should be used for control and feedback.

/**
 * Gets the quadrature encoder index pulse state.
 * 
 * <p>The index pulse is a reference marker that occurs once per revolution in many
 * quadrature encoders. It is generally saved between power cycles on absolute encoders</p>
 * 
 * @return A BooleanSupplier that returns true when the quadrature index pulse is detected.
 */
public BooleanSupplier getQuadIndex() { ... }

/**
 * Gets the alternate quadrature encoder index state.
 * 
 * @return A BooleanSupplier that returns true when the alternate quadrature index is detected.
 */
public BooleanSupplier getAltQuadIndex() { ... }

/**
 * Gets the quadrature encoder A channel state.
 * 
 * @return A BooleanSupplier that returns true when the quadrature A signal is high.
 */
public BooleanSupplier getQuadA() { ... }

/**
 * Gets the quadrature encoder B channel state.
 * 
 * @return A BooleanSupplier that returns true when the quadrature B signal is high.
 */
public BooleanSupplier getQuadB() { ... }

Encoder Position Handling

The ThriftyNova supports multiple types of position feedback:

  • Internal encoder (built into brushless motors like the NEO)

  • Quadrature encoder (external)

  • Absolute encoder (external)

Each type has specific methods to access their position values:

/**
 * Gets the position from the currently selected encoder type.
 * 
 * <p>This method returns position data from whichever encoder type was set
 * with the {@code useEncoderType()} method.</p>
 * 
 * @return The current position in encoder ticks.
 */
public double getPosition() { ... }

/**
 * Gets the internal encoder position value.
 * 
 * <p>For NEO motors, this represents the position of the motor in ticks,
 * regardless of which encoder type is selected for control.</p>
 * 
 * @return The internal encoder position in ticks.
 */
public double getPositionInternal() { ... }

/**
 * Gets the quadrature encoder position.
 * 
 * <p>Returns the position from an external quadrature encoder connected
 * to the ThriftyNova's encoder inputs.</p>
 * 
 * @return The quadrature encoder position in ticks.
 */
public double getPositionQuad() { ... }

/**
 * Gets the absolute encoder position.
 * 
 * <p>Returns the position from an external absolute encoder (like a REV Through Bore Encoder)
 * connected to the ThriftyNova's encoder inputs.</p>
 * 
 * @return The absolute encoder position in ticks.
 */
public double getPositionAbs() { ... }

Best Practices for IO Signal Usage

Integrating IO Signals With WPILib

The ThriftyNova's IO methods return BooleanSuppliers, making them compatible with WPILib's Command-based programming. You can use these directly in conditionals or pass them to commands.

// Stop the motor when the forward limit is reached
new RunCommand(() -> motor.set(0.5))
    .until(motor.getForwardLimit());

// Or use with a trigger
new Trigger(motor.getForwardLimit())
    .onTrue(new InstantCommand(() -> System.out.println("Limit reached!")));

Efficiently Polling IO Signals

Like other status frames, you can control how frequently IO data is sent over the CAN bus. If you're using limit switches for critical safety stops, you'll want a higher polling rate, but if you're just using them for homing sequences, you can use a lower rate.

Consider how your robot uses these signals:

  • For emergency stops or critical limits: 10-20ms (50-100Hz)

  • For position reference or homing: 50-100ms (10-20Hz)

  • For diagnostic information only: 200-250ms (4-5Hz)

Remember that IO states are included in the current frame, so you can control their update rate using motor.canFreq.setCurrent().

// Configure polling rates based on your needs
motor.canFreq
    .setCurrent(0.01)       // Poll internal encoder at 100Hz

Quick Tips for Encoder and IO Usage

  1. For mechanisms with hard stops (like an arm or elevator):

    • Use limit switches connected to ThriftyNova inputs

    • Check limit switch states with getForwardLimit() and getReverseLimit()

    • When a limit is reached, zero your encoder with setEncoderPosition(0)

  2. For tracking mechanisms through full rotations:

    • External encoders often provide more precision than internal encoders

    • Use getQuadIndex() to detect when an encoder passes its index pulse

    • This can be used to know when a full rotation has occurred

  3. Remember that digital inputs can be used for more than just limit switches:

    • Connect beam break sensors to detect game pieces

    • Use proximity sensors for position detection

    • Implement end-of-travel detection for moving mechanisms

PreviousConfigure CAN FrequencyNextSet Output

Last updated 2 months ago

Was this helpful?