ROS-Moveit和Gazebo联合仿真(二)

URDF功能包配置

config

首先在SW2URDF生成的功能包下Config目录下新建文件joint_trajectory_controller.yaml

robot_arm_controller:
  type: "position_controllers/JointTrajectoryController"
  joints: [joint1, joint2, joint3, joint4, joint5, joint6]

hand_ee_controller:
  type: "position_controllers/JointTrajectoryController"
  joints: [joint_hand1, joint_hand2]

joint_state_controller:
  type: "joint_state_controller/JointStateController"
  publish_rate: 50 

launch

在launch文件目录下新建arm_urdf.launch文件

<launch>
	<arg name="arg_x" default="0.00" />
	<arg name="arg_y" default="0.00" />
	<arg name="arg_z" default="0.00" />
	<arg name="arg_R" default="0.00" />
	<arg name="arg_P" default="0.00" />
	<arg name="arg_Y" default="0.00" />

	<!--Urdf file path-->
	<param name="robot_description" textfile="$(find ros_robot_arm)/urdf/ros_robot_arm.urdf"/>

	<!--spawn a empty gazebo world-->
	<include file="$(find gazebo_ros)/launch/empty_world.launch" />
	<node name="tf_footprint_base" pkg="tf" type="static_transform_publisher" args="0 0 0 0 0 0 base_link base_footprint 40" />

	<!--spawn model-->
	<node name="spawn_urdf" pkg="gazebo_ros" type="spawn_model" args="-x $(arg arg_x) -y $(arg arg_y) -z $(arg arg_z) -Y $(arg arg_Y) -param robot_description -urdf -model ros_robot_arm -J joint1 0.0 -J joint2 0.0 -J joint3 0.0 -J joint4 0.0 -J joint5 0.0 -J joint6 0.0 -J joint_hand1 0.0 -J joint_hand2 0.0" />

	<!--Load and launch the joint trajectory controller-->
	<rosparam file ="$(find ros_robot_arm)/config/joint_trajectory_controller.yaml" command="load"/>
	<node name= "controller_spawner" pkg= "controller_manager" type="spawner" respawn="false" output="screen" args="joint_state_controller robot_arm_controller hand_ee_controller"/>
    
	<!-- Robot State Publisher for TF of each joint: publishes all the current states of the joint, then RViz can visualize -->
	<node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher" respawn="false" output="screen"/>
</launch>

CMakeLists.txt

添加如下信息

find_package(catkin REQUIRED
		message_generation
		roscpp
		rospy
		std_msgs
		geometry_msgs
		urdf
		xacro
		message_generation
)

catkin_package(CATKIN_DEPENDS
		geometry_msgs
		roscpp
		rospy
		std_msgs
)

package.xml

<package format="2">
  <name>ros_robot_arm</name>
  <version>1.0.0</version>
  <description>
    <p>URDF Description package for ros_robot_arm</p>
    <p>This package contains configuration data, 3D models and launch files
for ros_robot_arm robot</p>
  </description>
  <author>TODO</author>
  <maintainer email="TODO@email.com" />
  <license>BSD</license>
  <buildtool_depend>catkin</buildtool_depend>
   
  <build_depend>message_generation</build_depend>
  <build_depend>roscpp</build_depend>
  <build_depend>rospy</build_depend>
  <build_depend>std_msgs</build_depend>
  <build_depend>geometry_msgs</build_depend>
  <build_depend>urdf</build_depend>
  <build_depend>xacro</build_depend>
  <build_depend>message_generation</build_depend>

  <depend>roslaunch</depend>
  <depend>robot_state_publisher</depend>
  <depend>rviz</depend>
  <depend>joint_state_publisher_gui</depend>
  <depend>gazebo</depend>
  <depend>moveit_simple_controller_manager</depend>


  <build_export_depend>roscpp</build_export_depend>
  <build_export_depend>rospy</build_export_depend>
  <build_export_depend>std_msgs</build_export_depend>
  <build_export_depend>geometry_msgs</build_export_depend>
  <build_export_depend>urdf</build_export_depend>
  <build_export_depend>xacro</build_export_depend>
  <exec_depend>roscpp</exec_depend>
  <exec_depend>rospy</exec_depend>
  <exec_depend>std_msgs</exec_depend>
  <exec_depend>geometry_msgs</exec_depend>
  <exec_depend>urdf</exec_depend>
  <exec_depend>xacro</exec_depend>
  <exec_depend>message_runtime</exec_depend>

  <export>
    <architecture_independent />
  </export>
