ROS Industrial教程(七)_笛卡尔规划和执行1

2024-04-28 04:58

本文主要是介绍ROS Industrial教程(七)_笛卡尔规划和执行1,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

笛卡尔规划和执行

引言

目标

接下来将介绍如何使用笛卡尔库中的各种组件来从半约束点轨迹规划和执行机器人路径。

包括:

·熟悉笛卡尔工作流程。

·了解如何加载自定义的笛卡尔RobotModel。

·了解如何从6DOF(Six degrees of freedom六自由度)工具姿势创建半约束轨迹。

·使用笛卡尔规划器规划机器人路径。

·将笛卡尔路径转换为MoveIt!消息以执行运动。

·在机器人上执行路径。

 

应用架构

接下来将配置练习完成过程中使用的所有软件包和文件。

 

获取并初始化工作区

cd ~/industrial_training/exercises/Descartes_Planning_and_Execution

cp -r template_ws ~/descartes_ws

cd ~/descartes_ws

source /opt/ros/melodic/setup.bash

catkin init

 

下载源依赖项

使用wstool命令下载src/.rosinstall文件中列出的存储库。

cd ~/descartes_ws/src/

wstool update

 

下载Debian依赖项

确保已安装并配置了rosdep工具。 然后,从工作区的src目录运行以下命令。

rosdep install --from-paths . --ignore-src -y

 

构建工作区

catkin build --cmake-args -G 'CodeBlocks - Unix Makefiles'

如果构建失败,请重新访问前面的两个步骤以确保下载了所有依赖项。

 

Source工作区

source ~/descartes_ws/devel/setup.bash

 

列出应用程序中的所有软件包

cd ~/descartes_ws/src

ls -la

plan_and_run:包含plan_and_run应用程序的源代码。 将通过编辑此程序包中的源文件来完成练习

ur5_demo_moveit_config:包含用于通过Moveit计划和执行机器人运动的支持文件。 该软件包是由Moveit设置助手生成的

ur5_demo_support:提供机器人定义为URDF文件。 该URDF在运行时由plan_and_run应用程序加载。

ur5_demo_descartes:为UR5手臂提供定制的笛卡尔机器人模型。 它使用逆运动学封闭形式解决方案; 这比MoveitStateAdapter使用的数值方法要快得多。

 

plan_and_run软件包

roscd plan_and_run

ls -la

src:应用程序源文件。

src/demo_application.cpp:包含应用程序实现代码的类源文件。

src/plan_and_run.cpp:应用程序主访问点。 它调用应用程序中的所有任务,并将它们包装在“ main”例程中。

src/tasks:一个目录,其中包含您在练习中取得进展时将要编辑或完成的所有源文件。

include:头文件

include/plan_and_run/demo_application.h:定义应用程序框架,并提供许多全局变量,以便在练习中的各个点传递数据。

launch:启动运行应用程序所需的文件

launch/demo_setup.launch:加载roscoremoveit和应用程序所需的运行时资源。

launch/demo_run.launch:作为ROS节点启动我们的应用程序主要可执行文件。

config:包含非关键配置文件的目录。

 

主应用程序源文件

在“ plan_and_run/src/plan_and_run_node.cpp”中,有如下代码:

int main(int argc,char** argv)

{

  ros::init(argc,argv,"plan_and_run");

  ros::AsyncSpinner spinner(2);

  spinner.start();

 

  // creating application

  plan_and_run::DemoApplication application;

 

  // loading parameters

  application.loadParameters();

 

  // initializing ros components

  application.initRos();

 

  // initializing descartes

  application.initDescartes();

 

  // moving to home position

  application.moveHome();

 

  // generating trajectory

  plan_and_run::DescartesTrajectory traj;

  application.generateTrajectory(traj);

 

 

  // planning robot path

  plan_and_run::DescartesTrajectory output_path;

  application.planPath(traj,output_path);

 

  // running robot path

  application.runPath(output_path);

 

  // exiting ros node

  spinner.stop();

 

  return 0;

}

