ROBOLANG™
Domain-specific programming language designed for humanoid robotics control and behavior scripting. Built for safety, real-time performance, and intuitive physical interaction.
# Simple greeting behavior in RoboLang
fn greet_visitor() {
robot.head.look_forward()
robot.right_arm.wave()
robot.speak("Hello! Welcome to our facility.")
robot.return_to_neutral_pose()
}
# Execute the greeting
greet_visitor()
Overview
RoboLang is a high-level interpreted language optimized for controlling humanoid robots. It combines familiar programming constructs with robotics-specific primitives, emphasizing safety, real-time performance, and intuitive physical interaction.
Design Principles
- •Safety First: Built-in safeguards and emergency handling
- •Real-time Capable: Predictable timing for control loops
- •Hardware Abstraction: Clean interface to robot hardware
- •Human-Readable: Intuitive syntax for robotics engineers
- •Concurrent by Design: Natural parallel operation support
Key Features
- •Native physical units (meters, degrees, newtons)
- •Built-in state machines for behaviors
- •Concurrent and real-time execution blocks
- •Emergency handling and watchdog timers
- •Computer vision and AI integration
Basic Syntax
Comments
# Single line comment /* Multi-line comment */
Statements
- • Statements are separated by newlines or semicolons
- • Blocks use curly braces {}
- • No semicolons required at end of lines
Functions
fn greet(name) { return "Hello, " + name + "!" } # Functions with default parameters fn move_arm(target, speed = 0.5, timeout = 5s) { robot.arm.move_to(target, speed: speed, timeout: timeout) } # Lambda functions let double = fn(x) { return x * 2 }
Data Types
Primitive Types
# Numbers let age = 25 # Integer let pi = 3.14159 # Float # Strings let name = "RoboLang" # String literals let msg = 'Hello World' # Single quotes also valid # Booleans let active = true let sleeping = false # Null let empty = null
Physical Types
RoboLang includes native support for physical units, making robotics programming more intuitive and less error-prone.
# Coordinates and poses let position = point(1.0, 2.5, 0.8) # 3D point let orientation = pose(x: 0, y: 0, z: 1.2, # 6DOF pose roll: 0, pitch: 0, yaw: 90deg) # Time and frequency let duration = 2.5s # Seconds let short_wait = 100ms # Milliseconds let control_rate = 50hz # Hertz # Physical units let distance = 1.5m # Meters let angle = 45deg # Degrees let force = 10.5N # Newtons let torque = 2.1Nm # Newton-meters
Collections
# Arrays let numbers = [1, 2, 3, 4, 5] let waypoints = [ point(0, 0, 1), point(1, 0, 1), point(1, 1, 1) ] # Objects/Maps let robot_config = { name: "Humanoid-v2", dof: 32, max_speed: 1.2, sensors: ["camera", "lidar", "imu"] }
Control Flow
Conditional Statements
if battery_level > 20 { robot.continue_mission() } else if battery_level > 10 { robot.return_to_base() } else { robot.emergency_shutdown() } # Ternary operator let status = battery_level > 50 ? "good" : "low"
Pattern Matching
match detection_result { case {type: "person", confidence: c} if c > 0.8 -> { robot.approach_person() } case {type: "obstacle"} -> { robot.avoid_obstacle() } case _ -> { robot.continue_scanning() } }
Loops
# For loop with range for i in range(10) { robot.sensors.read() } # While loop while robot.mission_active() { robot.patrol_step() wait(100ms) } # Loop control for waypoint in path { if obstacle_detected() { break } robot.move_to(waypoint) }
Robotics-Specific Features
Robot Hardware Interface
# Body part hierarchy robot.head.look_at(target_point) robot.left_arm.move_to(pose, duration: 2s) robot.right_hand.grasp(force: 5N) robot.base.move_forward(distance: 1m, speed: 0.5) robot.torso.adjust_posture("upright") # Sensor access let camera_frame = robot.sensors.camera.front.capture() let lidar_data = robot.sensors.lidar.scan() let joint_angles = robot.sensors.encoders.read_all() let imu_data = robot.sensors.imu.read()
Behavior State Machines
Define complex robot behaviors using intuitive state machines with entry/exit actions and event-driven transitions.
behavior patrol_behavior { state idle { entry { robot.stand_ready() } on start_patrol -> walking on low_battery -> charging } state walking { entry { robot.start_walking() } on obstacle_detected -> avoiding on destination_reached -> idle exit { robot.stop_walking() } } state avoiding { entry { robot.plan_detour() } on path_clear -> walking } } # Control the behavior patrol_behavior.start() patrol_behavior.send("start_patrol")
Trajectory Planning
let waypoints = [ pose(0, 0, 1.0, 0, 0, 0), pose(0.5, 0.2, 1.2, 0, 0, 45deg), pose(1.0, 0.0, 1.0, 0, 0, 90deg) ] robot.left_arm.follow_trajectory( waypoints, interpolation: "quintic_spline", max_velocity: 0.8, max_acceleration: 2.0, coordinate_frame: "world" )
Safety & Error Handling
Safe Blocks
Wrap dangerous operations in safe blocks with automatic error recovery.
safe { robot.arm.move_to(dangerous_position) robot.hand.apply_force(10N) } on_collision { robot.emergency_stop() robot.retract_to_safe_position() } on_timeout { robot.abort_motion() } on_error(err) { log_error("Motion failed: " + err.message) robot.recover() }
Emergency Handling
# Always-active emergency monitors always { if robot.sensors.emergency_stop.pressed() { robot.emergency_stop() break_all_behaviors() } if robot.sensors.tilt.angle() > 30deg { robot.balance_recovery() } } # Watchdog timers watchdog(timeout: 1s) { robot.heart_beat() } on_timeout { robot.safe_shutdown() }
Concurrency & Timing
Concurrent Operations
# Parallel execution concurrent { robot.head.track_target(person) robot.left_arm.wave() repeat 3 robot.right_arm.hold_position() robot.speak("Hello there!") } then { robot.return_to_neutral() } # Race conditions race { robot.sensors.wait_for_voice_command() -> handle_voice() robot.sensors.wait_for_gesture() -> handle_gesture() timeout(10s) -> robot.prompt_user() }
Real-time Constraints
# Real-time execution blocks realtime(priority: high, deadline: 10ms) { let imu_data = robot.sensors.imu.read() robot.balance_controller.update(imu_data) } # Periodic tasks periodic(rate: 100hz) { robot.low_level_control_loop() } # Temporal modifiers robot.arm.move() for 3s robot.head.scan() repeat 5 times robot.walk() until obstacle_detected()
Testing Framework
RoboLang includes a lightweight, deterministic testing framework specifically designed for robotics behaviors.
Test Execution
# Run tests robolang test <file_or_dir> # Run with simulation provider robolang --provider=sim test tests/
Test Structure
import math # Optional setup/teardown fn setup() { robot.initialize() } fn teardown() { robot.reset() } # Test functions must start with test_ fn test_constants() { assert_approx(math.pi, 3.14159, 0.0001) } fn test_robot_speaks() { spy_reset() robot.speak("hello") robot.speak("world") assert_called("speak") assert_called_times("speak", 2) } fn divide(a, b) { return a / b } fn test_throws() { assert_throws("divide", 1, 0) }
Assertions & Spies
- •
assert_true(cond, [message])
- Assert condition is true - •
assert_equal(a, b, [message])
- Assert values are equal - •
assert_approx(a, b, tol, [message])
- Assert approximate equality - •
assert_throws(fn_name, ...args)
- Assert function throws error - •
spy_reset()
- Clear recorded API calls - •
spy_calls()
- Get array of recorded calls
Complete Examples
Pick and Place Task
fn pick_and_place(object_name, target_location) { # Visual search robot.head.scan_for_object(object_name, timeout: 10s) let object = vision.find_object(object_name) if object == null { return error("Object not found: " + object_name) } safe { # Approach object robot.approach_position(object.pose, clearance: 0.1m) # Grasp robot.right_hand.open() robot.right_arm.move_to(object.grasp_pose, speed: 0.3) robot.right_hand.close_until_contact() # Verify grasp robot.right_arm.lift(height: 0.05m) if not robot.right_hand.has_object() { return error("Failed to grasp object") } # Transport robot.right_arm.move_to(target_location, speed: 0.5) robot.right_hand.open() robot.right_arm.retract() } on_error(err) { robot.right_hand.open() robot.right_arm.move_to_safe_position() return error("Pick and place failed: " + err.message) } return success("Object successfully moved") }
Interactive Conversation
import speech fn conversation_loop() { robot.speak("Hi! I'm ready to chat.") while true { let user_input = speech.listen(timeout: 30s) if user_input == null { robot.speak("I didn't hear anything.") continue } match user_input.lower() { case x if x.contains("goodbye") -> { robot.speak("Goodbye!") break } case x if x.contains("dance") -> { robot.speak("I'd love to dance!") robot.perform_dance_routine() } case x if x.contains("joke") -> { robot.speak("Why don't robots panic? Nerves of steel!") } case _ -> { robot.speak("Tell me more about that.") } } wait(500ms) } }
HTTP Integration
import http # Simple GET request let res = http.get("https://api.example.com/status", {Accept: "application/json"}) print(res.status_code) # integer print(res.body) # string # POST JSON data let payload = { robot_id: "unit-42", location: robot.get_position(), battery: robot.battery.percentage() } let response = http.post("https://api.example.com/telemetry", payload, {Authorization: "Bearer TOKEN"}) if response.status_code == 201 { robot.speak("Telemetry uploaded successfully") }
Hardware Providers
Unitree G1 Provider
- • Robust JSON bridge with request IDs and explicit initialization
- • Capability discovery via
get_capabilities
- • Internal motion IDs for asynchronous motions
- • Full support for G1 humanoid platform features
Simulation Provider
Run with the simulation provider for deterministic testing and introspection:
# Run with simulation robolang --provider=sim path/to/program.rob # Access simulation diagnostics robot.sim.last_speak() # Last spoken text robot.sim.speak_count() # Number of speak calls robot.sim.arm_target("right") # Last arm target robot.sim.wave_count() # Number of waves
Implementation Details
RoboLang is implemented as an interpreted language with the following characteristics:
- •Parser: Recursive descent parser for clean syntax
- •Runtime: Tree-walking interpreter built in Go with real-time scheduling
- •Type System: Dynamic typing with static analysis for safety
- •Memory Management: Garbage collected with deterministic cleanup for real-time sections
- •Hardware Interface: Plugin architecture for different robot platforms
- •Safety: Built-in bounds checking and emergency stop integration
Ready to Start Building?
Get your developer kit and start programming robots today.