</package>

urdf文件

为机器人的各个joint添加控制器

<transmission name="link1_trans">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="joint1">
      <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
    </joint>
    <actuator name="link1_motor">
      <mechanicalReduction>50</mechanicalReduction>
      <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
    </actuator>
  </transmission>

  <transmission name="link2_trans">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="joint2">
      <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
    </joint>
    <actuator name="link2_motor">
      <mechanicalReduction>50</mechanicalReduction>
      <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
    </actuator>
  </transmission>

  <transmission name="link3_trans">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="joint3">
      <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
    </joint>
    <actuator name="link3_motor">
      <mechanicalReduction>50</mechanicalReduction>
      <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
    </actuator>
  </transmission>

  <transmission name="link4_trans">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="joint4">
      <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
    </joint>
    <actuator name="link4_motor">
      <mechanicalReduction>50</mechanicalReduction>
      <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
    </actuator>
  </transmission>

  <transmission name="link5_trans">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="joint5">
      <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
    </joint>
    <actuator name="link5_motor">
      <mechanicalReduction>50</mechanicalReduction>
      <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
    </actuator>
  </transmission>

  <transmission name="link6_trans">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="joint6">
      <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
    </joint>
    <actuator name="link6_motor">
      <mechanicalReduction>50</mechanicalReduction>
      <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
    </actuator>
  </transmission>

  <transmission name="link_hand1_trans">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="joint_hand1">
      <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
    </joint>
    <actuator name="link_hand1_motor">
      <mechanicalReduction>50</mechanicalReduction>
      <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
    </actuator>
  </transmission>

  <transmission name="link_hand2_trans">
    <type>transmission_interface/SimpleTransmission</type>
    <joint name="joint_hand2">
      <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
    </joint>
    <actuator name="link_hand2_motor">
      <mechanicalReduction>50</mechanicalReduction>
      <hardwareInterface>hardware_interface/PositionJointInterface</hardwareInterface>
    </actuator>
  </transmission>

  <gazebo>
    <plugin name="control" filename="libgazebo_ros_control.so">
      <robotNamespace>/</robotNamespace>
    </plugin>
  </gazebo>

<gazebo reference="base_link">
    <selfCollide>true</selfCollide>
    <material>Gazebo/Red</material>
  </gazebo>

  <gazebo reference="Link1">
    <selfCollide>true</selfCollide>
    <material>Gazebo/Orange</material>
  </gazebo>

  <gazebo reference="Link2">
    <selfCollide>true</selfCollide>
    <material>Gazebo/Turquoise</material>
  </gazebo>

  <gazebo reference="Link3">
    <selfCollide>true</selfCollide>
    <material>Gazebo/Yellow</material>
  </gazebo>

  <gazebo reference="Link4">
    <selfCollide>true</selfCollide>
    <material>Gazebo/Orange</material>
  </gazebo>

  <gazebo reference="Link5">
    <selfCollide>true</selfCollide>
    <material>Gazebo/Green</material>
  </gazebo>

  <gazebo reference="Link6">
    <selfCollide>true</selfCollide>
    <material>Gazebo/Red</material>
  </gazebo>

  <gazebo reference="Hand1">
    <selfCollide>true</selfCollide>
    <material>Gazebo/Grey</material>
  </gazebo>

  <gazebo reference="Hand2">
    <selfCollide>true</selfCollide>
    <material>Gazebo/Grey</material>
  </gazebo>

Moveit功能包配置

config

修改ros_controllers.yaml

moveit_sim_hw_interface:
  joint_model_group: hand_group
  joint_model_group: hand_close

generic_hw_control_loop:
  loop_hz: 300
  cycle_time_error_threshold: 0.01

hardware_interface:
  joints:
    - joint1
    - joint2
    - joint3
    - joint4
    - joint5
    - joint6
    - joint_hand1
    - joint_hand2
  sim_control_mode: 1 # 0: position, 1: velocity

