Autonomous to Teleop, differential drive not updated

Hello Chief Delphi!

I’m a mentor on team 3098, having trouble with programming. The issue at hand is testing autonomous mode, then switching to teleop or testing autonomous mode again without power cycling. I believe I know the issue at hand, due to another post, but I’m unsure how to fix it.

Essentially, I believe it’s making a new DifferentialDrive upon first initialization autonomous mode, but fails to recreate/overwrite when switching to teleop or reiterating autonomous mode. Right now our method in fixing the issue is to simply power cycle. When switching to teleop or reiterating auton, the shooter wheels continue to run at full throttle while the drive train doesn’t move at all, hence why I write everywhere to set ShootPower(0.0); - temporary solution that I find isn’t working.

Hopefully I’m posting the right robot code onto dropbox, but please let me know if it doesn’t work.
Yes I know our autonomous mode is using a timer, I hope to change that when we get encoders installed.

Many thanks,
Aaron

firing = true should be in initialize.

Looking at the execute method of AutonomousCommand, I see two loops, calling the subsystem methods. This is the wrong approach and works against the scheduler. See this thread for a similar discussion. Consider using SequentialCommandGroup here.

Your AutonomousCommand.isFinished always returns false, which means that the command will never end, at least until interrupted by the end of autonomous mode.

2 Likes

Please considering using git or other version control system in the future. I recpmmend this for serveral reasons. 1) it can save you if your programmer PC dies. 2) it will allow multiple people to work on code in parallel. And 3) if you use github or a similar internet service, it’ll allow you to simply link us to your code when seeking help.

4 Likes

I find when I use the command scheduler instead of AutonomousCommand, the robot jitters/inches its way for the duration of autonomous. When I use AutonomousCommand, the robot moves smoothly. Because of the inching/jittering, the robot does not rev up the wheels fully and continuously before launching a ball, therefore failing to launch a ball.

I’m not sure how to begin SequentialCommandGroup, could you explain it? or even point me to a guide, please?

As per someone else, I’ve created a github for our team’s code. Please let me know if it doesn’t work. I should also note, that we’re not at competition this week but instead next week. So time isn’t completely critical but still worrying nonetheless.

Thanks,
Aaron

Jittering in autonomous is typically because two things are trying to drive the robot at the same time. This is usually two commands where addRequirements has not be used correctly, or where there’s code in the periodic of the drive subsystem that should in the default command instead.

In your case, I see the following in Drivetrain.periodic:

   drive.tankDrive(1.0,1.0);

This means that, regardless of what other command is running, the drive will be continually told to do this. This will cause jitter in both teleop and (a properly implemented) autonomous.

Hi, I’m on a personal account instead of the team’s account.

Originally I had:

if(counter < 4001)
            m_robotContainer.m_driveTrain.drive(1.0,1.0);
        if(counter < 8001)
            m_robotContainer.m_shooter.ShootPower(0.85);
        if(counter > 4501)
            m_robotContainer.m_intake.inPower(1.0);
        counter++;

Which still caused jittering. I thought using driveTrain.periodic() would help, by the thread you linked earlier talking about how the periodics in robot.java calls the periodics in the subcommands. Explaining it to a friend, I’m able to understand it more on why the periodics are causing it to inch across (because we’re sending “full power” to the talon in one instance that the periodic is called).

My method is circumnavigating around this issue of jittering is making an AutonomousCommand command and dumping the code in execute(), which brings me back to my original issue with new DifferentialDrive being reinitialized each time.

In a quick and crude understanding of SequentialCommandGroup, I initialize it in AutonomousInit() with GroupName.addCommands(m_robotContainer.autonDR(), m_robotContainer.autonSH(), m_robotContainer.autonIN()); with each auton##() being the commands previously named in the periodics(). Assume the variable GroupName has already been globally declared private SequentialCommandGroup GroupName. This is just to get my understanding of SequentialCommandGroup.

Many thanks,
Aaron

1 Like

I’m not quite sure what you’re proposing here. The code in your dropbox is a bit different from the code in your GItHub, and I don’t know which we’re talking about here. (I’m happy to look at more code if you push it.) If you’re talking about breaking up your autonomous routine into simple commands and assembling them using serial and parallel command groups, then that sounds like a good idea.

In general, the periodic method of a subsystem should not be making decisions about what to do. That’s what commands are for, and they call a method on the subsystem (e.g. drive) to act on that decision. (Some subsystems will store the decision in a member variable and only act on it in their periodic, but this is not an exception to this rule.).

If you want a subsystem to do something (e.g. obey the joysticks) when it’s not following a specific command, then that’s what default commands are for.

I apologize for my incoherence. But I’ll push code when I’m in the shop next on Monday. I’m just not sure what to do with the autonomous mode; I can get it 80% of what I want, but can’t gain anything else to be confident enough to push for competition. I appreciate your help thus far though.

Many thanks,
Aaron Hays

No worries. It’s been a long build season for all of us. :slight_smile:

To stop the jittering, you must remove all code from all subsystem periodic methods (Drivetrain, Intake, Shooter).

I recommend that you write your autonomous command something like:

class AutonomousCommand extends ParallelCommandGroup {
    AutonomousCommand(Drivetrain drivetrain, Shooter shooter, Intake intake) {
        addCommands(
            new TankDrive(drivetrain).withTimeout(4),
            new ShootCommand(0.85, shooter).withTimeout(8),
            new WaitCommand(4.5)
                .andThen(new IntakeCommand(1.0, intake).withTimeout(10))
        );    
    }
}

See Convenience Features and Command Groups for a good explanation of how to put commands together like this.

In most of your commands, you should be setting the power in the initialize method, not the execute. With rare exceptions, you should not be reading buttons in commands, but rather using buttons to run commands.

For example, IntakeCommand should be much simpler, like:

public class IntakeCommand extends CommandBase {
    private final Intake m_intake;
    private final double m_power;

    public IntakeCommand(double power, Intake subsystem) {
        m_power = power;
        m_intake = subsystem;
        addRequirements(m_intake);
    }

    @Override
    public void initialize() {
        m_intake.inPower(m_power);
    }

    // No execute() method

    @Override
    public void end(boolean interrupted) {
        m_intake.inPower(0.0); // or m_intake.stop()
    }
}

And the button bindings should be in RobotContainer.configureButtonBindings() like:

new JoystickButton(operatorController, XboxController.Button.kRightBumper.value)
    .whenPressed(new IntakeCommand(0.75, intake));
new JoystickButton(operatorController, XboxController.Button.kLeftBumper.value)
    .whenPressed(new IntakeCommand(-0.75, intake));
new JoystickButton(operatorController, XboxController.Button.kA.value)
    .whenPressed(new IntakeCommand(1.0, intake));
new JoystickButton(operatorController, XboxController.Button.kB.value)
    .whenPressed(new IntakeCommand(-1.0, intake));

I hope this helps. Good luck!

1 Like

I see you’re starting competition today. How did that work out for you? Were you able to put together an autonomous routine you’re happy with? Did you get rid of the jitter?

1 Like

The coach and I sat down a bit and figured out what the issue was. If I recall, we used the SequentialCommandClass in robotcontainer.java to make an autonomous mode.

I appreciate you helping us out!

1 Like

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