原始动作转换为实际环境中的动作:action
获取当前推理得到的目标位置姿态:this_target_poses = action
计算每个动作的时间戳:action_timestamps
设置动作执行延迟:action_exec_latency = 0.01
获取当前时间:curr_time = time.time()
判断哪些动作是新的:is_new = action_timestamps > (curr_time + action_exec_latency)
如果没有新的动作:
使用最后一个动作:this_target_poses = this_target_poses[[-1]]
计算下一个可用步骤的索引和时间戳:next_step_idx、action_timestamp
更新动作时间戳:action_timestamps = np.array([action_timestamp])
有新的动作:
更新动作:this_target_poses = this_target_poses[is_new]
更新动作时间戳:action_timestamps = action_timestamps[is_new]
将传入的动作数据action转换为姿势数据pose,并安排到各个机械臂和夹爪的路径点中去执行:actions=this_target_poses、timestamps=action_timestamps
动作数组转换为姿势:
获取当前时间:receive_time = time.time()
找出时间戳中晚于当前时间的部分:is_new = timestamps > receive_time
选择出新的动作:new_actions = actions[is_new]
选择出新的时间戳:new_timestamps = timestamps[is_new]
确保每个机器人的动作数据段长度为7:assert new_actions.shape[1] // len(self.robots) == 7
使用嵌套循环遍历每个新动作和每个机器人:
机械臂动作的延迟时间: r_latency=0.1
夹爪动作的延迟时间: g_latency=0.1
提取当前机械臂的位置动作数据段:r_actions = new_actions[i, 7 * robot_idx + 0: 7 * robot_idx + 6]
提取当前夹爪动作数据段:g_actions = new_actions[i, 7 * robot_idx + 6]
安排路径点:
调度机械臂路径点:robot.schedule_waypoint(<br> pose=r_actions,# 安排机械臂的位置动作<br> target_time=new_timestamps[i] - r_latency # 调度到目标时间,考虑机械臂动作延迟)
调度夹爪路径点:gripper.schedule_waypoint(<br> pos=g_actions, # 安排夹爪的位置动作<br> target_time=new_timestamps[i] - g_latency # 调度到目标时间,考虑夹爪动作延迟)