Help With Autonomous

Hey I’m having trouble with getting my autonomous working. I’m trying to use sequential commands in robot container but I can’t get anything to work. Can someone help teach me how to get this autonomous working? I plan on extending the elevator up and outaking a cube then driving backwards.

Here’s my github link:

You need to uncomment this line:

// m_autonomousCommand = m_robotContainer.getAutonomousCommand();

Also, instead of creating commands that incorporate timeouts, you can use WaitCommand or withTimeout(). See Command Compositions — FIRST Robotics Competition documentation

I recommend against using DifferentialDrive.arcadeDrive for auto. The default behaviour of squaring the inputs and applying a deadband is great for joysticks, but not for auto. For example, a “speed” of 0.6 will end up as 0.3364.

1 Like

Since the github has been updated I’ve changed this. I think my issue may have to do with most of my commands use a Supplier , could this be why most of the code for auto doesn’t work? As well I’m not able to get the drivetime command for auto to work but there seems to be no errors.

If you write commands to take a supplier, it’s easy to make them take a constant using an appropriate Lambda expression, e.g. () -> true, () -> 0.5.

I kind of get what you’re saying. I’m just not sure how to make this work for my auto code. Would it be something like this?

“ElevatorUp () → true, () → 0.67 , Drivetime (Speeds.DRIVE_SPEED, 2, m_drive));”?

or something like this ?

‘‘public Command getAutonomousCommand() {
return new SequentialCommandGroup(
new ElevatorUp(m_elevator, () → 0), () → 0.67));’’

the Drivetime only has a double value, which is still confusing on why it didn’t earlier.
How would you do it through the drivetrain? because I’m not sure if the Drivetime command itself actually works.

Well … I’m a little worried about the fact that your elevator has no encoder or limit switch, but you might want something like (untested):

public Command getAutonomousCommand() {
    return new SequentialCommandGroup(
        new StartEndCommand(
            () -> m_drive.setPower(Speeds.DRIVE_SPEED),
            () -> m_drive.stop(), m_drive).withTimeout(3),
        new StartEndCommand(
            () -> m_elevator.setElevatorSpeed(Speeds.ELEVATOR_SPEED),
            () -> m_elevator.ElevatorStop(), 
            m_elevator).withTimeout(0.7));
}

And in DriveTrain add methods:

public void setPower(double left, double right) {
    leftMotors.set(left);
    rightMotors.set(right);
}

public void setPower(double power) {
    setPower(power, power);
}

public void stop() {
    setPower(0);
}

We do technically have encoders but we haven’t had the chance to program the for our elevator. Until then we planned on testing which time and speed would be best for auto. Would the encoders interfere with any of the auto code we just made? or does it just need to the commands to be named the same?

If you had an encoder, then on the elevator command, instead of withTimeout, you could have something like:

.until(m_elevator::isExtended)

or

.until(() -> m_elevator.isAtPosition(ELEVATOR.extendedPosition))

But it’s a good idea to have code in the elevator periodic that prevents the position from going out of range.

Hey I’m sorry for such the late response, we’ve tested the auto and it works great! This is without the encoders so far though ,just in case we’re not able to get the encoders working in auto we have code we can use where we’ve tested the timing and speed needed for our arm.

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