Rviz Draw Bounding Box Python

Markers: Points and Lines (C++)

Description: Teaches how to utilize the visualization_msgs/Mark message to send points and lines to rviz.

Tutorial Level: BEGINNER

Next Tutorial: Interactive Markers: Getting Started

Contents

  1. Intro
  2. Using Points, Line Strips, and Line Lists
    1. The Lawmaking
    2. The Code Explained
    3. Viewing the Markers
  3. Next Steps

Intro

In the Markers: Bones Shapes you learned how to send elementary shapes to rviz using visualization markers. You can ship more than than only simple shapes though, and this tutorial will introduce you to the POINTS, LINE_STRIP and LINE_LIST marking types. For a full list of types, run into the Marker Display page.

Using Points, Line Strips, and Line Lists

The POINTS, LINE_STRIP and LINE_LIST markers all utilise the points member of the visualization_msgs/Mark bulletin. The POINTS type places a point at each betoken added. The LINE_STRIP type uses each point equally a vertex in a continued set of lines, where betoken 0 is connected to point 1, 1 to 2, 2 to 3, etc. The LINE_LIST blazon creates unconnected lines out of each pair of points, i.due east. point 0 to ane, 2 to 3, etc.

Anyway, allow'due south get to the code:

The Code

https://code.ros.org/svn/ros-pkg/stacks/visualization_tutorials/body/visualization_marker_tutorials/src/points_and_lines.cpp

                                          xxx                                          #              include <ros              /              ros.h>                                                                    31                                                        #              include <visualization_msgs              /              Marker.h>                                                                    32                                                                                                              33                                          #              include <cmath>                                                                    34                                                                                                35                                          int              chief(              int              argc,              char**              argv              )                                          36                            {                                          37                                          ros::init(argc,              argv,              "              points_and_lines              ");                                          38                                          ros::NodeHandle              n;                                          39                                          ros::Publisher              marker_pub              =              n.advertise<visualization_msgs::Marker>("              visualization_marker              ",              10);                                          twoscore                                                                                  41                                          ros::Rate              r(xxx);                                          42                                                                                  43                                          float              f              =              0.0;                                          44                                          while              (ros::ok())                                          45                                          {                                          46                                                                                  47                                          visualization_msgs::Marker              points,              line_strip,              line_list;                                          48                                          points.header.frame_id              =              line_strip.header.frame_id              =              line_list.header.frame_id              =              "              /my_frame              ";                                          49                                          points.header.stamp              =              line_strip.header.stamp              =              line_list.header.postage stamp              =              ros::Time::now();                                          50                                          points.ns              =              line_strip.ns              =              line_list.ns              =              "              points_and_lines              ";                                          51                                          points.activity              =              line_strip.action              =              line_list.activity              =              visualization_msgs::Marker::Add together;                                          52                                          points.pose.orientation.w              =              line_strip.pose.orientation.w              =              line_list.pose.orientation.west              =              1.0;                                          53                                                                                  54                                                                                  55                                                                                  56                                          points.id              =              0;                                          57                                          line_strip.id              =              1;                                          58                                          line_list.id              =              ii;                                          59                                                                                  lx                                                                                  61                                                                                  62                                          points.type              =              visualization_msgs::Marker::POINTS;                                          63                                          line_strip.type              =              visualization_msgs::Marker::LINE_STRIP;                                          64                                          line_list.type              =              visualization_msgs::Marker::LINE_LIST;                                          65                                                                                  66                                                                                  67                                                                                  68                                                                                  69                                          points.scale.x              =              0.2;                                          lxx                                          points.calibration.y              =              0.2;                                          71                                                                                  72                                                                                  73                                          line_strip.calibration.x              =              0.1;                                          74                                          line_list.scale.ten              =              0.1;                                          75                                                                                  76                                                                                  77                                                                                  78                                                                                  79                                          points.colour.g              =              one.0f;                                          80                                          points.color.a              =              1.0;                                          81                                                                                  82                                                                                  83                                          line_strip.color.b              =              1.0;                                          84                                          line_strip.color.a              =              1.0;                                          85                                                                                  86                                                                                  87                                          line_list.color.r              =              i.0;                                          88                                          line_list.color.a              =              i.0;                                          89                                                                                  90                                                                                  91                                                                                  92                                                                                  93                                          for              (uint32_t              i              =              0;              i              <              100; ++i)                                          94                                          {                                          95                                          float              y              =              v              *              sin(f              +              i              /              100.0f              *              2              *              M_PI);                                          96                                          float              z              =              5              *              cos(f              +              i              /              100.0f              *              2              *              M_PI);                                          97                                                                                  98                                          geometry_msgs::Bespeak              p;                                          99                                          p.x              = (int32_t)i              -              l;                                          100                                          p.y              =              y;                                          101                                          p.z              =              z;                                          102                                                                                  103                                          points.points.push_back(p);                                          104                                          line_strip.points.push_back(p);                                          105                                                                                  106                                                                                  107                                          line_list.points.push_back(p);                                          108                                          p.z              +=              ane.0;                                          109                                          line_list.points.push_back(p);                                          110                                          }                                          111                                                                                  112                                                                                  113                                          marker_pub.publish(points);                                          114                                          marker_pub.publish(line_strip);                                          115                                          marker_pub.publish(line_list);                                          116                                                                                  117                                          r.sleep();                                          118                                                                                  119                                          f              +=              0.04;                                          120                                          }                                          121                            }                                          122                                    

