_inorbit_robot_command_handler() method in the case of a fleet connector, or to your _inorbit_command_handler() method in the case of a single-robot connector.
The fleet handler _inorbit_robot_command_handler() receives the following parameters:
robot_id(str): The ID of the robot receiving the commandcommand_name(str): The name of the commandargs(list): Command argumentsoptions(dict): Options includingresult_functionto report results
_inorbit_command_handler() omits the robot_id parameter.
Reporting Command Results
Theoptions dictionary contains a result_function with the following signature:
- The
result_codeparameter must be set toCommandResultCode.SUCCESSorCommandResultCode.FAILUREto report the command result. - The
execution_status_detailsandstderrparameters are optional and can be used to provide specific error details. - The
stdoutparameter is optional and can be used to provide specific output details.
Reporting Success
The commands handler can call theresult_function with a CommandResultCode.SUCCESS to report a successful command execution before returning. The stdout parameter is optional and can be used to provide specific output details.
Reporting Failure
There are three ways to report a failed command execution:- (Recommended) Raise a
CommandFailureexception. - Raise any other exception.
- Call the
result_functionwith aCommandResultCode.FAILUREand provide theexecution_status_detailsandstderrparameters.
stderr field. All exceptions are logged.
The CommandFailure exception can be used to intentionally indicate a failure:
- Error details are automatically passed to InOrbit’s result function
execution_status_detailsis displayed in alert messages when commands are dispatched from the actions UI- Both
execution_status_detailsandstderrare available in audit logs and through the action execution details API
Parsing Script Arguments
When handling custom script commands, the Edge SDK delivers arguments in the form:args[0]: script file name (e.g.,"script.sh")args[1]: a flat list of alternating keys and values (e.g.,["x", "1.0", "y", "2.0"])
RunScript type (identified with the command_name COMMAND_CUSTOM_COMMAND),
the script name corresponds to the filename field of the action definition,
and the arguments key-value pairs.
For details on how to configure actions with arguments, refer to the
InOrbit Actions Definitions documentation.
Use the helper parse_custom_command_args() to turn these into a script name and a parameters dictionary:
CommandModel class (see Using CommandModel for Type-Safe Argument Parsing) for safe type validation and parsing.
(using-commandmodel-for-type-safe-argument-parsing)=
Using CommandModel for Type-Safe Argument Parsing
For structured command arguments that require validation and type safety, use the CommandModel base class. This is particularly useful when commands have multiple parameters with specific types and validation rules.
CommandModel provides:
- Automatic type validation and conversion using Pydantic
- Conversion of validation errors to
CommandFailureexceptions - Protection against extra fields (forbids unknown parameters)
CommandModel with ExcludeUnsetMixin to exclude unset fields from model dumps, which is useful for API calls where you only want to send non-default values.
Basic Usage
Define a command model by subclassingCommandModel:
Using with ExcludeUnsetMixin
To exclude unset fields from model dumps (useful for API calls), inherit from both ExcludeUnsetMixin and CommandModel. The mixin must come first in the inheritance list:
Using with parse_custom_command_args
CommandModel works seamlessly with parse_custom_command_args():
Automatic Error Handling
If validation fails,CommandModel automatically raises a CommandFailure with appropriate error details:
ValidationError exceptions.
See the Reporting Failure section for more details.
Excluding Unset Fields
When usingExcludeUnsetMixin, model_dump() excludes fields that weren’t explicitly set, which is useful when making API calls where you only want to send non-default values:
Example Usage
Here’s a concrete example of usingCommandModel with ExcludeUnsetMixin to handle a custom command.
The command is a RunScript action, whose filename is schedule_mission.
schedule_mission command and passes the arguments to an API client to schedule the mission.