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.
- Function:
on_eventfrom the lua module - Parameters:
- event: [str] Event name:
"robot_state"Redefine Robot State Change"robot_collide"Redefine Robot Collision"robot_stop"Redefine Robot Stop"task_exit"Redefine Task End"task_pause"Redefine Task Pause"task_resume"Redefine Task Resume
- func: [function] Function to execute when event is received
- event: [str] Event name:
- Returns: none
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_statefrom the lua module - Parameters:
- 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_collidefrom 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_stopfrom the lua module - Parameters:
- 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_exitfrom the lua module - Parameters:
- 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_pausefrom 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_resumefrom the lua module - Parameters: none
- Returns: none
Example
function on_task_resume()
resume_move()
end
