Subsystem
The composition of hardware components and their basic helper functions
Subsystems encapsulate hardware components like motors, servos, and sensors and their basic power on/off functionality.
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 asHardwareNames
.Motor Configuration: Sets up the
motor
for precise position control usingMotorEx
, 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 anisOpen
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.
Last updated