Programming - Main Loop

Main loop for the TeleOp code

The main "whileLoop" of our program this year is fairly short containing our functions and temeletry for the flywheel.

What is a Function?

You can think of functions (also known as methods) as a set of pre-written instructions represented by one line of code. When the function is called, the robot knows to run that set of instructions.

As an example, in our program we've created a function called splitStickArcadeDrive. Any time the robot receives an input for that function, in this case from the joysticks, it knows to go through the process of running the drivetrain despite those code lines not being listed individually in the mainLoop.

splitStickArcadeDrive function being called in the mainLoop

Our full splitStickArcadeDrive function, and those code steps, can be found elsewhere within our program organized and self-contained with all the relevant pieces together. This code is what's run when the function is called.

splitStickArcadeDrive function

In short:

Functions take the place of several lines of code and appear as a single line when called. This can be incredibly useful if there is a section of code we know will be repeated or to break apart our code into chunks for easy editing and viewing.

Below is a breakdown of our functions

Function
Purpose

splitStickArcadeDrive

Contains the code for driving the robot

setFlywheelVelocity

Contains both the auto and manual control for the flywheel

manualCoreHexAndServoControl

Contains manual control for the feeder Core Hex and servo

Interested in learning more about functions? Check our Hello Robot!

Telemetry

The telemetry of the main loop reports the flywheel's velocity and how that equals to power. This can be used as a reference when troubleshooting the flywheel or determining if a new velocity target should be set.

Telemetry for the flywheel's velocity and power

Last updated

Was this helpful?