Debug a Plan

Find and fix issues in your OPAL plans

Debug a Plan

Find and fix issues in your OPAL Plans using built-in debugging tools.

Pro Tip

Add log() statements liberally during development - they're your best friend for understanding plan behavior. You can always remove them or change to log_debug() for production use.


Debugging tools

OctoMY™ provides several debugging features:

Tool Purpose
Log Output View plan messages
Variable Watch Monitor variable values
Breakpoints Pause at specific lines
Step Execution Run line by line
Sensor Monitor Live sensor values

Using log output

Adding log statements

plan DebugExample {
    loop {
        var distance = sensors.distance.front
        log("Distance reading: " + distance + "cm")

        if distance < 30 {
            log("WARNING: Obstacle detected!")
            log("Taking evasive action")
            avoid_obstacle()
        }

        delay(100)
    }
}

Viewing logs

Open the log panel while plan is running:

Log Output Panel

Log levels

log("Normal message")           # INFO level
log_debug("Debug details")      # DEBUG level (verbose)
log_warn("Warning message")     # WARNING level
log_error("Error occurred!")    # ERROR level

Filter logs by level in the UI dropdown.


Variable watch

Monitor variable values in real-time:

Enable watch

  1. Click [Debug] button
  2. Select Variable Watch
  3. Add variables to watch list

Variable Watch

Watch expressions

Watch calculated values:

Expression Watch


Breakpoints

Pause execution at specific lines:

Set a breakpoint

Click the line number in the editor:

Breakpoints in Editor

Breakpoint controls

When paused at a breakpoint:

Breakpoint Controls

Button Action
Continue Resume until next breakpoint
Step Execute one line, enter functions
Step Over Execute one line, skip function internals
Stop End execution

Step execution

Run your plan line by line:

Start step mode

  1. Click [Debug][Step Mode]
  2. Plan starts paused at first line
  3. Click [Step] to advance

Step Execution


Sensor monitor

View live sensor data while debugging:

Sensor Monitor


Common errors

Syntax errors

Error at line 5: Unexpected token '}'

Solution: Check for missing brackets, parentheses, or semicolons.

# Wrong
if distance < 30
    avoid_obstacle()
}

# Correct
if distance < 30 {
    avoid_obstacle()
}

Undefined variable

Error at line 7: Variable 'distanc' is not defined

Solution: Check variable spelling.

# Wrong
var distance = 50
if distanc < 30 {  # Typo!

# Correct
var distance = 50
if distance < 30 {

Type mismatch

Error at line 4: Cannot compare string to number

Solution: Ensure types match in comparisons.

# Wrong
var state = "running"
if state < 30 {  # String vs number!

# Correct
var state = "running"
if state == "running" {

Sensor not found

Error: Sensor 'distance.rear' not found

Solution: Verify sensor name and that hardware is configured.

# Check available sensors first
log(sensors.list())

Performance issues

Plan running slow

Cause: Loop running too fast without delay.

# Bad - uses 100% CPU
loop {
    check_sensors()
    # No delay!
}

# Good - runs at 20Hz
loop {
    check_sensors()
    delay(50)  # 50ms between iterations
}

Memory issues

Cause: Creating objects in loop without cleanup.

# Bad - memory grows forever
loop {
    var data = read_all_sensors()  # New object each loop
}

# Good - reuse variable
var data = {}
loop {
    data = read_all_sensors()  # Replaces old value
}

Debugging state machines

For complex plans with states:

plan StateMachine {
    var state = "idle"
    var prev_state = ""

    loop {
        if state != prev_state {
            log("State change: " + prev_state + " -> " + state)
            prev_state = state
        }

        if state == "idle" {
            # ...
        } else if state == "searching" {
            # ...
        } else if state == "avoiding" {
            # ...
        }

        delay(50)
    }
}

State history

Enable state logging:

State History


Remote debugging

Debug plans from a connected Remote:

  1. On Remote: ☰ MenuUtilitiesPlan Debug
  2. Select the Agent and Plan
  3. Access all debugging tools remotely

Remote Debugging


Debugging tips

  1. Start simple - Get basic behavior working first
  2. Log generously - More logs = easier debugging
  3. Test sensors first - Verify readings before using them
  4. Use watch - Monitor key variables continuously
  5. Check edge cases - What if sensor reads 0? 999?
  6. Isolate problems - Comment out code to find issues
  7. Version control - Save working versions before changes

In this section
Topics
howto plans debugging troubleshooting OPAL breakpoints
See also