The Code Explained

Now let'southward break downwards the code, skipping things that were explained in the previous tutorial. The overall effect created is a rotating helix with lines sticking upwards from each vertex.

                                          47                                          visualization_msgs::Marker              points,              line_strip,              line_list;                                          48                                          points.header.frame_id              =              line_strip.header.frame_id              =              line_list.header.frame_id              =              "              /my_frame              ";                                          49                                          points.header.postage stamp              =              line_strip.header.postage stamp              =              line_list.header.stamp              =              ros::Fourth dimension::at present();                                          50                                          points.ns              =              line_strip.ns              =              line_list.ns              =              "              points_and_lines              ";                                          51                                          points.activity              =              line_strip.activeness              =              line_list.action              =              visualization_msgs::Marker::Add together;                                          52                                          points.pose.orientation.west              =              line_strip.pose.orientation.westward              =              line_list.pose.orientation.westward              =              1.0;                                          53                                    

Here we create 3 visualization_msgs/Marker messages and initialize all of their shared data. Nosotros accept advantage of the fact that message members default to 0 and only set the w member of the pose.

                                          56                                          points.id              =              0;                                          57                                          line_strip.id              =              1;                                          58                                          line_list.id              =              2;                                          59                                    

Nosotros assign three different ids to the three markers. The use of the points_and_lines namespace ensures they won't collide with other broadcasters.

                                          62                                          points.type              =              visualization_msgs::Marker::POINTS;                                          63                                          line_strip.type              =              visualization_msgs::Marker::LINE_STRIP;                                          64                                          line_list.type              =              visualization_msgs::Marker::LINE_LIST;                                          65                                    

Here we set the marker types to POINTS, LINE_STRIP and LINE_LIST.

                                          68                                                                                  69                                          points.scale.x              =              0.two;                                          70                                          points.scale.y              =              0.ii;                                          71                                                                                  72                                                                                  73                                          line_strip.calibration.x              =              0.ane;                                          74                                          line_list.scale.x              =              0.ane;                                          75                                    

The calibration member ways different things for these marker types. The POINTS marker uses the ten and y members for width and height respectively, while the LINE_STRIP and LINE_LIST markers only use the x component, which defines the line width. Scale values are in meters.

                                          78                                                                                  79                                          points.colour.g              =              1.0f;                                          eighty                                          points.colour.a              =              one.0;                                          81                                                                                  82                                                                                  83                                          line_strip.color.b              =              1.0;                                          84                                          line_strip.colour.a              =              one.0;                                          85                                                                                  86                                                                                  87                                          line_list.color.r              =              1.0;                                          88                                          line_list.colour.a              =              ane.0;                                          89                                    

Here nosotros fix the points to green, the line strip to bluish, and the line list to red.

                                          92                                                                                  93                                          for              (uint32_t              i              =              0;              i              <              100; ++i)                                          94                                          {                                          95                                          float              y              =              5              *              sin(f              +              i              /              100.0f              *              ii              *              M_PI);                                          96                                          float              z              =              5              *              cos(f              +              i              /              100.0f              *              2              *              M_PI);                                          97                                                                                  98                                          geometry_msgs::Signal              p;                                          99                                          p.10              = (int32_t)i              -              50;                                          100                                          p.y              =              y;                                          101                                          p.z              =              z;                                          102                                                                                  103                                          points.points.push_back(p);                                          104                                          line_strip.points.push_back(p);                                          105                                                                                  106                                                                                  107                                          line_list.points.push_back(p);                                          108                                          p.z              +=              1.0;                                          109                                          line_list.points.push_back(p);                                          110                                          }                                          111                                    

We utilize sine and cosine to generate a helix. The POINTS and LINE_STRIP markers both require only a point for each vertex, while the LINE_LIST marker requires ii.

Viewing the Markers

Set rviz the aforementioned mode you did in the final tutorial, which is as follows:

Edit the CMakeLists.txt file in your using_markers bundle, and add to the bottom:

          rosbuild_add_executable(points_and_lines src/points_and_lines.cpp)

And then,

          rosmake using_markers points_and_lines          rosrun using_markers points_and_lines          rosrun rviz rviz

You should see a rotating helix that looks something similar this:

Basic Shapes

Next Steps

The Marker Display page has a list of all the markers and options supported by rviz. Try out some of the other markers!

dunlapsagenur.blogspot.com

Source: http://library.isr.ist.utl.pt/docs/roswiki/rviz(2f)Tutorials(2f)Markers(3a20)Points(20)and(20)Lines.html

0 Response to "Rviz Draw Bounding Box Python"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel