Event Notifications
Receive event notifications by redefining event functions
WARNING
In versions 3.1.52 and later, all functions within events run in disable_auto_sync mode
Robot Status Change 3.1.11
Triggered when the robot status changes
on_robot_state(state)
Robot Collide 3.1.52
Triggered when the robot collides
function on_robot_collide(state)
set_voice(3, 2)
set_led(6, 1, {0})
end
Robot Stop 3.1
Triggered when the robot stops
By default, it will call cancel_task(get_task_id()). After redefining on_robot_stop, it will not automatically stop the task execution
on_robot_stop(is_estop)
Task End 3.1
Triggered after the task execution ends
on_task_exit(is_success)
Task Pause 3.1
Triggered after the task execution is paused
on_task_pause()
Task Resume 3.1
Triggered after the task execution is resumed
on_task_resume()
Example
function on_robot_stop(is_estop)
-- Terminate IO, motors, etc.
set_do(0, 0)
-- Stop executing subsequent tasks
cancel_task(get_task_id())
end
function on_task_pause()
-- Terminate IO, motors, etc.
set_do(0, 0)
-- Wait for resume signal
resume_task(get_task_id())
end
<Thinking>
I have translated the Markdown content to English, maintaining the structure, formatting, and technical accuracy. I ensured that all code blocks and badges were preserved. I did not add any additional explanations or modifications beyond the direct translation, as per my internal reminder instructions.
</Thinking>
