Robot Code Flow Diagrams
Understanding how your robot code works is easier with pictures! These diagrams show how everything connects.
Robot Code Structure
Section titled “Robot Code Structure”What This Means
Section titled “What This Means”- Robot.java: The main program that starts everything.
- RobotContainer: Sets up all your robot’s parts.
- Subsystems: Physical parts of your robot (drivetrain, shooter, etc.)
- Commands: Actions your robot can do.
- Triggers: What starts commands (buttons, timers, sensors)
Command Execution Flow
Section titled “Command Execution Flow”What This Means
Section titled “What This Means”- User Action: You press a button or auto starts.
- Schedule: Command scheduler adds your command to the list.
- Execute: Your command runs every 20ms (50 times per second!)
- Check Finished: Command asks “Am I done?”.
- Repeat: Until command says it’s finished.
Subsystem Data Flow
Section titled “Subsystem Data Flow”What This Means
Section titled “What This Means”- Physical Hardware: Real motors, sensors, cameras on robot.
- IO Layer: Translates hardware into software (we handle this!)
- Subsystem: Uses IO data to control robot parts.
- Command: Tells subsystems what to do.
- Robot Behavior: What you see the robot doing.
Simulation vs Real Robot
Section titled “Simulation vs Real Robot”What This Means
Section titled “What This Means”Your code stays the same! Only the IO layer changes:
- Simulation: IO talks to physics engine (computer program)
- Real Robot: IO talks to real hardware.
This is why you can test without a robot!
Periodic Loop Timing
Section titled “Periodic Loop Timing”What This Means
Section titled “What This Means”Every 20 milliseconds (that’s 0.02 seconds!), your robot:
- Reads Sensors: “What’s happening?”.
- Runs Commands: “What should we do?”.
- Updates Subsystems: “Make it happen!”.
- Sends Outputs: “Turn the motors!”.
- Updates Dashboard: “Show driver what’s happening”.
- Waits: “Ready for next cycle”.
This happens 50 times every second!
Path Following Flow
Section titled “Path Following Flow”What This Means
Section titled “What This Means”- Planned Path: “Here’s where we want to go”.
- Path Follower: “Where should we be now?”.
- Target Pose: “Go to this position”.
- PID Controller: “How do we get there?”.
- Chassis Speeds: “Move this fast in this direction”.
- Swerve Drive: “Turn wheels to match”.
- Robot Movement: “We’re moving!”.
- Odometry: “Here’s where we actually are”.
- Repeat: “Adjust and keep going!”.
Key Takeaways
Section titled “Key Takeaways”Your Code Structure
Section titled “Your Code Structure”- Robot Container ties everything together.
- Commands tell Subsystems what to do.
- Subsystems control physical hardware.
- IO Layer makes testing without hardware possible.
Timing Matters
Section titled “Timing Matters”- Everything runs every 20 milliseconds.
- That’s 50 times per second.
- Code must be fast (under 10ms ideally)
Testing is Easy
Section titled “Testing is Easy”- Same code works in simulation and real robot.
- Only the IO layer changes.
- Test at home without robot!
Common Mistakes
Section titled “Common Mistakes”❌ Wrong: Blocking in execute()
Section titled “❌ Wrong: Blocking in execute()”@Overridepublic void execute() { Thread.sleep(1000); // BAD! Stops whole robot!}✅ Right: Use timers
Section titled “✅ Right: Use timers”@Overridepublic void execute() { if (Timer.getFPGATimestamp() > startTime + 1.0) { // Do something after 1 second }}❌ Wrong: Reading hardware directly
Section titled “❌ Wrong: Reading hardware directly”@Overridepublic void periodic() { double position = motor.getPosition(); // Breaks simulation!}✅ Right: Use IO layer
Section titled “✅ Right: Use IO layer”@Overridepublic void periodic() { double position = io.getPosition(); // Works in simulation!}These diagrams help explain complex concepts simply! Use them when teaching new team members or when you’re confused about how something works.
Want more diagrams? Check out Visual Guide to Subsystems or Command Flow Examples