简而言之,该程序将通过从application对象调用相应的函数来运行每个练习。 例如,为了初始化笛卡尔,程序调用application.initDescartes()。 因此,每个练习都包括编辑执行该练习的源文件,因此对于application.initDescartes(),您将编辑plan_and_run/src/tasks/init_descartes.src源文件。

 

DemoApplication

在头文件“plan_and_run/include/plan_and_run/demo_application.h”中,您将找到应用程序主类的定义以及一些支持结构。 需要注意的一些重要组件如下:

       ·程序变量:包含在应用程序的各个位置使用的固定值。

const std::string ROBOT_DESCRIPTION_PARAM = "robot_description";

const std::string EXECUTE_TRAJECTORY_ACTION = "execute_trajectory";

const std::string VISUALIZE_TRAJECTORY_TOPIC = "visualize_trajectory_curve";

const double SERVER_TIMEOUT = 5.0f; // seconds

const double ORIENTATION_INCREMENT = 0.5f;

const double EPSILON = 0.0001f;

const double AXIS_LINE_LENGHT = 0.01;

const double AXIS_LINE_WIDTH = 0.001;

const std::string PLANNER_ID = "RRTConnectkConfigDefault";

const std::string HOME_POSITION_NAME = "home";

·轨迹类型:方便表示一系列笛卡尔轨迹点的类型。

typedef std::vector<descartes_core::TrajectoryPtPtr> DescartesTrajectory;

       ·DemoConfiguration数据结构:提供变量,其值在运行时根据相应的ros参数进行初始化。

struct DemoConfiguration

{

  std::string group_name;                 /* Name of the manipulation group containing the relevant links in the robot */

  std::string tip_link;                   /* Usually the last link in the kinematic chain of the robot */

  std::string base_link;                  /* The name of the base link of the robot */

  std::string world_frame;                /* The name of the world link in the URDF file */

  std::vector<std::string> joint_names;   /* A list with the names of the mobile joints in the robot */

 

 

  /* Trajectory Generation Members:

   *  Used to control the attributes (points, shape, size, etc) of the robot trajectory.

   *  */

  double time_delay;              /* Time step between consecutive points in the robot path */

  double foci_distance;           /* Controls the size of the curve */

  double radius;                  /* Controls the radius of the sphere on which the curve is projected */

  int num_points;                 /* Number of points per curve */

  int num_lemniscates;            /* Number of curves*/

  std::vector<double> center;     /* Location of the center of all the lemniscate curves */

  std::vector<double> seed_pose;  /* Joint values close to the desired start of the robot path */

 

  /*

   * Visualization Members

   * Used to control the attributes of the visualization artifacts

   */

  double min_point_distance;      /* Minimum distance between consecutive trajectory points. */

};

 

·DemoApplication类:应用程序的主要组件,为我们程序的每个步骤提供功能。 它还包含将此应用程序转换为ROS节点的几种构造。

class DemoApplication

{

public:

  /*  Constructor

   *    Creates an instance of the application class

   */

  DemoApplication();

  virtual ~DemoApplication();

 

  /* Main Application Functions

   *  Functions that allow carrying out the various steps needed to run a

   *  plan and run application.  All these functions will be invoked from within

   *  the main routine.

   */

 

  void loadParameters();

  void initRos();

  void initDescartes();

  void moveHome();

  void generateTrajectory(DescartesTrajectory& traj);

  void planPath(DescartesTrajectory& input_traj,DescartesTrajectory& output_path);

  void runPath(const DescartesTrajectory& path);

 

protected:

 

  /* Support methods

   *  Called from within the main application functions in order to perform convenient tasks.

   */

 

  static bool createLemniscateCurve(double foci_distance, double sphere_radius,

                                    int num_points, int num_lemniscates,

                                    const Eigen::Vector3d& sphere_center,

                                    EigenSTL::vector_Affine3d& poses);

 

  void fromDescartesToMoveitTrajectory(const DescartesTrajectory& in_traj,

                                              trajectory_msgs::JointTrajectory& out_traj);

 

  void publishPosesMarkers(const EigenSTL::vector_Affine3d& poses);

 

 

protected:

 

  /* Application Data

   *  Holds the data used by the various functions in the application.

   */

  DemoConfiguration config_;

 

 

 

  /* Application ROS Constructs

   *  Components needed to successfully run a ros-node and perform other important

   *  ros-related tasks

   */

  ros::NodeHandle nh_;                        /* Object used for creating and managing ros application resources*/

  ros::Publisher marker_publisher_;           /* Publishes visualization message to Rviz */

  std::shared_ptr<actionlib::SimpleActionClient<moveit_msgs::ExecuteTrajectoryAction>>   moveit_run_path_client_ptr_; /* Sends a robot trajectory to moveit for execution */

 

 

 

  /* Application Descartes Constructs

   *  Components accessing the path planning capabilities in the Descartes library

   */

  descartes_core::RobotModelPtr robot_model_ptr_; /* Performs tasks specific to the Robot

                                                     such IK, FK and collision detection*/

  descartes_planner::SparsePlanner planner_;      /* Plans a smooth robot path given a trajectory of points */

 

};

 

应用启动文件

该文件将应用程序作为ROS节点启动,并将必要的参数加载到ROS参数服务器中。 通过打开“ plan_and_run/launch/demo_run.launch”文件来观察此操作:

<launch>

  <node name="plan_and_run_node" type="plan_and_run_node" pkg="plan_and_run" output="screen">

    <param name="group_name" value="manipulator"/>

    <param name="tip_link" value="tool"/>

    <param name="base_link" value="base_link"/>

    <param name="world_frame" value="world"/>

    <param name="trajectory/time_delay" value="0.1"/>

    <param name="trajectory/foci_distance" value="0.07"/>

    <param name="trajectory/radius" value="0.08"/>

    <param name="trajectory/num_points" value="200"/>

    <param name="trajectory/num_lemniscates" value="4"/>

    <rosparam param="trajectory/center">[0.36, 0.2, 0.1]</rosparam>

    <rosparam param="trajectory/seed_pose">[0.0, -1.03, 1.57 , -0.21, 0.0, 0.0]</rosparam>

    <param name="visualization/min_point_distance" value="0.02"/>

  </node>

</launch>

一些重要的参数解释如下:

·group_name:一个命名空间,指向机械臂的运动链中包含的机器人链接列表(从基础到工具末端的链接base to end-of-tooling links)。该列表在ur5_demo_moveit_config包中定义。

·tip_link:运动链中最后一个链接的名称,通常是工具链接。

·base_link:机械手基座链接的名称。

·world_frame:规划环境中定义的所有对象的绝对坐标参考系。

·“trajectory”命名空间下的参数用于生成馈入笛卡尔计划器的轨迹。

·trajectory / seed_pose:这点特别重要,因为在规划路径时,它用于指示机器人的首选开始和结束关节配置。如果未指定“ seed_pose”,则计划将需要更长的时间,因为必须考虑多个起点和终点关节配置,从而导致通过组合多个起点和终点姿势而产生多路径解决方案。

 

 

一般说明

接下来,将展示如何在练习中逐步进行演示。 此外,还将展示如何在仿真模式和真实机器人上运行系统。

 

主要目标

通常,您将逐步实施plan_and_run节点。 这意味着在每个练习中,您将添加完成完整的应用程序演示所需的各个部分。 因此,完成练习后,请在模拟模式下运行演示以验证您的结果。 只有完成所有练习后,才可以在真实的机器人上运行它。

 

完成练习

要完成练习,请打开src/plan_and_run/src/tasks/目录下的相应源文件。 例如,在练习1中,需打开load_parameters.cpp

花一点时间阅读标题评论,以获取有关如何完成此特定练习的特定说明。 例如,load_parameters.cpp文件包含以下说明和提示:

/* LOAD PARAMETERS

  Goal:

    - Load missing application parameters into the node from the ros parameter server.

    - Use a private NodeHandle in order to load parameters defined in the node's namespace.

  Hints:

    - Look at how the 'config_' structure is used to save the parameters.

    - A private NodeHandle can be created by passing the "~" string to its constructor.

*/

不要忘了注释掉这一行:

ROS_ERROR_STREAM("Task '"<<__FUNCTION__ <<"' is incomplete. Exiting"); exit(-1);

该行通常位于每个功能的开头。 省略此步骤将导致程序在到达此点时立即退出。

当遇到以/* Fill Code:开头的注释块时,这意味着后面的一行(或几行)代码是错误的,注释掉或完成代码。 阅读Fill Code后面的说明,并按照说明完成该任务。 指令注释块的示例如下:

  /*  Fill Code:

   * Goal:

   * - Create a private handle by passing the "~" string to its constructor

   * Hint:

   * - Replace the string in ph below with "~" to make it a private node.

   */

[ COMPLETE HERE ]条目意在由适当的code entry代替。 正确的代码条目(code entries)可以是程序变量,字符串或数字常量。 下面是一个示例:

ros::NodeHandle ph("[ COMPLETE HERE ]: ?? ");

在这种情况下,正确的替换将是字符串“〜”,因此此行应如下所示:

ros::NodeHandle ph("~");

 

 

在完成本练习中的每个任务时,可以运行演示(请参阅以下部分)以验证它是否已正确完成。

在仿真模式下运行演示

在终端中,运行设置程序启动文件,如下所示:

roslaunch plan_and_run demo_setup.launch

虚拟机器人准备就绪后,Rviz应该已启动并正在运行,并且UR5臂处于原始位置,可在终端中看到以下消息:

      .

      .

      .

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

* MoveGroup using:

*     - CartesianPathService

*     - ExecutePathService

*     - KinematicsService

*     - MoveAction

*     - PickPlaceAction

*     - MotionPlanService

*     - QueryPlannersService

*     - StateValidationService

*     - GetPlanningSceneService

*     - ExecutePathService

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

 

[ INFO] [1430359645.694537917]: MoveGroup context using planning plugin ompl_interface/OMPLPlanner

[ INFO] [1430359645.694700640]: MoveGroup context initialization complete

 

All is well! Everyone is happy! You can start planning now!

该设置启动文件只需要运行一次。

在另一个终端中,运行应用程序启动文件:

roslaunch plan_and_run demo_run.launch

               在Rviz窗口中查看,机械臂应开始移动。

 

在真实机器人上运行演示

注:确保可以ping通机器人,并且附近没有任何障碍物。

在终端中,运行安装程序启动文件,如下所示:

roslaunch plan_and_run demo_setup.launch sim:=false robot_ip:=000.000.0.00

 

注:在robot_ip参数中输入机器人的实际IP地址。 Rviz中的机器人模型应与真实机器人处于大致相同的位置。

在另一个终端中,运行应用程序启动文件:

roslaunch plan_and_run demo_run.launch

此时,真正的机器人应该开始运动。

 

 

这篇关于ROS Industrial教程(七)_笛卡尔规划和执行1的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/942369

相关文章

Spring Security 从入门到进阶系列教程

Spring Security 入门系列 《保护 Web 应用的安全》 《Spring-Security-入门(一):登录与退出》 《Spring-Security-入门(二):基于数据库验证》 《Spring-Security-入门(三):密码加密》 《Spring-Security-入门(四):自定义-Filter》 《Spring-Security-入门(五):在 Sprin

Makefile简明使用教程

文章目录 规则makefile文件的基本语法:加在命令前的特殊符号:.PHONY伪目标: Makefilev1 直观写法v2 加上中间过程v3 伪目标v4 变量 make 选项-f-n-C Make 是一种流行的构建工具,常用于将源代码转换成可执行文件或者其他形式的输出文件(如库文件、文档等)。Make 可以自动化地执行编译、链接等一系列操作。 规则 makefile文件

动态规划---打家劫舍

