LinearOpMode
Last updated
Last updated
This set of blocks primarily relate to the program itself. It doesn’t affect how the code affects the robot, but instead how the code affects the logic or running of itself.
waitForStart
Used to pause the program execution until the "Start" button is pressed. This ensures that your robot's actions begin at the same time as the match starts.
Key points:
Purpose: To synchronize the start of your robot's program with the match start.
Behavior: Pauses the program until the "Start" button is pressed.
Placement: Typically placed at the beginning of an OpMode.
idle
Used to pause the current thread execution for a short time. This allows the other threads to run.
Key points:
Purpose: To enhance program performance by reducing the amount of active threads running.
Behavior: Pauses the program for 1 millisecond
Usage: Typically used for a thread not performing any active work. This puts it into a state of readiness, helping to conserve energy and optimize CPU utilization.
sleep
Used to pause the program execution for a specified duration.
Key points:
Purpose: To introduce a delay in the program's execution.
Units: The duration is measured in milliseconds.
Usage: Commonly used for timing actions, synchronizing movements, or creating pauses between executions.
opModeIsActive
A conditional block that checks whether the current OpMode is still running. It returns a boolean value: true if the OpMode is active, false otherwise.
Key points:
Purpose: To determine if the OpMode is currently running.
Return value: A boolean value indicating the OpMode's active state.
Usage: Often used within loops to continuously check the OpMode's status.
isStarted
A conditional block that checks if the Opmode has been started. It returns a boolean value: true if the OpMode has started, false otherwise.
Key points:
Purpose: To determine if the Opmode has been started.
Return value: True if the Opmode has been started, false otherwise.
Usage: Typically used within a loop to check if the start has begun so that it can execute subsequent code.
isStopRequested
A conditional block that checks if a stop has been requested for the OpMode. This is typically initiated by pressing the “Stop” button.
Key points:
Purpose: To determine if the OpMode should be terminated.
Return value: True if a stop has been requested, false otherwise.
Usage: Typically used within a loop to check for a stop request and perform necessary cleanup actions.
getRuntime
Provides the elapsed time since the OpMode was initialized. This means it starts counting as soon as the OpMode is selected, even before the waitForStart block is reached.
Key points:
Start time: The timer begins when the OpMode is initialized, not when the match starts.
Return value: Returns a double value measured in seconds.
Usage: You can use this block to measure time-based events, implement delays, or calculate rates.