Thoughts on COMBINING SubsystemBase and Subsystems?

Hello guys! As a new team, we’ve been trying to get trajectory path following working. We discovered that the online tutorials only work under SubsystemBase and CommandScheduler, but not Subsystem and Scheduler, which are unfortunately what we’ve been working on. We tried quite an effort to combine both code together hoping for the Robot to execute SubsystemBase autonomous for the path generator and Subsystem teleop for the rest of mechanisms. We tried, but the robot unfortunately didn’t work. We know it’s an interesting idea to have, but if possible, can you guys please tell us if this set up is not possible at all, or we are just having code errors? Thank you so much! Since I have a poor knowledge of github, I’ll post the code in the following sections. This is a crazy attempt, enjoy!

Please, please, if you’re going to post all of your code, use github or something similar. Even pastebin.com. And if you do post code directly next time, use a triple ’ so it shows up nicely.

It’s very hard to read the code you have right now and most people won’t jump through hoops to read your code. We do want to help, though.

3 Likes

Thank you! I’ll delete the replies and repost them on github

Thank you so much! I went through the tutorial and uploaded the code. The code are short, please ignore the limelight and PID portion. The interaction between the subsystem and subsystem base is interesting, though. Thank you so much for stopping by and for your time!

https://docs.wpilib.org/en/latest/docs/software/commandbased/subsystems.html#creating-a-subsystem

Fourth paragraph contains details on SubsystemBase; I would just stick with the default SubsystemBase that gets created when you make a new subsystem from the right-click options.

Thank you so much again! I’ll definitely try it out

Nvm it didn’t work out too great haha

So when you call getLeftPIDController, your drivetrain in Robot.java isn’t initialized. That’s why you’re getting a NullPointerException.

Can you initialize your drivetrain in RobotContainer or initialize your drivetrain before initializing RobotContainer? I think part of your code is trying to use something that’s not initialized yet.

Also, when using the command framework, it’s recommended to use dependency injection (passing variables through constructors instead of using static (global) variables)

I strongly recommend against combining both the old and new command frameworks on the same robot. Pick one and stick with it; if you really want to use the old framework with the new path following features, the best option is to re-implement RamseteCommand on top of the old framework.

Thank you so much! Since much of our code was coded with the new Subsystem framework, we prefer the new framework more. However, after we discovered the autoPathGenerator, the tutorials only showed how to make it work with the old SubsystemBase framework. Is there a way to implement the RamseteCommand on a Subsystem new framework (Scheduler)? Thank you again for your time! We are willing to read off tutorials if there’s any.

Got it! We’ll definitely fix them tomorrow. Hopefully it will work! Thank you so much.

You have it backwards; SubsystemBase is from the new framework, not the old framework.

1 Like

Got it! Do anyone of you guys think it’s possible to combine both the old framework and the new framework? I notice that the Scheduler and calling method are different (CommandScheduler & Periodic vs. Scheduler & Init). Will they interfere with each other when I try to call both of them separately? We only need autopathing for autonomous, so we are not really sure if we should spend more time on that. Please let us know if it’s structurally possible or not. Thank you so much for stopping by and have a great weekend!

It is possible, but it is a very bad idea and you should not do it.

2 Likes

Thank you so much guys! I combined the subsystemBase and the subsystem for the trajectory. The code is uploaded on github. However, it seems that setVoltage produces a incredibly small output of 0.5 which doesn’t even run the motors, so I change it to set. Other than that, the code functions (interaction works) but doesn’t update the speed (method fails). I suspected some bugs may still be around which I’ll elaborate more later. Feel free to take a look and leave some comments if you have good suggestions to the problem!

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