题目: 你是一个专业的小偷,计划偷窃沿街的房屋。每间房内都藏有一定的现金,影响你偷窃的唯一制约因素就是相邻的房屋装有相互连通的防盗系统,如果两间相邻的房屋在同一晚上被小偷闯入,系统会自动报警。 给定一个代表每个房屋存放金额的非负整数数组,计算你 不触动警报装置的情况下 ,一夜之内能够偷窃到的最高金额。 思路: 动态规划五部曲: 1.确定dp数组及含义 dp数组是一维数组,dp[i]代表

软考系统规划与管理师考试证书含金量高吗?

2024年软考系统规划与管理师考试报名时间节点: 报名时间:2024年上半年软考将于3月中旬陆续开始报名 考试时间:上半年5月25日到28日,下半年11月9日到12日 分数线:所有科目成绩均须达到45分以上(包括45分)方可通过考试 成绩查询:可在“中国计算机技术职业资格网”上查询软考成绩 出成绩时间:预计在11月左右 证书领取时间:一般在考试成绩公布后3~4个月,各地领取时间有所不同

poj 2976 分数规划二分贪心(部分对总体的贡献度) poj 3111

poj 2976: 题意: 在n场考试中,每场考试共有b题,答对的题目有a题。 允许去掉k场考试,求能达到的最高正确率是多少。 解析: 假设已知准确率为x,则每场考试对于准确率的贡献值为: a - b * x,将贡献值大的排序排在前面舍弃掉后k个。 然后二分x就行了。 代码: #include <iostream>#include <cstdio>#incl

SWAP作物生长模型安装教程、数据制备、敏感性分析、气候变化影响、R模型敏感性分析与贝叶斯优化、Fortran源代码分析、气候数据降尺度与变化影响分析

查看原文>>>全流程SWAP农业模型数据制备、敏感性分析及气候变化影响实践技术应用 SWAP模型是由荷兰瓦赫宁根大学开发的先进农作物模型,它综合考虑了土壤-水分-大气以及植被间的相互作用;是一种描述作物生长过程的一种机理性作物生长模型。它不但运用Richard方程,使其能够精确的模拟土壤中水分的运动,而且耦合了WOFOST作物模型使作物的生长描述更为科学。 本文让更多的科研人员和农业工作者

maven 编译构建可以执行的jar包

💝💝💝欢迎莅临我的博客,很高兴能够在这里和您见面!希望您在这里可以感受到一份轻松愉快的氛围,不仅可以获得有趣的内容和知识,也可以畅所欲言、分享您的想法和见解。 推荐:「stormsha的主页」👈,「stormsha的知识库」👈持续学习,不断总结,共同进步,为了踏实,做好当下事儿~ 专栏导航 Python系列: Python面试题合集,剑指大厂Git系列: Git操作技巧GO

代码随想录冲冲冲 Day39 动态规划Part7

198. 打家劫舍 dp数组的意义是在第i位的时候偷的最大钱数是多少 如果nums的size为0 总价值当然就是0 如果nums的size为1 总价值是nums[0] 遍历顺序就是从小到大遍历 之后是递推公式 对于dp[i]的最大价值来说有两种可能 1.偷第i个 那么最大价值就是dp[i-2]+nums[i] 2.不偷第i个 那么价值就是dp[i-1] 之后取这两个的最大值就是d

沁恒CH32在MounRiver Studio上环境配置以及使用详细教程

目录 1.  RISC-V简介 2.  CPU架构现状 3.  MounRiver Studio软件下载 4.  MounRiver Studio软件安装 5.  MounRiver Studio软件介绍 6.  创建工程 7.  编译代码 1.  RISC-V简介         RISC就是精简指令集计算机(Reduced Instruction SetCom

数学建模笔记—— 非线性规划

数学建模笔记—— 非线性规划 非线性规划1. 模型原理1.1 非线性规划的标准型1.2 非线性规划求解的Matlab函数 2. 典型例题3. matlab代码求解3.1 例1 一个简单示例3.2 例2 选址问题1. 第一问 线性规划2. 第二问 非线性规划 非线性规划 非线性规划是一种求解目标函数或约束条件中有一个或几个非线性函数的最优化问题的方法。运筹学的一个重要分支。2