During auton the motor is supposed to run continuously but it stutters, it runs barely stops runs barely, ect.
It sounds like two commands are fighting for control. Make sure your default and auto commands declare their subsystem requirements correctly.
We can help more if you can post a link to your code, say on GitHub.
I dont really think they should be fighting but maybe im not the greatest at coding heres the git
See Jerky wheels with DifferentialDrive in autonomous
You need to âfeedâ the differential drive when you directly set motor speeds in auto
⌠but it looks like youâre always going through your drivetrainâs arcadeDrive()
, not trying to directly set the left/right motor, so thatâs not it, unless maybe you do see âmotor safetyâ warnings?
If itâs not that, then youâre likely running multiple commands at the same time.
Youâre calling arcadeDrive with joystick values from the periodic of your drive subsystem. You should be doing this using a default command instead.
Sorry itâs not the driveTrain itâs the SparkMax aka liftSpark if you look into 2BallAuton thatâs what Iâm working on
If the setpoint is higher than the position, then the MoveToPosition command will alternately set the power and stop the motor. This will make the motion jerky, but only in one direction.
So remove the greater than?
Maybe like this:
// Check encoder value
if(liftEncoder.getPosition() >= setpoint)
// If the encoder is going to pass the setpoint, stop the motor
liftSpark.stopMotor();
else
liftSpark.set(power);
So either move or stop, but donât move & stop at the same time
But then you would not be able to move âbackâ once you hit the limit.
So maybe something like this:
// Check encoder value when moving 'up' to prevent running too high
if (power > 0 && liftEncoder.getPosition() >= setpoint)
// If the encoder is going to pass the setpoint, stop the motor
liftSpark.stopMotor();
else
// always OK to move 'down' or 'up' while below limit
liftSpark.set(power);
I think that if youâre already moving to commands to make your robot work, it would be worth the investment to just have your teleop be command-based as well.
I think it will greatly reduce the amount of guessing and troubleshooting you have to do to make your robot work.
The only real issue I saw in a brief look at your 2 ball Auto sequence command is that your moveToSetpoint command never finishes. So your sequence will actually never run all the way through because your first command will block it from continuing on.
How would i fix that. I donât know much about commands.
Probably not a good idea to try and do it before youâre done competing this year, but the core of it is to break your robotâs functionality into Subsystems, and Subsystems are driven to do things through commands.
The nice thing about this paradigm is that it allows a more novice programmer to do perform more complicated actions.
You can take a look at our schoolâs code, we keep it open source.
Here for example is a single command defined as a shooting sequence that interacts with a couple different subsystems.
The nice thing about this setup, is if you look at the RobotContainer.java file, specifically the configureButtonBindings() method, youâll see that we bind three different button presses (A, B, Y) on the controller to perform that same shooting sequence from three different spots on the field.
Iâm not saying our code is the best way to code, or that there arenât other ways to do the same thing. The point Iâm making about Command-based things simplifying complex robot interactions is that once we got that command to work well for shooting the ball one time, it became next-to-zero effort to give our drivers multiple control options that performed similar actions (like shoot reliably from multiple places on the field).
Iâve got like half the controls based off commands itâs just at the beginning of coding this Iâd only ever done timed so I was learning as I was doing.
The most important piece of good Command-Based code is understanding the scheduler.
Key parts there are:
- The Subsystem default command is the command scheduled to run, when no other command is scheduled to run for that subsystem."
- Commands are typically instantiated, just one time. There is only one instance of a given command, (e.g. when you bind it to a controller button). That command is going to be scheduled to run multiple times. Pay attention to the state of things you need to do in the initialize method to set things up, the execute->isFinished loop, and terminate your command safely by doing stuff in the end() methods of your commands.
- You can view what commands are scheduled and running by using shuffleboard, smartdashboard, or glass.
After that, itâs just getting your commands scheduled to the proper triggers (like button presses).
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.