Simple way to switch speeds mid match

My team wants a simple way to switch speed during a match

Multiply the speed you’re telling the motors to run by some number. For example, half speed would be motorSetpoint * 0.5.

1 Like

How would you put a button to that

if ( your button) {
m_rightStick.getX()*0.5} else {
m_rightStick.getX()},
if ( your button) {
-m_rightStick.getY()*0.5} else {
-m_rightStick.getY});
I’m trying to do it like this but it’s giving me syntax errors

1 Like

You have a comma between your conditional statements also a parentheses at the end. You should use code blocks when pasting code in the future it makes it easier to read

Here is a hypothetical for using a button to toggle in and out of a slow drive mode using Command-Based by scaling your joystick inputs.

m_drivetrain.setDefaultCommand(new ArcadeDrive(
    () -> m_controller.getRawAxis(ControlConstants.kDriveAxis),
    () -> m_controller.getRawAxis(ControlConstants.kRotateAxis),
    m_drivetrain
));

Trigger m_slowDrive = new Trigger(()->m_controller.getRawButton(ControlConstants.kSlowMode));
m_slowDrive.toggleOnTrue(new ArcadeDrive(
    () -> m_controller.getRawAxis(ControlConstants.kDriveAxis)*DriveTrainConstants.kSlowScalingFactor,
    () -> m_controller.getRawAxis(ControlConstants.kRotateAxis)*DriveTrainConstants.kSlowScalingFactor,
    m_drivetrain
));
1 Like

Would it be the same as dropping speed to be able to push robots when we go defensive

For increased torque to play defense you would need a shifting gearbox.

Only up to a point. Most drivetrains these days are traction limited even at fairly normal ratios and apart from running better wheels , there is no way to gain any additional useful torque.

1 Like

we do not want the torque part we would like something that can hold a tank drive robot without us spinning around them to keep them at a stop for a little bit and we were told to lower our speed and this would help us with that task

Jumping on this thread:

We want to slow down our drive in general - here’s what we have. We know how to slow down our other motors, just not the drive.

public void teleopPeriodic() {

m_myRobot.tankDrive(-m_DriverJoystick.getRawAxis(1), -m_DriverJoystick.getRawAxis(3));

if(m_DriverJoystick.getRawButton(6)){
  m_armMotor.set(0.5);
  m_armMotor2.set(0.5);
} else if(m_DriverJoystick.getRawButton(8)) {
  m_armMotor.set(-0.5);
  m_armMotor2.set(-0.5);
} else {
  m_armMotor.set(0);
  m_armMotor2.set(0);
}

if(m_DriverJoystick.getRawButton(5)){
  m_intakeMotor.set(0.75);
} else if(m_DriverJoystick.getRawButton(7)) {
  m_intakeMotor.set(-0.75);
} else {
  m_intakeMotor.set(0);
}

}

Is the response you are seeing too jittery to control effectively?

If so, you can do a couple of things. One is multiplying your joystick values by a percentage (0.7 for 70% max speed) however this isn’t ideal because you are taking away possible motor power.

Another option would be using a SlewRateLimiter, which you can google and read the WPILib explanation for. It is going to limit how fast your motors can accelerate

We just want to slow it down since our drivers are pretty new to FRC and we want them to have more control over the robot. We don’t mind losing a bit of motor power since our bot is quite small and light. What would that look like?

Replace
m_myRobot.tankDrive(-m_DriverJoystick.getRawAxis(1), -m_DriverJoystick.getRawAxis(3));
with
m_myRobot.tankDrive(-m_DriverJoystick.getRawAxis(1) * 0.7, -m_DriverJoystick.getRawAxis(3) * 0.7);
Or replace 0.7 with whatever maximum percent speed you would like.

1 Like

Thank you!

3 Likes

This was my team’s code. I thought the filter really added a lot.

  //this gain is the drive wheel speed gain
  gainTgt = 0.25;      //normal driving
  if (leftBumper) {
     gainTgt = 0.8;       //fast driving
  } else if (rightBumper) {
     gainTgt = 0.1;     //slow driving
  }
  gain = prevGain + (0.025*(gainTgt - prevGain));  //filter
  prevGain = gain;

Assuming you’re using KoP wheels, switching to something like blue nitrile or another type of traction wheel would probably help a lot.

You can also use @Ether’s method to make the joystick less sensitive at low speeds (meaning less jerky) while still maintaining full power capability. With the this method, you don’t even need a switch - and the simple version doesn’t even need an if statement.

paper: joystick sensitivity (gain) adjustment - CD-Media: Papers - Chief Delphi

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