Roarm.CommandValidator (RoArm v0.1.1)

View Source

Command validation module for RoArm robot commands.

This module defines command schemas and provides validation for all robot commands. It supports parameter validation, range clamping, and symbolic values (:min, :mid, :max).

Command Schemas

The command schemas define the structure, types, and validation rules for all RoArm robot commands. Each schema includes:

  • T-code: Unique command identifier
  • Description: Human-readable command description
  • Parameters: Map of parameter definitions with validation rules

Parameter Definition Structure

Each parameter can have the following attributes:

  • :type - Parameter type (:integer, :float, :string)
  • :min - Minimum allowed value (for numeric types)
  • :max - Maximum allowed value (for numeric types)
  • :default - Default value if parameter is not provided
  • :required - Whether the parameter is required (default: false)

Example Usage

# Get all command schemas
schemas = Roarm.CommandValidator.command_schemas()

# Get specific command schema
{:ok, schema} = Roarm.CommandValidator.get_command_schema(122)

# Access position control parameters
position_schema = schemas[1041]
x_param = position_schema.parameters[:x]
# => %{type: :float, min: -500.0, max: 500.0, required: true}

Command Categories

  • Movement Commands (100-199): Home, joint control, position control
  • Position Commands (1000-1099): Coordinate-based positioning
  • System Commands (200-299): Torque, feedback, system control
  • LED Commands (100-199): Light control and effects
  • Mission Commands (220-249): Recorded movement sequences
  • Advanced Commands (100-199): PID tuning, force adaptation
  • Gripper Commands (222): Gripper control for M3 models

Summary

Functions

Get all command schemas for RoArm robot commands.

Get the command schema for a given T-code.

Convert a validated command map to JSON string.

Validate and normalize a command map.

Functions

command_schemas()

Get all command schemas for RoArm robot commands.

Returns a map where keys are T-codes (command identifiers) and values are schema definitions containing parameter validation rules.

Schema Structure

Each schema contains:

  • :description - Human-readable description of the command
  • :parameters - Map of parameter definitions with validation rules

Returns

A map of T-code => schema, where each schema follows this structure:

%{
  description: "Command description",
  parameters: %{
    param_name: %{
      type: :integer | :float | :string,
      min: number,              # For numeric types
      max: number,              # For numeric types
      default: any,             # Default value
      required: boolean         # Whether required (default: false)
    }
  }
}

Examples

# Get all schemas
all_schemas = Roarm.CommandValidator.command_schemas()

# Get home command schema
home_schema = all_schemas[100]
# => %{description: "Home position", parameters: %{}}

# Get position control schema
pos_schema = all_schemas[1041]
x_limits = pos_schema.parameters[:x]
# => %{type: :float, min: -500.0, max: 500.0, required: true}

# Check if a T-code exists
Map.has_key?(all_schemas, 122)  # => true

# Get parameter names for a command
joint_params = Map.keys(all_schemas[122].parameters)
# => [:b, :s, :e, :h, :w, :g, :spd]

get_command_schema(t_code)

Get the command schema for a given T-code.

to_json(validated_command)

Convert a validated command map to JSON string.

validate_command(command)

Validate and normalize a command map.

Returns {:ok, validated_map} or {:error, reason}