TimedRobot autonomous

I was wondering if anyone had some simple examples of timedRobot Auto
using gyros and encoders and a limelight for targeting

I’m not aware of a single example that will show you all of that. However, you could combine bits from a few examples to get close.

This example shows how you might use a gyro with driving.

This example shows how you might use encoders with driving.

The Limelight docs provide a number of case studies that provide examples on how you might integrate it into your robot code.

The real goal of software engineering is to figure out how to best combine these things to meet your goal. Take a stab at it using these resources. If you still have issues, feel free to share a link to your code, provide a brief description of what you’ve done and how it’s not working, and state what your goal is.

It’s often easier to do this if you break it up into smaller tasks. For example… First get it driving forward. Then get it driving autonomously (not necessarily accurately). Then integrate the encoders so it drives straight. Then integrate the gyro so you can turn to a specific angle. Then integrate the limelight feedback to replace the hardcoded values you were likely using.

I’ll also add that you’re likely going to need to look into closed-loop control modes to get this to drive exactly how you want. This could be in the form of wpilib’s built-in PIDController class, or through your motor controllers.

That is a huge help one more question. what are some ways to execute tasks in an order for the auto period. like using a timer or sequence or what?

A state machine is likely the best option if you need to guarantee sequential tasks. On each loop iteration, you evaluate a condition on whether to advance to the next state. The condition can be a timer, feedback from a sensor, or any other condition you decide. The current state could be tracked by an integer you simply increment, but a better option is to use an enumeration.

Code to do this could look something like this:


enum AutoState {
    STATE1, STATE2, STATE3
}

AutoState current = AutoState.STATE1;

autonomousPeriodic() {
    switch (current) {
        case STATE1:
            // do something
            if (condition == true) {
                current = STATE2;
            }
            break;
        case STATE2:
            // do something else
            if (otherCondition == true) {
                current = STATE3;
            }
            break;
        case STATE3:
            // stop, we're done
            break;
    }
}
1 Like

What do you think of this
I still do not know much about programming but i was hoping i could get your imput

also my AutoState is in a diffrent folder called AutoState.Java

AutoState current = AutoState.Drive15;

autonomousPeriodic(); {

  switch (current) {

      case Drive15:

          // do something

          if(distance > 15)

              Drive.arcadeDrive(-.5, 0);

          if (timer.get() > 5 == true) {

              

              current = AutoState.Limelight;

          }

          break;

      case Limelight:

          // do something else

          if (distance > 25) {

            NetworkTableInstance.getDefault().getTable("limelight").getEntry("ledMode").setNumber(3);

      

            if (m_LimelightHasValidTarget) {

      

              LED.set(.11);

              // Drive.arcadeDrive(-drive,m_LimelightSteerCommand);

      

              PID();

              Drive.arcadeDrive(0, rcw * .75);

            }

          }

          if (m_LimelightHasValidTarget) 

          {

            

            shooterTop.set(ControlMode.PercentOutput, 1);

            shooterBottom.set(ControlMode.PercentOutput, .75);

          }

          if (timer.get() > 8 == true) {

              current = AutoState.shoot;

          }

          break;

      case shoot:

          // stop, we're done

          {

            shoot.set(0);

          }

          break;

  }

}

Have you considered using the Command-based approach?

1 Like

yes I have but it is a little late in the season to learn command based for the 2020 year.

1 Like

For an autonomous that’s able to be easily changed, I think it’s easier to use the command based framework just for autonomous and not use it for anything else. The flexibility you gain by using some sort of command based framework is really amazing.

We don’t use the command framework but use something similar. Being able to create a few base commands and link them together is really nice. If I had to program autonomous modes without some sort of command based setup it would be a real pain and probably end up an unreadable mess.

And also, it’s not too difficult to learn at this point. Either way, you have to learn how to create an autonomous mode by a simple state machine or by using the command based approach. Both require learning something new.

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