Skip to content

dhiebert-whs/Challenge-4.4

Repository files navigation

Challenge 4.4: Switch Between Tank and Arcade Drive with Button

Category: Drivetrain

Robot Base

  • Required Robot: Testbed (Differential Drive)

Overview

This challenge introduces dynamic control scheme switching, allowing drivers to choose between tank drive and arcade drive during operation. Understanding how to implement multiple drive modes gives students flexibility in control schemes and teaches important concepts about command switching, state management, and driver preferences. This is commonly used in competition robots where different drivers prefer different control schemes or different game situations call for different driving styles.

Challenge Description

Create a drivetrain system that can switch between tank drive and arcade drive control schemes using a button press. The robot should start in one mode (your choice) and seamlessly switch to the other mode when a designated button is pressed. The current drive mode should be displayed on the SmartDashboard so the driver knows which control scheme is active.

Required Hardware

Testbed Robot

  • Motors:
    • Front Left Motor: TalonSRX (CAN ID: 20)
    • Back Left Motor: VictorSPX (CAN ID: 21)
    • Front Right Motor: TalonSRX (CAN ID: 22)
    • Back Right Motor: VictorSPX (CAN ID: 23)
  • Controller: Xbox Controller (Port: 0)
  • Encoders:
    • Front Left: DIO ports 0, 1
    • Back Left: DIO ports 2, 3
    • Front Right: DIO ports 4, 5
    • Back Right: DIO ports 6, 7

Implementation Steps

  1. Create a DrivetrainSubsystem that extends SubsystemBase with both left and right MotorControllerGroups
  2. Configure all motor controllers with proper settings (brake mode, voltage compensation, inversions)
  3. Create a DifferentialDrive object to handle the drive calculations
  4. Create two separate command classes: TankDriveCommand and ArcadeDriveCommand
  5. Implement both commands to read appropriate joystick inputs and control the drivetrain
  6. Add a boolean variable to track the current drive mode in RobotContainer
  7. Create a button binding that toggles between the two drive commands
  8. Add telemetry to display the current drive mode on SmartDashboard
  9. Set an initial default command for the drivetrain

Success Criteria

  • Robot drives using tank drive (left stick controls left side, right stick controls right side)
  • Robot drives using arcade drive (left stick Y-axis for speed, right stick X-axis for rotation)
  • Button press seamlessly switches between the two control modes
  • Current drive mode is clearly displayed on SmartDashboard
  • No jerky movements or unexpected behavior when switching modes
  • Both control schemes feel responsive and intuitive

Hints and Troubleshooting

  • For Step 1: Create a subsystem with private final MotorControllerGroup leftMotors; and private final MotorControllerGroup rightMotors;. Group the front and back motors for each side. Example: leftMotors = new MotorControllerGroup(frontLeft, backLeft);
  • For Step 2: Set each motor to brake mode using motor.setNeutralMode(NeutralMode.Brake);. Set voltage compensation with motor.configVoltageCompSaturation(12.0);. Remember to invert the right side motors.
  • For Step 3: Initialize with private final DifferentialDrive drive = new DifferentialDrive(leftMotors, rightMotors);. This handles the math for both tank and arcade drive.
  • For Step 4: Create two command classes that extend CommandBase. Each should require the drivetrain subsystem in their constructor using addRequirements(drivetrain);
  • For Step 5: In TankDriveCommand, use drivetrain.tankDrive(leftStick, rightStick);. In ArcadeDriveCommand, use drivetrain.arcadeDrive(speed, rotation);. Apply deadbands with MathUtil.applyDeadband().
  • For Step 6: In RobotContainer, add private boolean isTankDrive = true; to track the current mode.
  • For Step 7: Use driverController.a().onTrue(Commands.runOnce(() -> toggleDriveMode())); Create a toggleDriveMode() method that switches the default command using drivetrainSubsystem.setDefaultCommand().
  • For Step 8: In the drivetrain's periodic() method, use SmartDashboard.putString("Drive Mode", isTankDrive ? "Tank Drive" : "Arcade Drive");
  • For Step 9: In configureDefaultCommands(), set the initial drive command based on your starting mode.
  • Common Issue: If switching feels jerky, ensure both commands apply the same deadband values and consider adding a small delay or ramping.
  • Common Issue: If the drive mode display doesn't update, make sure you're updating the boolean variable in RobotContainer and accessing it from the subsystem's periodic method.

Challenge Extensions

  • Smooth Transitions: Add ramping or filtering to make the transition between drive modes smoother when switching mid-motion.
  • Mode Memory: Store the last used drive mode in Preferences so it persists between robot power cycles.
  • Visual Feedback: Use different LED colors or patterns to indicate the current drive mode in addition to SmartDashboard display.
  • Speed Scaling: Add different maximum speed multipliers for each drive mode (e.g., tank drive at 100%, arcade drive at 80%).
  • Advanced Controls: Add a third mode that uses differential steering (single joystick controls both speed and steering simultaneously).
  • Driver Profiles: Create multiple driver profiles where each profile has a preferred drive mode and automatically switches when that driver takes control.

Learning Resources

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages