从零开始的机械臂yolov5抓取gazebo仿真(四)

news/2024/7/11 1:02:11 标签: YOLO, 机器人, gazebo, ROS, 机械臂

Moveit与Gazebo联合仿真

上一篇博客已经将moveit!配置完毕,然而想要让moveit!控制gazebo中的机械臂,还需要进行一些接口的配置。现在我们有的功能包为sunday_description、sunday_moveit_config这两个功能包。且已经配置好xacro文件,本篇内容需要进行gazebo功能包的配置以及moveit功能包的文件修改。

gazebo_2">sunday_gazebo

创建sunday_gazebo功能包

catkin_create_pkg sunday_gazebo roscpp rospy std_msgs

创建launch、config、world、scripts等文件夹,其列表如下所示

.
├── CMakeLists.txt
├── config
├── include
├── launch
├── package.xml
├── scripts
├── src
└── world

配置关节轨迹控制器

创建sunday_gazebo/config/sunday_trajectory_control.yaml文件,用于配置关节轨迹控制器,代码如下:

sunday:
  arm_joint_controller:
    type: "position_controllers/JointTrajectoryController"
    joints:
      - joint_1
      - joint_2
      - joint_3
      - joint_4
      - joint_5
      - joint_6


    gains:
      joint_1:   {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
      joint_2:   {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
      joint_3:   {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
      joint_4:   {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
      joint_5:   {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}
      joint_6:   {p: 1000.0, i: 0.0, d: 0.1, i_clamp: 0.0}


对应创建sunday_gazebo/launch/sunday_trajectory_controller.launch文件,用于加载上述yaml文件代码如下:

<launch>

    <rosparam file="$(find sunday_gazebo)/config/sunday_trajectory_control.yaml" command="load"/>

    <node name="arm_controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
          output="screen" ns="/sunday" args="arm_joint_controller"/>

</launch>

配置关节状态控制器

创建sunday_gazebo/config/sunday_gazebo_joint_states.yaml文件,用于配置关节状态控制器,代码如下:

sunday:
  # Publish all joint states -----------------------------------
  joint_state_controller:
    type: joint_state_controller/JointStateController
    publish_rate: 50  

对应创建sunday_gazebo/launch/sunday_gazebo_states.launch文件,用于加载上述yaml文件代码如下:

<launch>
    <!-- 将关节控制器的配置参数加载到参数服务器中 -->
    <rosparam file="$(find sunday_gazebo)/config/sunday_gazebo_joint_states.yaml" command="load"/>

    <node name="joint_controller_spawner" pkg="controller_manager" type="spawner" respawn="false"
          output="screen" ns="/sunday" args="joint_state_controller" />

    <!-- 运行robot_state_publisher节点,发布tf  -->
    <node name="robot_state_publisher" pkg="robot_state_publisher" type="robot_state_publisher"
        respawn="false" output="screen">
        <remap from="/joint_states" to="/sunday/joint_states" />
    </node>

</launch>

gazebo_90">配置gazebo环境

创建sunday_gazebo/launch/sunday_gazebo_world.launch文件,用于加载gazebo环境,代码如下:

<launch>

  <!-- these are the arguments you can pass this launch file, for example paused:=true -->
  <arg name="paused" default="false"/>
  <arg name="use_sim_time" default="true"/>
  <arg name="gui" default="true"/>
  <arg name="headless" default="false"/>
  <arg name="debug" default="false"/>

  <!-- We resume the logic in empty_world.launch -->
  <include file="$(find gazebo_ros)/launch/empty_world.launch">
    <arg name="debug" value="$(arg debug)" />
    <arg name="gui" value="$(arg gui)" />
    <arg name="paused" value="$(arg paused)"/>
    <arg name="use_sim_time" value="$(arg use_sim_time)"/>
    <arg name="headless" value="$(arg headless)"/>
    <arg name="world_name" value="$(find sunday_gazebo)/world/feeding_place.world"/>
  </include>

  <!-- Load the URDF into the ROS Parameter Server -->
  <param name="robot_description" command="$(find xacro)/xacro --inorder '$(find sunday_description)/urdf/sunday.xacro'" /> 


  <!-- Run a python script to the send a service call to gazebo_ros to spawn a URDF robot -->
  <node name="urdf_spawner" pkg="gazebo_ros" type="spawn_model" respawn="false" output="screen"
	args="-urdf -model sunday -param robot_description"/>
</launch>

配置moveit功能包文件

创建/修改sunday_moveit_config/config/controllers_gazebo.yaml文件,用于配置moveit!控制器接口,代码如下:

controller_manager_ns: controller_manager
controller_list:
  - name: sunday/arm_joint_controller
    action_ns: follow_joint_trajectory
    type: FollowJointTrajectory
    default: true
    joints:
      - joint_1
      - joint_2
      - joint_3
      - joint_4
      - joint_5
      - joint_6

修改sunday_moveit_config/launch/sunday_moveit_controller_manager.launch.xml,代码如下:

<launch>

  <!-- loads moveit_controller_manager on the parameter server which is taken as argument 
    if no argument is passed, moveit_simple_controller_manager will be set -->
  <arg name="moveit_controller_manager" default="moveit_simple_controller_manager/MoveItSimpleControllerManager" />
  <param name="moveit_controller_manager" value="$(arg moveit_controller_manager)"/>

  <!-- loads ros_controllers to the param server -->
  <rosparam file="$(find sunday_moveit_config)/config/controllers_gazebo.yaml"/>
</launch>

创建/修改sunday_moveit_config/launch/moveit_planning_execution.launch,用于加载planning_group等moveit核心功能,代码如下:

<launch>
 <!-- # The planning and execution components of MoveIt! configured to 
 # publish the current configuration of the robot (simulated or real)
 # and the current state of the world as seen by the planner -->
 <include file="$(find sunday_moveit_config)/launch/move_group.launch">
  <arg name="publish_monitored_planning_scene" value="true" />
 </include>

 <!-- # The visualization component of MoveIt! -->
 <include file="$(find sunday_moveit_config)/launch/moveit_rviz.launch">
  <arg name="config" value="true" />
 </include>

  <!-- We do not have a robot connected, so publish fake joint states -->
  <node name="joint_state_publisher" pkg="joint_state_publisher" type="joint_state_publisher">
    <param name="/use_gui" value="false"/> 
    <rosparam param="/source_list">[/sunday/joint_states]</rosparam>
  </node>

</launch>

修改sunday_moveit_config/launch/moveit_rviz.launch,使用新版配置工具生成的moveit_rviz.launch文件有些许问题,代码如下:

<launch>

  <arg name="debug" default="false" />
  <arg unless="$(arg debug)" name="launch_prefix" value="" />
<arg     if="$(arg debug)" name="launch_prefix" value="gdb --ex run --args" />

  <arg name="config" default="false" />
  <arg unless="$(arg config)" name="command_args" default="" />
  <arg     if="$(arg config)" name="command_args" default="-d $(find sunday_moveit_config)/launch/moveit.rviz" />

  <node name="$(anon rviz)" launch-prefix="$(arg launch_prefix)" pkg="rviz" type="rviz" respawn="false"
	args="$(arg command_args)" output="screen">
    <rosparam command="load" file="$(find sunday_moveit_config)/config/kinematics.yaml"/>
  </node>

</launch>

配置总bringup.launch文件

配置sunday_gazebo/launch/sunday_moveit_bringup.launch,用于加载所有launch文件,代码如下:

<launch>
  
    <!-- Launch Gazebo  -->
    <include file="$(find sunday_gazebo)/launch/sunday_gazebo_world.launch" />

    <!-- ros_control arm launch file -->
    <include file="$(find sunday_gazebo)/launch/sunday_gazebo_states.launch" />   

    <!-- ros_control trajectory control dof arm launch file -->
    <include file="$(find sunday_gazebo)/launch/sunday_trajectory_controller.launch" />

    <!-- moveit launch file -->
    <include file="$(find sunday_moveit_config)/launch/moveit_planning_execution.launch">
    </include>
</launch>

至此gazebo与moveit功能包配置完毕,将功能包进行编译。sunday_gazebo列表如下

.
├── CMakeLists.txt
├── config
│   ├── sunday_gazebo_joint_states.yaml
│   └── sunday_trajectory_control.yaml
├── include
│   └── sunday_gazebo
├── launch
│   ├── sunday_bringup_moveit.launch
│   ├── sunday_gazebo_states.launch
│   ├── sunday_gazebo_world.launch
│   └── sunday_trajectory_controller.launch
├── package.xml
├── scripts
├── src
└── world
    └── feeding_place.world

world为配置好的抓取仿真场景。

联合仿真测试

运行代码roslaunch sunday_gazebo sunday_bringup_moveit.launch,可以看到同时加载moveit和gazebo场景,在Query栏,将Goal State设置为scan_food,在Commands栏点击Plan & Execute,可以看到gazebo中的机械臂运行到scan_food姿态。
在这里插入图片描述

小结

至此moveit!与gazebo联合仿真配置完毕,配置原理部分不展开介绍,各位可以去古月居学习这部分的原理内容。接下去将讲解如何用yolo训练自己的数据集。

参考资料

1.古月居机械臂课程


http://www.niftyadmin.cn/n/168953.html

相关文章

锁屏面试题百日百刷-Spark篇(九)

锁屏面试题百日百刷&#xff0c;每个工作日坚持更新面试题。锁屏面试题app、小程序现已上线&#xff0c;官网地址&#xff1a;https://www.demosoftware.cn。已收录了每日更新的面试题的所有内容&#xff0c;还包含特色的解锁屏幕复习面试题、每日编程题目邮件推送等功能。让你…

数据大放送之全国行政边界数据下载

一、前言作为一名Giser&#xff0c;可能在某些时候会碰到一个问题&#xff0c;想要行政矢量数据&#xff0c;但是东找西找&#xff0c;没有可以入自己法眼的&#xff0c;今天就给大家送上两个免费下载的网站&#xff0c;请大家务必收藏好。&#xff08;1&#xff09;阿里云Data…

皕杰报表工具之报表日志和tomcat日志

我们在调试皕杰报表的过程中&#xff0c;通过浏览器访问有时会出现错误&#xff0c;比如查不出数据&#xff0c;500错误等&#xff0c;不知是哪里出了问题&#xff1f;这时候我们需要查看报表日志&#xff0c;看看报表运行是否有错误信息。 皕杰报表日志的位置位于wabapps/ifac…

Python实现GWO智能灰狼优化算法优化卷积神经网络分类模型(CNN分类算法)项目实战

说明&#xff1a;这是一个机器学习实战项目&#xff08;附带数据代码文档视频讲解&#xff09;&#xff0c;如需数据代码文档视频讲解可以直接到文章最后获取。1.项目背景灰狼优化算法(GWO)&#xff0c;由澳大利亚格里菲斯大学学者 Mirjalili 等人于2014年提出来的一种群智能优…

数据库--进阶版-11--SQL优化

1.插入数据 insert优化&#xff1a; 例如要插入下面这些 insert into tb_test values(1,tom); insert into tb_test values(2,cat); insert into tb_test values(3,jerry); 我们可以通过以下几个方面进行操作&#xff1a; >批量插入&#xff08;如果一次性要插入多条…

【Docker】Mysql主从复制Redis集群

文章目录安装mysql主从复制新建主服务器容器实例3307配置文件 my.cnf修改完配置后重启master实例 docker restart mysql-master进入mysql-master容器 docker exec -it mysql-master /bin/bash、mysql -uroot -prootmaster容器实例内创建数据同步用户 CREATE USER slave% IDENTI…

Apache Doris 1.2.3 Release 版本正式发布

亲爱的社区小伙伴们&#xff0c;我们很高兴地宣布&#xff0c;Apache Doris 于 2023 年 3 月 20 日迎来 1.2.3 Release 版本的正式发布&#xff01;在新版本中包含超过 200 项功能优化和问题修复。同时&#xff0c;1.2.3 版本作为 1.2 LTS 的迭代版本&#xff0c;更加稳定易用&…

计算机网络(性能指标)

1.1标准化工作及相关组织1.1.1标准化工作要实现不同厂商之间的硬件、软件之间相互连通&#xff0c;必须遵从统一标准。分类&#xff1a;法定标准 &#xff08;OSI&#xff09;事实标准&#xff08;TCP/IP协议&#xff09;1.1.2标准化工作相关组织&#xff1a;国际标准化组织ISO…