The composition of hardware components and their basic helper functions
An FTCLib Subsystem is like a part of your robot that controls specific tasks, such as driving, lifting an arm, or shooting a game element. Each subsystem has its own job and knows how to control the motors, sensors, or other components related to that job. By breaking the robot into subsystems, your code becomes easier to manage and update because each part is responsible for its own actions. Think of it like different departments in a company—each one has a clear purpose, making the whole robot work smoothly together.
The advantage of using subsystems in FTCLib is that it allows for smooth control of multiple parts of your robot at once. Organizing your code this way allows you to run several subsystems without everything happening in one big block. This means one thread can manage multiple subsystems simultaneously without commands blocking each other. For example, the robot can move and operate its arm, and if a new command interrupts a current action—like stopping the drive to shoot a game element—it can smoothly switch tasks without delays or confusion.
Hardware and Setup:
The Arm
subsystem in our example demonstrates essential aspects of subsystem creation:
Hardware References: Declares member variables like motor
, wristServo
, etc., linking them to hardware names from a centralized place for these "magic strings," such as HardwareNames
.
Motor Configuration: Sets up the motor
for precise position control using MotorEx
, defining parameters like PID coefficients and tolerances.
Servo Initialization: Retrieves servo objects from the hardwareMap
and sets their initial positions.
Helpful Methods:
Subsystems often include convenience methods to control hardware directly. The Arm
class provides examples:
travelMode()
: Sets the arm for driving by closing the claw, adjusting the wrist, and storing the new wrist position.
wristUp()
/wristDown()
: Increment/decrement the wrist servo position within set limits.
openClaw()
/closeClaw()
: Manipulate the claw servo based on an isOpen
boolean flag.
toggleOpen()
/toggleRoll()
: Implement button-pressable actions using conditional logic.
State Management:
Subsystems can maintain internal state using variables like isOpen
for the claw. The toString()
method provides a human-readable snapshot of the subsystem's current state (servo positions in this case).
Where do state variables go?
There are state variables like wristAng
and isOpen
in this subsystem. Does every subsystem get unique state variables? Should we consolidate them into the MyRobot
file? These are organizational guidelines that are flexible and will need to be discussed so all programmers know how things ought to be organized.
Beyond Commands:
Remember, not every action needs a dedicated Command. Servos like the wrist can be adjusted directly using methods like wristUp()
. They're instantaneous and aren't a threat to block off other commands. So here's how we can bind these to a button (more details in Running Your Code).
Next Steps:
While this explanation covers the basics of subsystems, exploring the provided Robot
OpMode will reveal how these subsystems are integrated and controlled within your robot's overall behavior. Remember, effectively utilizing subsystems is vital in writing well-structured and maintainable robot code in FTCLib.