Send Encoder Value to SmartDashboard with profiledPIDsubsystem, New Command based ArmBot example

Hi CD -

I’m working through going from “Robot” to “Robot with Encoders” to “profiled Robot using Encoders”, using the new command framework and a Johnson Electric PLG set up with a linear actuator. The encoder feeds back into the RIO directly, and I am using a Spark Mini to control it over PWM.

When I was at “Robot with Encoders”, I had my subsystem set up to report the encoder value to SmartDashboard in the periodic() method of that subsystem.

public void periodic(){
  putNumber("EncoderX", m_encoder.getDistance());

Now that I move that subsystem over to ProfiledPIDSubsystem, the periodic() appears to have gone away, and even if I leave that periodic() in place I’m not getting encoder values on the dashboard.

Looking at the ArmBot example, where is a good place to make the robot report the encoder state to SmartDashboard?

I have tried setting the default command for the ProfiledPIDsubsystem in robotContainer to push the state to smartDashboard: I renamed periodic() to putMeasurement() and then tried to call it as either a new RunCommand or new InstantCommand. This crashed the program. What am I missing?

I don’t have code up in front of me, so take this with a grain of salt, but a ProfiledPIDSubsysten should still be a Sybsystem via inheritance, and therefore should still have a periodic method you could use.

Are you commenting that the example doesn’t show it, or that your editor doesn’t indicate that it exists?

1 Like

I added the following code to the ArmBot ArmSubsystem and ran in simulation and got updated encoder values in smart dashboard.

  public void periodic() {
    SmartDashboard.putNumber("Encoder", m_encoder.getDistance());

If you leave out the call to super.periodic(), the motor won’t ever move, because ProfiledPIDSubsystem updates the motor in periodic().

If you just want to see the encoder value, you can use the LiveWindow tab on shuffleboard, which is automatically updated, without needing to add any code.

1 Like

Thanks Joe! That makes sense, the missing super.periodic() is the key.

What’s a good way to get in and view the class, so I could catch something like this more easily?
I was clicking through the VSCode popups and found a link all the back to view the Command class that’s linked in the description of profiledPIDsubsystem, but couldn’t figure out how to view just the ProfiledPIDsubsystem class on its own, from VSCode…