ROS Workshop 2016: разбор задачи безопасного управления роботом

, ! ROS — ROS workshop. , . ( 4 ), ROS workshop . , . , .

image


. — . ( ASUS Xtion turtlebot_gazebo), :

  • Safe — ,
  • Warning — , (, )
  • Danger — ,


, ROS Indigo Ubuntu 14.04. ROS Indigo .

! roscpp, pcl_ros, pcl_conversions, sensor_msgs geometry_msgs:

cd ~/catkin_ws/src
catkin_create_pkg safety_control_cloud roscpp pcl_ros pcl_conversions sensor_msgs geometry_msgs
cd ~/catkin_ws

PCL package.xml:

<build_depend>libpcll-all-dev</build_depend>
...
<run_depend>libpcl-all</run_depend>


CMakeLists.txt:

find_package(PCL REQUIRED)
...
include_directories(${PCL_INCLUDE_DIRS})

safety_control.cpp src:

safety_control.cpp
#include "ros/ros.h"
#include "pcl_conversions/pcl_conversions.h"
#include <pcl/pcl_base.h>
#include <sstream>
#include <sensor_msgs/PointCloud2.h>
#include <pcl/filters/passthrough.h>
#include <pcl/common/common.h>
#include <geometry_msgs/Twist.h>

typedef pcl::PointXYZ PointType;
typedef pcl::PointCloud<PointType> PointCloud;
typedef PointCloud::Ptr PointCloudPtr;

ros::Publisher pcd_pub_, cmd_vel_pub_;

void pcd_cb(const sensor_msgs::PointCloud2ConstPtr& pcd) {
    ROS_INFO_STREAM_ONCE("Point cloud arrived");
    PointCloudPtr pcd_pcl = PointCloudPtr(new PointCloud), pcd_filtered = PointCloudPtr(new PointCloud);
    PointType pt_min, pt_max;
    pcl::fromROSMsg(*pcd, *pcd_pcl);

    pcl::PassThrough<PointType> pass;
    pass.setInputCloud(pcd_pcl);
    pass.setFilterFieldName("y");
    pass.setFilterLimits(-0.25,0.20);
    pass.filter(*pcd_filtered);

    pass.setInputCloud(pcd_filtered);
    pass.setFilterFieldName("x");
    pass.setFilterLimits(-0.3,0.3);
    pass.filter(*pcd_pcl);

    pcl::getMinMax3D(*pcd_pcl, pt_min, pt_max);

    geometry_msgs::Twist vel;
    if (pt_min.z > 1.0) {
        vel.linear.x = 0.2;
        ROS_INFO_STREAM("Safe zone");
    } else if (pt_min.z > 0.5) {
        vel.linear.x = 0.1;
        ROS_INFO_STREAM("Warning zone");
    } else {
        vel.linear.x = 0.0;
        ROS_INFO_STREAM("Danger zone");
    }

    cmd_vel_pub_.publish(vel);

    sensor_msgs::PointCloud2 pcd_out;
    pcl::toROSMsg(*pcd_pcl, pcd_out);

    pcd_pub_.publish(pcd_out);
}

int main(int argc, char **argv)
{
  /**
   * The ros::init() function needs to see argc and argv so that it can perform
   * any ROS arguments and name remapping that were provided at the command line.
   * For programmatic remappings you can use a different version of init() which takes
   * remappings directly, but for most command-line programs, passing argc and argv is
   * the easiest way to do it.  The third argument to init() is the name of the node.
   *
   * You must call one of the versions of ros::init() before using any other
   * part of the ROS system.
   */
  ros::init(argc, argv, "safety_control_cloud");

  /**
   * NodeHandle is the main access point to communications with the ROS system.
   * The first NodeHandle constructed will fully initialize this node, and the last
   * NodeHandle destructed will close down the node.
   */
  ros::NodeHandle n;

  ros::Subscriber pcd_sub = n.subscribe("/camera/depth/points", 1, pcd_cb);

  pcd_pub_ = n.advertise<sensor_msgs::PointCloud2>("/output", 1);
  cmd_vel_pub_ = n.advertise<geometry_msgs::Twist>("/cmd_vel_mux/input/teleop", 1);

  ros::spin();

  return 0;
}


safety_control.cpp CMakeLists.txt:

add_executable(safety_control_node src/safety_control.cpp)
target_link_libraries(safety_control_node ${catkin_LIBRARIES} ${PCL_LIBRARIES})

/camera/depth/points, , geometry_msgs/Twister /cmd_vel_mux/input/teleop.

. :


    pcl::PassThrough<PointType> pass;
    pass.setInputCloud(pcd_pcl);
    pass.setFilterFieldName("y");
    pass.setFilterLimits(-0.25,0.20);
    pass.filter(*pcd_filtered);

PassThrough 25 20 ( y).

:


pass.setInputCloud(pcd_filtered);
pass.setFilterFieldName("x");
pass.setFilterLimits(-0.3,0.3);
pass.filter(*pcd_pcl);

0.3 (30 ) ( z). z ( ) — :


pcl::getMinMax3D(*pcd_pcl, pt_min, pt_max);

/mobile_base/commands/velocity. :

cd ~/catkin_ws
catkin_make
source devel/setup.bash

Turtle Bot Gazebo


TurtleBot Gazebo. turtlebot_gazebo apt-get:

sudo apt-get install ros-indigo-turtlebot*

. , ROS . :

roslaunch turtlebot_gazebo turtlebot_world.launch

Gazebo :

image

. , , . . , . :

image

. -

image

, . :

image

rviz:

rosrun rviz rviz

RobotModel, . PointCloud2 /camera/depth/points. :

image

PointCloud2 Color Transformer RGB8. :

image

safety_control_node:

rosrun safety_control_cloud safety_control_node

:

[ INFO] [1479229421.537897080, 2653.960000000]: Point cloud arrived
[ INFO] [1479229421.572338588, 2654.000000000]: Warning zone
[ INFO] [1479229421.641967924, 2654.070000000]: Warning zone

:

rostopic list

:

/cmd_vel_mux/input/teleop
...
/mobile_base/commands/velocity

/mobile_base/commands/velocity:

rostopic echo /mobile_base/commands/velocity

:

linear: 
  x: 0.1
  y: 0.0
  z: 0.0
angular: 
  x: 0.0
  y: 0.0
  z: 0.0
---

Danger. Gazebo :

image

safety_control_node :

[ INFO] [1479229426.604300460, 2658.980000000]: Danger zone
[ INFO] [1479229426.717093096, 2659.100000000]: Danger zone

/mobile_base/commands/velocity :

linear: 
  x: 0.0
  y: 0.0
  z: 0.0
angular: 
  x: 0.0
  y: 0.0
  z: 0.0
---

PointCloud2 /output rviz. Color Transformer FlatColor Color. safety_control_node:

image

, . :

image

, :

image

rviz :

image

:

[ INFO] [1479230429.902116395, 3658.000000000]: Safe zone
[ INFO] [1479230429.992468971, 3658.090000000]: Safe zone

:

---                                                                                                                                                                                 
linear: 
  x: 0.2
  y: 0.0
  z: 0.0
angular: 
  x: 0.0
  y: 0.0
  z: 0.0
---

: .

TurtleBot , (ASUS Xtion ROS Indigo). , Microsoft Kinect.

. — — TurtleBot Gazebo.

!

Source: https://habr.com/ru/post/fr399151/


All Articles