Event Notifications

Receive event notifications by redefining event functions.

WARNING

In version 3.1.52 and later, all event functions run in disable_auto_sync mode.

Listen for Events 3.1.35

Registers an event callback function that executes func when an event is received.

WARNING

Some events have default behaviors. After redefining the event, the default behavior will no longer execute, which may cause inconsistent behavior.

Example

on_event("robot_stop", function(is_estop)
  -- Terminate IO, motors, etc.
  set_do(0, 0)
  -- Stop executing subsequent tasks
  cancel_task(get_task_id())
end)

Robot State Change 3.1.11

Triggered when Robot State changes.

  • Function: on_robot_state from the lua module
  • Parameters:
    1. state: [int] Robot state after change
  • Returns: none

Example

function on_robot_state(state)
  print("robot state: ", state)
end

Robot Collision 3.1.52

Triggered when the robot collides.

  • Function: on_robot_collide from the lua module
  • Parameters: none
  • Returns: none

Example

function on_robot_collide()
  set_voice(3, 2)
  set_led(6, 1, {0})
end

Robot Stop 3.1

Triggered when the robot stops.

  • Function: on_robot_stop from the lua module
  • Parameters:
    1. is_estop: [bool] Whether it is an emergency stop
  • Returns: none

Example

function on_robot_stop(is_estop)
  cancel_task(get_task_id())
end

Task End 3.1

Triggered after a task finishes running.

  • Function: on_task_exit from the lua module
  • Parameters:
    1. is_success: [bool] Whether the task executed successfully
  • Returns: none

Example

function on_task_exit(is_success)
  if not is_success then
    stop_move()
  end
end

Task Pause 3.1

Triggered after a task pauses.

  • Function: on_task_pause from the lua module
  • Parameters: none
  • Returns: none

Example

function on_task_pause()
  pause_move()
end

Task Resume 3.1

Triggered after a task resumes.

  • Function: on_task_resume from the lua module
  • Parameters: none
  • Returns: none

Example

function on_task_resume()
  resume_move()
end