ROS-Moveit和Gazebo联合仿真

news2024/11/18 15:28:21

文章目录

    • URDF功能包配置
      • config
      • launch
      • CMakeLists.txt
      • package.xml
      • urdf文件
    • Moveit功能包配置
      • config
      • launch
    • 运行

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.urdf文件

<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>

修改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

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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/729892.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Tomcat使用数据库连接池数据库

1.连接池技术的作用 数据池允许应用程序重复使用一个现有的数据库连接&#xff0c;而不是重新建立一个。这项技术能明显地提高对数据库操作的性能。 2.什么是连接池技术 数据库连接池在初始化时将创建一定数量的数据库连接&#xff0c;具体数量的由连接池的最小数据库连接数来设…

什么是Uniswap v3?

目录 1. 集中化流动性&#xff1a;2. 集中化资金池管理&#xff1a;3. 多个流动性池&#xff1a;4. 高级订单类型&#xff1a;5. 协议费用优化&#xff1a; Uniswap v3 是去中心化交易所 Uniswap 的第三个主要版本&#xff0c;它于2021年5月发布。相比于 Uniswap v2&#xff0c…

内嵌tomcat使用方式(读取web.xml)

pom <?xml version"1.0" encoding"UTF-8"?> <project xmlns"http://maven.apache.org/POM/4.0.0"xmlns:xsi"http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation"http://maven.apache.org/POM/4.0.0 http…

微信小程序之单选题按钮切换背景

先来效果图 未选效果 已选效果 上代码 <view class"questionClass">问题1&#xff1a;夜晚落地西安咯&#xff0c;你最想先去哪里看看呢&#xff1f;</view><view class"single"><ul class"box"><li v-for"(s,i…

Python获取豆丁文档数据内容, 保存word文档

前言 嗨喽&#xff0c;大家好呀~这里是爱看美女的茜茜呐 开发环境: python 3.8 pycharm 模块使用: requests --> pip install requests re base64 docx --> pip install python-docx 第三方模块安装方法&#xff1a; win R 输入cmd 输入安装命令 pip install …

第N4周:使用Word2vec实现文本分类

目录 二、数据预处理1.加载数据2.构建词典3.生成数据批次和迭代器 二、模型构建1.搭建模型2.初始化模型3.定义训练与评估函数 三、训练模型1.拆分数据集并运行模型2.测试指定数据 &#x1f368; 本文为&#x1f517;365天深度学习训练营 中的学习记录博客&#x1f356; 原作者&…

原子操作CAS

CAS 悲观锁 具有强烈的独占和排他特性。在有悲观锁的情况下&#xff0c;对数据进行处理&#xff0c;数据会处于锁定状态。前面讲到的synchronized同一时间只允许一个线程访问某块资源&#xff0c;其他线程处于阻塞状态&#xff0c;就是一个独占锁&#xff0c;是悲观锁中的一种…

语义分割大模型SAM论文阅读(二)

论文链接 Segment Anything 开源代码链接 SAM 论文阅读 摘要 We introduce the Segment Anything (SA) project: a new task, model, and dataset for image segmentation. Using our efficient model in a data collection loop, we built the largest segmentation dat…

Presto启动报错:No such file or directory

1. 问题描述 1.1 无法通过sudo -u presto启动 使用低版本的Presto时&#xff0c;在root用户下&#xff0c;通过如下命令切换到presto用户、启动Presto服务&#xff1a; sudo -u presto /install_dir/bin/launcher start # 或直接restart&#xff0c;包含stop和start操作 sudo …

12.3 ARM寄存器组织

目录 ARM寄存器组织&#xff08;一&#xff09; 寄存器 概念 作用 分类 ARM寄存器 ARM寄存器组织&#xff08;二&#xff09; 专用寄存器 R15(PC,Program Counter) R14(LR,Link Register) R13(SP,Stack Pointer) ARM寄存器组织&#xff08;三&#xff09; CPSR寄存…

【Vue面试题系列】二

