Advanced Robotics Programming: Difference between revisions

From TrcWiki
Jump to navigation Jump to search
No edit summary
Line 7: Line 7:


=== Pre-Work ===
=== Pre-Work ===
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. FRC software installation instructions can be found [https://trc492.github.io/pages/FrcProgrammingSoftwareInstallation.html here].
* Create GitHub account if not already have one.
* Create GitHub account if not already have one.
* Download and install GitHub Desktop.
* Download and install GitHub Desktop.
Line 14: Line 15:


=== Session 1: Simple Motor ===
=== Session 1: Simple Motor ===
==== Topics ====
==== Topics ====
* Verify software setup.
* Verify software setup.
Line 64: Line 66:


=== Session 2: Elevator Subsystem ===
=== Session 2: Elevator Subsystem ===
==== Hardware ====
 
* Screw-driven elevator
* DC motor with built-in encoder
* Lower limit switch (optional)
* Robot-In-A-Box
* Driver Station with a Gamepad
==== Topics ====
==== Topics ====
* Create the Elevator class as a Motor Actuator.
* Create the Elevator class as a Motor Actuator.
Line 77: Line 74:
* Calibrate elevator scale, offset and position limits.
* Calibrate elevator scale, offset and position limits.
* Tune elevator position PID control.
* Tune elevator position PID control.
May continue to the next session if time runs out.


=== Session 3: Arm Subsystem ===
==== Hardware ====
===== Hardware =====
* Screw-driven elevator
* Swing Arm with elbow
* DC motor with built-in encoder
* DC motor with built-in encoder to drive the elbow
* Lower limit switch (optional)
* Lower limit switch (optional)
* Robot-In-A-Box
* Robot-In-A-Box
* Driver Station with a Gamepad
* Driver Station with a Gamepad
=== Session 3: Arm Subsystem ===
==== Topics ====
==== Topics ====
* Create the Arm class as a Motor Actuator.
* Create the Arm class as a Motor Actuator.
Line 94: Line 92:
* Tune gravity compensation.
* Tune gravity compensation.
* Tune arm position PID control.
* Tune arm position PID control.
May continue to the next session if time runs out.


=== Session 4: Turret Subsystem ===
===== Hardware =====
==== Hardware ====
* Swing Arm with elbow
* Turret with rotating base (Old FRC turret stored on the shop shelf?)
* DC motor with built-in encoder to drive the elbow
* DC motor with built-in encoder to drive the rotating base
* Lower limit switch (optional)
* Zero position limit switch
* Rotation direction limit switch
* Robot-In-A-Box
* Robot-In-A-Box
* Driver Station with a Gamepad
* Driver Station with a Gamepad
=== Session 4: Turret Subsystem ===
==== Topics ====
==== Topics ====
* Create the Turret class as a Motor Actuator.
* Create the Turret class as a Motor Actuator.
Line 111: Line 109:
* Determine the turret rotation scale.
* Determine the turret rotation scale.
* Tune turret position PID control.
* Tune turret position PID control.
May continue to the next session if time runs out.


=== Session 5: Intake Subsystem ===
==== Hardware ====
==== Hardware ====
* Intake with rotating brushes or rollers (Build one based on FTC Centerstage Intake)
* Turret with rotating base (Old FRC turret stored on the shop shelf?)
* DC motor (no encoder needed) to drive the intake
* DC motor with built-in encoder to drive the rotating base
* Sensor to detect the presence of game element taken in
* Zero position limit switch
* Rotation direction limit switch
* Robot-In-A-Box
* Robot-In-A-Box
* Driver Station with a Gamepad
* Driver Station with a Gamepad
=== Session 5: Intake Subsystem ===
==== Topics ====
==== Topics ====
* Create the Intake class.
* Create the Intake class.
Line 126: Line 126:
* Create code to display the state of the intake on the Dashboard.
* Create code to display the state of the intake on the Dashboard.
* Tune the analog threshold value if it is an analog sensor.
* Tune the analog threshold value if it is an analog sensor.
==== Hardware ====
* Intake with rotating brushes or rollers (Build one based on FTC Centerstage Intake)
* DC motor (no encoder needed) to drive the intake
* Sensor to detect the presence of game element taken in
* Robot-In-A-Box
* Driver Station with a Gamepad


=== Session 6: Grabber Subsystem ===
=== Session 6: Grabber Subsystem ===
==== Topics ====
==== Hardware ====
==== Hardware ====
==== Topics ====


=== Session 7: Shooter Subsystem ===
=== Session 7: Shooter Subsystem ===
==== Topics ====
==== Hardware ====
==== Hardware ====
==== Topics ====


=== Session 8: Vision Subsystem ===
=== Session 8: Vision Subsystem ===
Line 162: Line 169:
* Synchronization
* Synchronization
* State machine
* State machine
== 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.
* [[FRC Programming Software Installation]]
* [[FTC Programming Software Installation]]
== 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.
* [[Driving FRC Swerve Drive Base in TeleOp]]
* [[Driving FTC Mecanum Drive Base in TeleOp]]
== Creating Subsystems ==
Once the drive base is fully operational, 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, you need to determine the following:
* '''What hardware does the subsystem contain?''' This includes motors, actuators and sensors. For example, an elevator will most likely contain a motor to move it up and down, an encoder to keep track of its position and one or two limit switches to tell if the elevator has reached its lower or upper height limit.
* '''What operations does the subsystem support?''' For example, an elevator may have a method to allow the joystick to control it going up and down at various speed, a method to command the elevator to go to a certain height, and a method to command the elevator to go to next preset height up or down.
Even though the game of each season changes, a lot of subsystems repeat themselves season after season. Therefore, our Framework Library provides generalized subsystems to handle most of the scenarios. Here are some typical subsystems you will find on a robot.
* '''[[Motor Actuator]]''': Motor is the most fundamental output device on a robot. It provides movements for mechanisms. Motor Actuators contain one or more motors, an encoder to keep track of its position and some limit switches to limit their movement. '''FIRST''' provided some basic motor classes (e.g. ''DcMotor/DcMotorEx'' for FTC and ''Phoenix5/Phoenix6/SparkMax'' for FRC). The Framework Library added a lot more features on top of that in the '''TrcMotor''' class. For example, it added support for a digital input sensor to reset the motor encoder automatically (limit switches). This is useful for using the motor in a complex actuator such as an arm or elevator when you may need to zero calibrate the zero position of the actuator using a lower limit switch. It also added support to provide velocity control and motor odometry. On top of the fundamental motor features, it also provided PID Controlled functionality. It can support either native motor close-loop control (position and velocity PID control) or software PID control in case some motors do not support native close-loop control (e.g. continuous servos). '''TrcMotor''' added support for lower and upper limit switches, motor stall protection for safety, multiple motors with synchronization (motor followers), zero position calibration, gravity compensation and much more. These advanced features made it trivial to implement complex subsystems such as swing arm, elevator, slide or pan and tilt. The built-in PIDF controller allows the arm or elevator to be controlled by an analog joystick to speed up or slow down the arm/elevator movement. It understands the arm/elevator position approaching the lower/upper position limits and will automatically slow down its movement. It also provides stall protection. If the PID Actuator got stuck and the motor is stalled, it can cut motor power to prevent it from burning out. It also allows a reset timeout so that the stall condition can be cleared after a certain period assuming the stall condition is caused by human temporarily. This allows the subsystem to resume its function and provides time for the motor to cool down. In addition, it also supports voltage compensation. It understands battery voltage drop and can compensate the power level sent to the motor.
* '''[[Servo Actuator]]''':
* '''[[Pneumatic Actuator]]''':
* '''[[Intake]]''':
* '''[[Conveyor]]''':
* '''[[Shooter]]''':
* '''[[Grabber]]''':
== Connecting Subsystems to the Robot ==
* Instantiate the subsystems
* TeleOp control of the subsystems
* Display subsystem status
== Writing Autonomous Code ==

Revision as of 10:56, 21 July 2024

The Advanced Robotics Programming Class focuses on teaching our Titan Robotics Framework (TRC Library). The target audience is for students who already know the Java language. Titan Robotics Framework is designed for both FTC and FRC. After finishing this class, you should be able to write code for both FTC and FRC robots with minimal platform specific changes.

Titan Robotics Framework

You can read about our Framework Library here

Class Curriculum

Pre-Work

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. FRC software installation instructions can be found here.

  • Create GitHub account if not already have one.
  • Download and install GitHub Desktop.
  • Clone FrcTemplate project.
  • Download and install WPILib with Visual Studio Code.
  • Download and install Git Command Line tools.

Session 1: Simple Motor

Topics

  • Verify software setup.
    • Visual Studio Code with WPILib
    • FrcTemplate project cloned
  • Demo and students follow along:
    • Start Visual Studio Code.
    • Open FrcTemplate project in Visual Studio Code.
    • Brief walk through of FrcTemplate code: Code organization (team492, trclib, frclib)
      • autocommands: contains Autonomous code
      • autotasks: contains Auto-Assist tasks
      • commandbased: contains commandbased code (not used)
      • drivebases: contains standard supported drive bases (Differential, Mecanum, Swerve)
      • subsystems: contains code for all upper subsystems
      • Main.java: main entry point of robot code (provided by FIRST, do not change)
      • Robot.java: top level robot object
      • RobotParams.java: contains robot configurations and subsystem parameters
      • FrcAuto.java, FrcTeleOp.java, FrcTest.java, FrcDisabled.java: contain code for respective robot run mode
    • Brief walk through of Visual Studio Code.
      • WPILib Plug-in (commonly used operations)
        • Set Team Number: set our team number 492 (Very important: team number is used to find our robot for pushing code)
        • Build Robot Code: Compile your robot code
        • Depoloy Robot Code: Compile and push code to robot
        • Debug Robot Code: Compile, push code to robot and start real time debugger
        • Check for WPILib Updates: Check for latest WPILib from the Internet
        • Manage Vendor Libraries: Install/Remove/CheckUpdate of various 3rd party vendor libraries
      • Common Source Control Operations
        • Branches: Create/Remove/Switch code branches
        • Fetch: Sync latest changes from GitHub
        • Discard: Discard changes to a file and revert back to last committed version
        • Stage: Stage the changed file for commit
        • Compare changes: Compare the changes with last committed version
        • Commit: Commit changes to your local repository
        • Push: Push changes from your local repository to GitHub
    • Controlling a Simple Motor.
      • Robot.java: Instantiate and initialize a Simple Motor.
        • Create FrcCANTalonSRX
        • Reset to factory default
        • Enable Voltage Compensation
        • Enable Brake Mode
        • Invert motor direction
      • FrcTeleOp.java: Create code to control the simple motor in TeleOp.
        • In the periodic method, add code to read the gamepad joystick and set motor power with the value.
        • In the updateStatus method, add code to display the motor status: joystick value, actual motor power.

Hardware

  • Simple DC motor
  • Robot-In-A-Box
  • Driver Station with a Gamepad

Session 2: Elevator Subsystem

Topics

  • Create the Elevator class as a Motor Actuator.
  • Create code to instantiate an Elevator subsystem.
  • Create code to control the elevator in TeleOp.
  • Create code to display the state of elevator on the Dashboard.
  • Calibrate elevator scale, offset and position limits.
  • Tune elevator position PID control.

Hardware

  • Screw-driven elevator
  • DC motor with built-in encoder
  • Lower limit switch (optional)
  • Robot-In-A-Box
  • Driver Station with a Gamepad

Session 3: Arm Subsystem

Topics

  • Create the Arm class as a Motor Actuator.
  • Create code to instantiate an Arm subsystem.
  • Create code to control the arm in TeleOp.
  • Create code to display the state of the arm on the Dashboard.
  • Calibrate arm scale, offset and position limits.
  • Tune gravity compensation.
  • Tune arm position PID control.
Hardware
  • Swing Arm with elbow
  • DC motor with built-in encoder to drive the elbow
  • Lower limit switch (optional)
  • Robot-In-A-Box
  • Driver Station with a Gamepad

Session 4: Turret Subsystem

Topics

  • Create the Turret class as a Motor Actuator.
  • Create code to instantiate a Turret subsystem.
  • Create code to control the turret in TeleOp.
  • Create code to display the state of the turret on the Dashboard.
  • Determine the turret rotation scale.
  • Tune turret position PID control.

Hardware

  • Turret with rotating base (Old FRC turret stored on the shop shelf?)
  • DC motor with built-in encoder to drive the rotating base
  • Zero position limit switch
  • Rotation direction limit switch
  • Robot-In-A-Box
  • Driver Station with a Gamepad

Session 5: Intake Subsystem

Topics

  • Create the Intake class.
  • Create code to instantiate an Intake subsystem.
  • Create code to control the intake in TeleOp.
  • Create code to display the state of the intake on the Dashboard.
  • Tune the analog threshold value if it is an analog sensor.

Hardware

  • Intake with rotating brushes or rollers (Build one based on FTC Centerstage Intake)
  • DC motor (no encoder needed) to drive the intake
  • Sensor to detect the presence of game element taken in
  • Robot-In-A-Box
  • Driver Station with a Gamepad

Session 6: Grabber Subsystem

Topics

Hardware

Session 7: Shooter Subsystem

Topics

Hardware

Session 8: Vision Subsystem

  • AprilTag Detection
  • Object Detection
  • Color Blob Detection

Session 9: DriveBase Subsystem

  • Swerve PID Tuning
  • Odometry Tuning
  • DriveBase PID Tuning

Session 10: Path Following

  • PurePursuit

Session 11: Auto-Assist Pickup

  • DriveBase
  • Intake
  • Vision

Session 12: Auto-Assist Shoot

  • DriveBase
  • Shooter
  • Vision

Session 13: Autonomous

  • Asynchronous operations
  • Synchronization
  • State machine