joint_state_controller:
  type: joint_state_controller/JointStateController
  publish_rate: 50
controller_list:
  []

在config文件目录下新建new_ros_controllers.yaml

# JointTrajectoryController
controller_list:
  - name: robot_arm_controller
    action_ns: follow_joint_trajectory
    type: FollowJointTrajectory
    default: true
    joints:
    - joint1
    - joint2
    - joint3
    - joint4 
    - joint5
    - joint6
  - name: hand_ee_controller
    action_ns: follow_joint_trajectory
    type: FollowJointTrajectory
    joints:
    - joint_hand1
    - joint_hand2

launch

修改launch文件目录下simple_moveit_controller_manager.launch.xml

ros_controllers.yaml改为new_ros_controllers.yaml

<launch>
  <!-- Define the MoveIt controller manager plugin to use for trajectory execution -->
  <param name="moveit_controller_manager" value="moveit_simple_controller_manager/MoveItSimpleControllerManager" />

  <!-- Load controller list to the parameter server -->
  <rosparam file="$(find moveit_ros_robot_arm)/config/simple_moveit_controllers.yaml" />
  <rosparam file="$(find moveit_ros_robot_arm)/config/new_ros_controllers.yaml" />
</launch>

在launch文件目录下新建full_robot_arm_sim.launch

<launch>
	<!-- Launch Your robot arms launch file which loads the robot in Gazebo and spawns the controllers -->
	<include file = "$(find ros_robot_arm)/launch/arm_urdf.launch" />

	<!-- Launch Moveit Move Group Node -->
	<include file = "$(find moveit_ros_robot_arm)/launch/move_group.launch" />

	<!-- Run Rviz and load the default configuration to see the state of the move_group node -->
	<arg name="use_rviz" default="true" />
	<include file="$(find moveit_ros_robot_arm)/launch/moveit_rviz.launch" if="$(arg use_rviz)">
		<arg name="rviz_config" value="$(find moveit_ros_robot_arm)/launch/moveit.rviz"/>
	</include>

</launch>

运行

source ./devel/setup.bash
roslaunch moveit_ros_robot_arm full_robot_arm_sim.launch

首先确定最终姿态,然后Plan规划,再Execute执行,可看到Gazebo中机械臂开始运动

image-20230707181422728

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 3
    评论
你可以使用ROS-Melodic和MoveIt来进行UR5机械臂的仿真控制。以下是一个基本的步骤: 1. 安装ROS-Melodic:请根据ROS官方文档的说明安装ROS-Melodic。确保你的系统满足所有的依赖项。 2. 安装MoveIt:在终端中运行以下命令来安装MoveIt: ``` sudo apt-get install ros-melodic-moveit ``` 3. 配置工作空间:创建一个新的工作空间,并将其初始化为ROS工作空间。例如,你可以运行以下命令: ``` mkdir -p ~/catkin_ws/src cd ~/catkin_ws/ catkin_make ``` 4. 下载UR5机械臂包:在终端中运行以下命令来下载UR5机械臂的ROS软件包: ``` cd ~/catkin_ws/src git clone https://github.com/ros-industrial/universal_robot.git ``` 5. 下载MoveIt配置文件:在终端中运行以下命令来下载MoveIt配置文件: ``` cd ~/catkin_ws/src git clone https://github.com/ros-planning/moveit_resources.git ``` 6. 构建和编译:在终端中运行以下命令来构建和编译你的工作空间: ``` cd ~/catkin_ws/ catkin_make ``` 7. 启动仿真环境:在终端中运行以下命令来启动UR5机械臂的仿真环境: ``` roslaunch ur_gazebo ur5.launch ``` 8. 启动MoveIt RViz:在终端中运行以下命令来启动MoveIt RViz界面: ``` roslaunch ur5_moveit_config moveit_rviz.launch config:=true ``` 9. 进行控制:在RViz界面中,你可以使用MoveIt插件来规划和控制UR5机械臂的运动。你可以设置目标位置、执行运动等。 这些是基本的步骤,可以帮助你开始使用ROS-Melodic和MoveIt进行UR5机械臂的仿真控制。你可以根据自己的需求进行进一步的定制和开发。
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值