Advanced Robotics Programming

From TrcWiki
Jump to navigation Jump to search

The Advanced Robotics Programming Class focuses on teaching our Titan Robotics Framework (TRC Library). The target audience of this Programming Class is for students who already have basic knowledge of the Java language. The class is primarily designed for FRC although it is also applicable for FTC because our TRC Library is shared between FTC and FRC. After finishing this class, you should be able to write code for both FTC and FRC robots with some platform specific differences.

Programming Software Installation

Before coming to the programming class, you need to install the required software on your laptop. Please do this at home before coming to class. We do not want to dedicate class time to install software because they are time consuming and require downloading gigabytes of data from the Internet which would overwhelm our Internet bandwidth if all students were downloading at the same time. Therefore, please make sure you finish these tasks at home before coming to class.

TeleOp Driving Your Robot Right Out-Of-The-Box

At this point, you should have installed all necessary software for developing robot code and also clone the robot template code from the GitHub repo. Since the template already contains basic code for three different kinds of robot base (Differential Drive, Mecanum Drive and Swerve Drive), it takes very few modifications to make it work with any of the three types of robots.

Creating Subsystems

Once the drive base is fully functional, the next step is to create subsystems for the robot such as Elevator, Arm, Intake, Grabber etc. It is a good practice to create subsystems as separate Java classes that encapsulate all hardware related to those subsystems. To create a subsystem, follow the steps below: 1. Create a Java class in the subsystems folder (e.g. Slide.java).

  ```
  public class Slide
  {
      private final TrcMotor slideMotor;
      /**
       * Constructor: Creates an instance of the object.
       */
      public Slide()
      {
          FtcMotorActuator.Params slideParams = new FtcMotorActuator.Params()
              .setMotorInverted(RobotParams.SLIDE_MOTOR_INVERTED)
              .setLowerLimitSwitch(
                  RobotParams.SLIDE_HAS_LOWER_LIMIT_SWITCH,
                  RobotParams.SLIDE_LOWER_LIMIT_INVERTED)
              .setUpperLimitSwitch(
                  RobotParams.SLIDE_HAS_UPPER_LIMIT_SWITCH,
                  RobotParams.SLIDE_UPPER_LIMIT_INVERTED)
              .setVoltageCompensationEnabled(RobotParams.SLIDE_VOLTAGE_COMP_ENABLED)
              .setPositionScaleAndOffset(RobotParams.SLIDE_INCHES_PER_COUNT, RobotParams.SLIDE_OFFSET)
              .setPositionPresets(RobotParams.SLIDE_PRESET_TOLERANCE, RobotParams.SLIDE_PRESETS);
          slideMotor = new FtcMotorActuator(RobotParams.HWNAME_SLIDE, slideParams).getActuator();
          //
          // Delete or comment out the following three statements if you want to use motor native PID control
          // (aka RUN_TO_POSITION) instead of software PID control.
          //
          slideMotor.setSoftwarePidEnabled(true);
          slideMotor.setPositionPidParameters(
              RobotParams.SLIDE_KP, RobotParams.SLIDE_KI, RobotParams.SLIDE_KD, RobotParams.SLIDE_KF,
              RobotParams.SLIDE_IZONE, RobotParams.SLIDE_TOLERANCE);
          slideMotor.setStallDetectionEnabled(
              RobotParams.SLIDE_STALL_DETECTION_DELAY, RobotParams.SLIDE_STALL_DETECTION_TIMEOUT,
              RobotParams.SLIDE_STALL_ERR_RATE_THRESHOLD);
          //
          // If you are using motor native PID control, you need to set PID tolerance.
          //
          slideMotor.setPositionPidTolerance(RobotParams.SLIDE_TOLERANCE);
          //
          // Stall protection will detect motor stall and cut power to protect it. This is also required if
          // you want to enable zero calibration by motor stall (e.g. don't have lower limit switch).
          // A motor is considered stalled if:
          // - the power applied to the motor is above or equal to stallMinPower.
          // - the motor has not moved or movement stayed within stallTolerance for at least stallTimeout.
          // Note: By definition, holding target position doing software PID control is stalling. If you decide to enable
          //       stall protection while holding target, please make sure to set a stallMinPower much greater than the
          //       power necessary to hold position against gravity, for example. However, if you want to zero calibrate
          //       on motor stall, you want to make sure calPower is at least stallMinPower.
          //
          slideMotor.setStallProtection(
              RobotParams.SLIDE_STALL_MIN_POWER, RobotParams.SLIDE_STALL_TOLERANCE,
              RobotParams.SLIDE_STALL_TIMEOUT, RobotParams.SLIDE_STALL_RESET_TIMEOUT);
      }
      public TrcMotor getSlideMotor()
      {
          return slideMotor;
      }
  }
  ```
  • Motor Actuators
    • Elevator
    • Slide
    • Arm
    • Turret
  • Intake
  • Conveyor
  • Shooter
  • Grabber

Connecting Subsystems to the Robot

  • Instantiate the subsystems
  • TeleOp control of the subsystems
  • Display subsystem status

Writing Autonomous Code