Skip to content

Comments

Add If Step Support for Conditional Mission Execution: Part 1#18

Merged
miguelgarcia merged 6 commits intomainfrom
add-if-step
Dec 2, 2025
Merged

Add If Step Support for Conditional Mission Execution: Part 1#18
miguelgarcia merged 6 commits intomainfrom
add-if-step

Conversation

@miguelgarcia
Copy link
Member

@miguelgarcia miguelgarcia commented Dec 1, 2025

Summary

This PR introduces support for conditional execution in missions through the new if step type. This PR is only the data types extension. The behavior will be implemented in subsequent PRs.

Changes

Data Model (inorbit_edge_executor/datatypes.py)

  • Added MissionStepIf class: A new mission step type that supports conditional execution based on expression evaluation

    • Extends MissionStep base class
    • Implements visitor pattern via accept() method
    • Supports optional target field for evaluating expressions on different robots
  • Added IfArgs nested class: Contains the conditional logic configuration

    • expression: str - The expression to evaluate (e.g., "getValue('battery') > 50")
    • target: Target (optional) - Target robot for expression evaluation
    • then: StepsList - Steps to execute when expression is true (aliased as "if" in JSON)
    • else_: Optional[StepsList] - Steps to execute when expression is false (aliased as "else" in JSON, optional)
  • Updated MissionStepTypes enum: Added IF = "if" step type

  • Updated MissionDefinition.steps: Extended the Union type to include MissionStepIf via a new StepsList type alias

JSON Structure

The if step follows this structure:

{
  "if": {
    "expression": "getValue('battery') > 50",
    "then": [
      {"data": {"key": "value"}},
      {"timeoutSecs": 10}
    ],
    "else": [
      {"data": {"key": "else_value"}}
    ]
  },
  "label": "Check battery level",
  "timeoutSecs": 30
}

Testing (tests/test_if_step.py)

Added comprehensive unit tests covering:

  • Basic if step creation with if branch only
  • If step with both if and else branches
  • If step with target robot specification
  • Nested if steps
  • If step with label and timeout
  • Visitor pattern acceptance
  • Integration with MissionDefinition
  • Multiple steps in branches
  • Validation of required fields

Implementation Status

This PR implements Ticket 1 from the implementation plan (IF_ELSE_IMPLEMENTATION_PLAN.md):

  • ✅ Data model implementation complete
  • ✅ Unit tests for data model complete
  • ⏳ Behavior tree node implementation (future work)
  • ⏳ Visitor method for behavior tree building (future work)
  • ⏳ Integration tests (future work)

Breaking Changes

None. This is a purely additive change.


Note

Introduce MissionStepIf with then/else branches in datatypes and add corresponding unit tests; add visit_if stub in behavior tree.

  • Data model:
    • Add MissionStepIf with expression, optional target, then (StepsList), and optional else_.
    • Extend MissionStepTypes with IF and introduce StepsList type alias.
    • Update MissionDefinition.steps to use StepsList.
  • Behavior tree:
    • Import MissionStepIf and add NodeFromStepBuilder.visit_if stub raising NotImplementedError.
  • Tests:
    • New tests/test_if_step.py covering basic/else/target/nested cases, label/timeout, visitor acceptance, integration with MissionDefinition, multiple-steps branches, and validation.

Written by Cursor Bugbot for commit 556d842. This will update automatically on new commits. Configure here.

@miguelgarcia
Copy link
Member Author

@b-Tomas can you review ? Thanks a lot. Feel free to check our internal board for reference

@miguelgarcia miguelgarcia requested a review from b-Tomas December 1, 2025 21:03
Copy link
Member

@b-Tomas b-Tomas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@miguelgarcia miguelgarcia merged commit 4062843 into main Dec 2, 2025
7 checks passed
@miguelgarcia miguelgarcia deleted the add-if-step branch December 2, 2025 15:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants