Challenge- Modify the XRPDrivetrain!

Test your skills by modifying the XRPDrivetrain for your robot.

As the challenge name suggests, you'll be modifying your XRPDrivetrain class! You will move the robot around using the two XRPMotors attached onto the side.

circle-info

We are deliberately not using DifferentialDrive() and arcadeDrive() to practice using these motors.

Write a GetInstance() Method

Your code should:

chevron-rightSample Codehashtag
/* class header */
/* This is what I alluded to in Hint #1. */
private static XRPDrivetrain subsystem;

/* this should only run once- for creating the subsystem object above. */
public XRPDrivetrain() {
    /* [code] */
}

/* Returns a DriveSubsystem instance. */
public static XRPDrivetrain getInstance() {
    if (subsystem != null) {
      subsystem = new XRPDrivetrain(); /* create the aforementioned instance */
    }
    
    return subsystem;
}

Write a moveRobot() Method

Now that you learned about how to set motors, at the bottom of the XRPDrivetrain class, make a helper method called moveRobot().

Conditions:

circle-info

For the last point, although you can use math.abs() or a bunch of if-statements, there's another way we can do this, but using one of the built-in libraries that comes with your modded VSC.

WPILIB's MathUtil class has a clamp method, clamp(number, lowestBound, highestBound). This method will return the number you gave in the first parameter, but between lowestBound and highestBound inclusively.

Also import the MathUtil class!(import edu.wpi.first.math.MathUtil)

Once you have what you believe to be your answer, compare your code with the answer code below.

chevron-rightAnswer Codehashtag
chevron-rightAlternate Answer Codehashtag

Sample Code

chevron-rightSample Codehashtag

Last updated