pic: Odd Sensor Readings



This weekend I experimented with data logging, and got some odd results. The cycles were about 20ms apart, which is correct. Yet the sensor readings from the TalonSRX’s gave identical outputs for approximately 100ms at a time. Is there something fundamental I’m missing, like making an internal call too often? Is this normal behavior for 50hz data? Is there a resource lock internal to the SRX (similar to the PDP), where I shouldn’t log everything every cycle?

  @Override
  public void update(double pNow) {
    data.drivetrain.meta().setTimestamp(pNow);
    set(TIME_SECONDS, Timer.getFPGATimestamp());
    set(LEFT_POSITION_ROT, (double)mLeftMaster.getEncPosition());
    set(RIGHT_POSITION_ROT,(double)mRightMaster.getEncPosition());
    set(LEFT_VELOCITY_RPM, (double)mLeftMaster.getEncVelocity());
    set(RIGHT_VELOCITY_RPM, (double)mRightMaster.getEncVelocity());
    
    set(LEFT_TALON_MASTER_CURRENT, mLeftMaster.getOutputCurrent());
    set(LEFT_TALON_MASTER_VOLTAGE, mLeftMaster.getOutputVoltage());
    set(LEFT_TALON_FOLLOW_CURRENT, mLeftFollow.getOutputCurrent());
    set(LEFT_TALON_FOLLOW_VOLTAGE, mLeftFollow.getOutputVoltage());

    set(RIGHT_TALON_MASTER_CURRENT, mRightMaster.getOutputCurrent());
    set(RIGHT_TALON_MASTER_VOLTAGE, mRightMaster.getOutputVoltage());
    set(RIGHT_TALON_FOLLOW_CURRENT, mRightFollow.getOutputCurrent());
    set(RIGHT_TALON_FOLLOW_VOLTAGE, mRightFollow.getOutputVoltage());
    
    
    set(TALON_VBUS, (mLeftMaster.getBusVoltage() + mRightMaster.getBusVoltage())/2);

    mLeftMaster.set(get(DESIRED_LEFT_POWER) * -1);
    mRightMaster.set(get(DESIRED_RIGHT_POWER));
    gearShifter.set(data.drivetrain. isSet(IS_SHIFT));
    if(data.driverinput.isSet(ELogitech310.BACK)) {
      resetEncoders();
    }
  }

We ran into this same problem last year. If I’m remembering correctly, the solution was to use the setStatusFrameRateMs() method in our java code to change the update frequency of sensor readings to the CAN bus. Not sure how or why they arrived at the 100 ms frame rate as the default for a lot of the information, but it could have something to do with overloading the system.

Refer to section 20.5, see if that helps:

Thanks Carl! That looks promising. I’ll check it out in a bit.

The Feedback Status frame (getPosition() / getVelocity() with unit scaling applied for the selected sensor) uses uses 20ms periods by default. The quadrature status frame (getEnc*()) uses 100ms.

Basically you’re running into the different default frame timings.

getEncVelocity and getEncPosition come from the Quadrature Status Frame, which by default is sent ever 100 ms. If you select the sensor as the feedback device and use getPosition and getVelocity, that’ll come from the Feedback Status Frame which has a period of 20 ms.

For your current logging, it should be 20 ms already as that is in the Feedback Status frame.

For your reference, this is section 20 in the Talon SRX Software Manual.

Yep, that did it! These are quadrature encoders, so it was set to 100ms. Turns out these are the very first SRX’s we purchased (2015-ish?), so they also needed a firmware update.

Thanks again!