Vue3中的Treeshaking特性是什么&#xff1f;并举例说明。 是什么&#xff1f; treeshaking是一种通过清除多余代码方式来优化项目打包体积的技术。 简单来讲&#xff0c;就是在保持代码运行结果不变的前提下&#xff0c;去掉无用的代码。 如果把代码打包比作制作蛋糕&#xff…

将xxl-job集成到自己的项目中,部署并测试

文章目录 1、添加依赖2、application.yml 配置3、 新建配置类4、创建任务5、将项目打包&#xff0c;在服务器上运行6、编辑执行器机器地址7、测试 1、添加依赖 <dependency><groupId>com.xuxueli</groupId><artifactId>xxl-job-core</artifactId>…

常见排序算法—面试编程题2023

常见排序算法—面试编程题2023 最近在看一些面试题&#xff0c;发现很多面试过程中都会要求手写排序编程题&#xff0c;经过一番查找整理&#xff0c;可以快速学习和使用相关排序算法题&#xff0c;通俗易懂&#xff0c;手撕代码吊打面试官。 一、冒泡排序 冒泡排序 是一种简…

ETHERNET/IP 转ETHERCAT连接倍福和欧姆龙PLC的配置方法

ETHERNET/IP和ETHERCAT是两种不同的协议&#xff0c;它们在工业生产中都有广泛的应用。然而&#xff0c;由于协议不同&#xff0c;这两种设备之间无法通讯&#xff0c;这给工业生产带来了很大的麻烦。而远创智控YC-EIP-ECT网关应运而生&#xff0c;它能够连接到ETHERNET/IP总线…

路径规划算法:基于世界杯优化的路径规划算法- 附代码

路径规划算法&#xff1a;基于世界杯优化的路径规划算法- 附代码 文章目录 路径规划算法&#xff1a;基于世界杯优化的路径规划算法- 附代码1.算法原理1.1 环境设定1.2 约束条件1.3 适应度函数 2.算法结果3.MATLAB代码4.参考文献 摘要&#xff1a;本文主要介绍利用智能优化算法…

合合信息AI图像内容安全新技术亮相WAIC2023,防范“生成式造假”

开年以来&#xff0c;多个图像生成软件在全球迅速蹿红&#xff0c;其作画逼真程度“技惊四座”。AI一路“狂飙”&#xff0c;让生成、篡改等多形式的图片伪造的门槛变得更低&#xff0c;由此引发的隐患也令人忧虑。 图像是信息的主要载体之一&#xff0c;利用AI进行图像造假的…

MachineLearningWu_4_GradientDescent

我们在上一个章节中学习了损失函数&#xff0c;我们的最终目的是要求得损失函数最小化的weight和bias&#xff0c;那么如何做到这一点呢&#xff0c;我们引入梯度下降算法&#xff0c; 请注意&#xff0c;对于Linear Regression MSE&#xff0c;你得到的J(w, b)和w, b的图必然…

AIGC - Stable Diffusion 多重控制网络 ControlNet (OpenPose + Depth) 配置

欢迎关注我的CSDN&#xff1a;https://spike.blog.csdn.net/ 本文地址&#xff1a;https://spike.blog.csdn.net/article/details/131603523 Multi-ControlNet 是 Stable Diffusion 的一个功能&#xff0c;让用户用不同的空间条件来控制图像生成的过程。例如&#xff0c;可以用…

【高并发网络通信架构】2.引入多线程实现多客户端连接的tcp服务端

目录 一&#xff0c;往期文章 二&#xff0c;代码实现 一&#xff0c;往期文章 【高并发网络通信架构】1.Linux下实现单客户连接的tcp服务端 二&#xff0c;代码实现 关键代码 因为accept是阻塞等待客户端连接&#xff0c;当客户端连接成功后才会执行accept后面的代码&…

简介Maven结构与配置方法

一、Maven是什么 Maven是apache旗下的一个开源项目&#xff0c;是一款用于管理和构建java项目的工具。 它有什么用呢&#xff1f; 比如我以前要IOUtils这个包&#xff0c;那要到网站下去下载下来&#xff0c;再导入。 当jar包多的时候&#xff0c;一个一个导出&#xff0c;…