看了《MoveIt玩转双臂机器人 • 李江浩》

里面只有单机械臂运行的示例

可一些作业场景需要双臂并发作业,甚至协同作业

那么问题来了

如何用ROS对两个乃至多个机械臂控制进行仿真?

********************************************************************************

对《MoveIt玩转双臂机器人 • 李江浩》的double_arm_demo moveit_fk_demo.py进行了修改:

  1. 同时导入left_arm和right_arm
  2. 控制left_arm关节运动到目标位置1,控制right_arm关节运动到目标位置2

运行结果异常,right_arm的运动过程似乎瞬间结束,直接到达目标位置2,如视频所示:

ROS double_arm 运行仿真

哪位能帮忙看看问题的原因和解决方案么?

rosrun double_arm_demo moveit_fk_demo.py代码如下:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright 2019 Wuhan PS-Micro Technology Co., Itd.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import rospy, sys
import moveit_commander

class MoveItFkDemo:
    def __init__(self):
        # 初始化move_group的API
        moveit_commander.roscpp_initialize(sys.argv)

        # 初始化ROS节点
        rospy.init_node('moveit_fk_demo', anonymous=True)
 
        # 初始化需要使用move group控制的机械臂中的arm group
        arm = moveit_commander.MoveGroupCommander('left_arm')
        arm2 = moveit_commander.MoveGroupCommander('right_arm')
        
        # 设置机械臂运动的允许误差值
        arm.set_goal_joint_tolerance(0.001)
        arm2.set_goal_joint_tolerance(0.001)

        # 设置允许的最大速度和加速度
        arm.set_max_acceleration_scaling_factor(0.5)
        arm.set_max_velocity_scaling_factor(0.5)
        
        arm2.set_max_acceleration_scaling_factor(0.5)
        arm2.set_max_velocity_scaling_factor(0.5)
        
        # 控制机械臂先回到初始化位置
        arm.set_named_target('left_home')
        arm.go()
        rospy.sleep(1)

        arm2.set_named_target('right_home')
        arm2.go()
        rospy.sleep(1)
         
        # 设置机械臂的目标位置,使用六轴的位置数据进行描述(单位:弧度)
        joint_positions = [0.0, -0.8, 1.44, 0.98, 0.0]
        arm.set_joint_value_target(joint_positions)

        #arm.set_named_target('left_forward')       
        # 控制机械臂完成运动
        arm.go()
        rospy.sleep(1)

        # 设置机械臂的目标位置,使用六轴的位置数据进行描述(单位:弧度)
        joint_positions2 = [0.0, 0.8, -1.44, -0.98, 0.0]
        arm2.set_joint_value_target(joint_positions2)

        #arm.set_named_target('left_forward')       
        # 控制机械臂完成运动
        arm2.go()
        rospy.sleep(1)

        # 控制机械臂先回到初始化位置
        arm.set_named_target('left_home')
        arm.go()
        rospy.sleep(1)
        
        # 关闭并退出moveit
        moveit_commander.roscpp_shutdown()
        moveit_commander.os._exit(0)

if __name__ == "__main__":
    try:
        MoveItFkDemo()
    except rospy.ROSInterruptException:
        pass

测试shell指令

roslaunch double_arm_moveit_config demo.launch 

rosrun double_arm_demo moveit_fk_demo.py