主要内容

使用ROS拾取和放置工作流程

此示例显示了如何设置端到端的选择,并将工作流放置为像Kinova®Gen3这样的机器人操纵器,并在凉亭物理模拟器中模拟机器人。

概述

This example identifies and recycles objects into two bins using a KINOVA Gen3 manipulator. The example uses tools from five toolboxes:

  • 机器人系统工具箱™用于模拟并模拟操纵器。

  • StateFlow®.用于将示例中的高级任务安排到任务到任务。

  • ROS工具箱™is usedfor connecting MATLAB to Gazebo.

  • 计算机Vision Toolbox™and深度学习工具箱™用于使用凉亭的模拟相机进行对象检测。

此示例在以下相关示例中构建关键概念:

Robot Simulation and Control in Gazebo

Start a ROS-based simulator for a KINOVA Gen3 robot and configure the MATLAB® connection with the robot simulator.

This example uses a virtual machine (VM) available for download. If you have never used it before, seeGet Started with Gazebo and a Simulated TurtleBot(ROS工具箱).

  • 启动Ubuntu®虚拟机桌面。

  • 在Ubuntu桌面中,单击凉亭回收世界icon to start the Gazebo world built for this example.

  • Specify the IP address and port number of the ROS master in Gazebo so that MATLAB® can communicate with the robot simulator. For this example, the ROS master in Gazebo uses the IP address of192.168.203.131显示在桌面上。调整玫瑰花基于VM的变量。

  • Start the ROS 1 network using罗斯尼特.

玫瑰花='192.168.203.131';启用ROS的机器的%IP地址罗斯尼特(rosIP,11311);%初始化ROS连接
192年ROS_IP环境变量的值。168.31.1, will be used to set the advertised address for the ROS node. Initializing global node /matlab_global_node_36570 with NodeURI http://192.168.31.1:51073/

After initializing the Gazebo world by click the icon, the VM loads a KINOVA Gen3 Robot arm on a table with one recycling bin on each side. To simulate and control the robot arm in Gazebo, the VM contains theros_kortex.ROS package, which are provided by KINOVA.

The packages useros_control控制关节到所需的关节位置。有关使用VM的其他详细信息,请参阅Get Started with Gazebo and a Simulated TurtleBot(ROS工具箱)

Stateflow Chart

此示例使用StateFlow图表在示例中计划任务。打开图表以检查内容并在图表执行期间遵循状态转换。

editexampleHelperFlowChartPickPlaceROSGazebo.sfx

The chart dictates how the manipulator interacts with the objects, or parts. It consists of basic initialization steps, followed by two main sections:

  • 识别零件并确定放置它们的位置

  • 执行挑选工作流程

有关拾取步骤的高级描述,请参阅Pick-and-Place Workflow Using Stateflow for MATLAB.

Opening and closing the gripper

激活夹具的命令,examplecommandactivategripperrosgazebo.,发送一个动作请求来打开和关闭在凉亭中实现的夹具。要发送请求打开夹具,请使用以下代码。Note:显示的示例代码只是说明了命令所做的。别跑。

[gripAct,gripGoal] = rosactionclient('/my_gen3/custom_gripper_controller/gripper_cmd');gripperCommand = rosmessage('control_msgs/GripperCommand');gripperCommand.Position = 0.0; gripGoal.Command = gripperCommand; sendGoal(gripAct,gripGoal);

Moving the Manipulator to a Specified Pose

ThecommandMoveToTaskConfigcommand function is used to move the manipulator to specified poses.

Planning

路径规划从初始到所需任务配置生成简单的任务空间轨迹trapveltraj.andTransfortraj.. For more details on planning and executing trajectories, seePlan and Execute Task- and Joint-Space Trajectories Using KINOVA Gen3 Manipulator.

Joint Trajectory Controller in ROS

在为机器人产生关节轨迹之后,commandMoveToTaskConfig以所需的采样速率对轨迹进行采样,将其包装成关节轨迹ROS消息,并将动作请求发送到在Kinova ROS包中实现的联合轨迹控制器。

检测和分类场景中的对象

功能commandDetectPartsandcommandclassifyparts.使用从机器人的模拟末端执行器相机源,并应用预训练的深学习模型以检测可回收部件。该模型将相机帧作为输入,并输出对象(像素位置)的2D位置,并且它需要的回收类型(蓝色或绿色垃圾箱)。图像帧上的2D位置映射到机器人基础帧。

Deep-Learning Model Training: Acquiring and Labeling Gazebo Images

The detection model was trained using a set of images acquired in the simulated environment within the Gazebo world with the two classes of objects (bottle, can) placed on different locations of the table. The images are acquired from the simulated camera on-board the robot, which is moved along the horizontal and vertical planes to get images of the objects from many different camera perspectives.

The images are then labeled using theImage Labeler(Computer Vision Toolbox)应用程序,为Yolo V2检测模型创建培训数据集。trainyolov2objectdetector(Computer Vision Toolbox)训练模型。看如何在Matlab中训练Yolo V2网络,看火车yolo v2网络用于车辆检测(Computer Vision Toolbox).

The trained model is deployed for online inference on the single image acquired by the on-board camera when the robot is in the home position. The探测(Computer Vision Toolbox)函数返回检测到的对象的边界框的图像位置,以及它们的类,然后用于找到对象顶部的中心的位置。使用简单的摄像机投影方法,假设已知对象的高度,将对象位置投影到世界中,最后用作挑选对象的参考位置。与边界盒装关联的类决定要放置对象的垃圾箱。

Start the Pick-and-Place Task

该模拟使用Kinova Gen3机械手Robotiqgripper attached. Load the robot model from a.matfile as arigidBodyTreeobject.

load('examplehelperkinovagen3gripperrosgazebo.mat');

初始化选择和放置协调员

设置初始机器人配置。通过提供机器人模型,初始配置和结束效应名称,创建处理机器人控制的协调器。

initialRobotJConfig = [3.5797 -0.6562 -1.2507 -0.7008 0.7303 -2.0500 -1.9053]; endEffectorFrame ="gripper";

Initialize the coordinator by giving the robot model, initial configuration, and end-effector name.

coordinator = exampleHelperCoordinatorPickPlaceROSGazebo(robot,initialRobotJConfig, endEffectorFrame);

Specify the home configuration and two poses for placing objects.

协调员。HomeRobotTaskConfig = getTransform(robot, initialRobotJConfig, endEffectorFrame); coordinator.PlacingPose{1} = trvec2tform([[0.2 0.55 0.26]])*axang2tform([0 0 1 pi/2])*axang2tform([0 1 0 pi]); coordinator.PlacingPose{2} = trvec2tform([[0.2 -0.55 0.26]])*axang2tform([0 0 1 pi/2])*axang2tform([0 1 0 pi]);

Run and Visualize the Simulation

Connect the coordinator to the Stateflow Chart. Once started, the Stateflow chart is responsible for continuously going through the states of detecting objects, picking them up and placing them in the correct staging area.

协调员。流程图= exampleHelperFlowChartPickPlaceROSGazebo('coordinator', coordinator);

Use a dialog to start the pick-and-place task execution. Click是的in the dialog to begin the simulation.

answer = questdlg(“你想现在开始挑选挑选工作吗?',...'开始工作','Yes','不','不');switchanswer案子'Yes'%触发事件要启动SoundFlow图表中的选择和放置协调员。FlowChart.startPickPlace;案子'不'coordinator.flowchart.endpickplace;删除(coordinator.flowchart)删除(协调器);结尾

结束挑选任务

The Stateflow chart will finish executing automatically after 3 failed attempts to detect new objects. To end the pick-and-place task prematurely, uncomment and execute the following lines of code or press Ctrl+C in the command window.

%coordinator.flowchart.endpickplace;% delete(coordinator.FlowChart);%删除(协调员);

观察模拟状态

During execution, the active states at each point in time are highlighted in blue in the Stateflow chart. This helps keeping track of what the robot does and when. You can click through the subsystems to see the details of the state in action.

Visualize the Pick-and-Place Action in Gazebo

The Gazebo world shows the robot in the working area as it moves parts to the recycling bins. The robot continues working until all parts have been placed. When the detection step doesn't find any more parts four times, the Stateflow chart exits.

如果strcmp(answer,'Yes')尽管coordinator.numdetectionRuns <4%等待未检测到的部分。结尾结尾

完成示例后关闭ROS网络。

rosshutdown
Shutting down global node /matlab_global_node_36570 with NodeURI http://192.168.31.1:51073/

版权所有2020 Mathworks,Inc。