Encoder and Digital Input Error

We are currently trying to simply add encoders to our practice bot. All I’m trying to do is simply read the value they are outputting but I’m struggling to get that to work. Here is the code and the error we keep getting

Also, if the is anything I can do to make my the code “better” please let me know. This new command-based model is throwing me off a bit so any help would be nice. I really don’t know if I’m using the robotcontainer properly.

Thanks in advance for any help!

You’re instantiating an instance of the Drivetrain subsystem in both Robot.java and RobotContainer.java. You can only do this once, so you’ll probably want to remove it from Robot.java.

This documentation provides more overview details about the new Command Based framework: https://docs.wpilib.org/en/latest/docs/software/commandbased/structuring-command-based-project.html

Oh, that makes sense. That doesn’t seem to affect the encoders though. Before I added the encoder code it still drove with the instantiation in the drivetrain

As the error message you got indicates, it can’t instantiate multiple DigitalInput objects on the same port, which is what it was trying to do when you created multiple instances of the DriveTrain.

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.