Performance: Why actions for long-running tasks
This concept affects the responsiveness and smoothness of robot control interfaces during long-running operations.
import actionlib from your_package.msg import LongTaskAction, LongTaskGoal def execute_long_task_action(): client = actionlib.SimpleActionClient('long_task', LongTaskAction) client.wait_for_server() goal = LongTaskGoal() client.send_goal(goal) # Non-blocking, can handle feedback and preemption client.wait_for_result() return client.get_result()
def execute_long_task(): # Blocking call result = do_heavy_computation() return result # Called directly in main thread execute_long_task()
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Blocking long task in main thread | N/A | Blocks input events | Blocks UI updates | [X] Bad |
| Using ROS actions for long tasks | N/A | No blocking | Smooth UI updates | [OK] Good |
client.send_goal(goal_msg)
while not client.wait_for_result(timeout=1.0):
print('Working...')
result = client.get_result()
print(result)client.send_goal(goal_msg)
client.wait_for_result()
print('Result:', client.get_result())Pass the test and this pattern moves unknown