This page introduces the usage of display_virtual_lines, including how to display virtual walls in rviz.
...
Contents
...
Environment Setup
software platform
- Ubuntu 20.04 X86
- ROS Noetic
hardware platform
Choose any one below:
- Slamware Kit (User Robot System based on Slamware Solution)
- robot base systems like Apollo/Ares/Athena
...
Sample Code Download
ROS-Sample Download Link
...
Compile and Run
- Download the Slamware ROS SDK along with ROS examples.
- Place the 'src' folder from the ROS SDK into an empty working directory, such as 'catkin_ws'. Also, put the 'slamware_ros_sample' folder from the ROS examples into the 'src' folder.
Code Block |
---|
|
mkdir -p catkin_ws/src
cd catkin_ws/src |
- Initialize the workspace using the Catkin tool.
Code Block |
---|
|
catkin_init_workspace |
- Compile.
Code Block |
---|
|
cd ..
catkin_make |
- Set up workspace environment.
Code Block |
---|
|
source devel/setup.bash |
- Launch the slamware_ros_sdk_server_node node. Select the corresponding IP according to the mode.
Code Block |
---|
|
roslaunch slamware_ros_sdk slamware_ros_sdk_server_node.launch ip_address:=10.6.128.141 // Station mode
// If in AP mode, the IP address is 192.168.11.1 |
- Open another terminal, repeat step 5, and start the view_slamware_ros_sdk_server_node node.
Code Block |
---|
|
roslaunch slamware_ros_sdk view_slamware_ros_sdk_server_node.launch |
- Open another terminal, repeat step 5, and start the display_virtual_lines_node node.
Code Block |
---|
|
roslaunch slamware_ros_sample display_virtual_lines.launch |
- Configure and add the display of Marker information in Rviz:
Click 'Add' in the bottom-left corner of Rviz, then in the pop-up window, select 'Marker' and click 'OK'. Upon success, as shown in the image below, a Marker is added to Displays, and the virtual walls are also displayed in the interface.
Image Added
Image Added
...
Code Description
Code Block |
---|
language | cpp |
---|
firstline | 1 |
---|
title | Initialize the node, define publisher and subscriber objects |
---|
|
ros::init(argc, argv, "display_virtual_lines_node");
ros::NodeHandle n;
ros::Publisher pub = n.advertise<visualization_msgs::Marker>("visualization_marker", 10);
ros::Subscriber sub = n.subscribe<slamware_ros_sdk::Line2DFlt32Array>("/slamware_ros_sdk_server_node/virtual_walls", 30, virtualWallCallback); |
Code Block |
---|
language | cpp |
---|
title | Declare a global variable of type Marker named "lines" to store the published virtual walls |
---|
|
visualization_msgs::Marker lines; |
Code Block |
---|
language | cpp |
---|
title | Upon receiving the virtual wall message sent by the slamware_ros_sdk_server_node, save it into the "lines" variable |
---|
|
void virtualWallCallback(const slamware_ros_sdk::Line2DFlt32Array::ConstPtr & msg)
{
lines.points.clear();
size_t cnt = msg->lines.size();
for (size_t i = 0; i < msg->lines.size(); ++i)
{
geometry_msgs::Point p1;
p1.x = msg->lines[i].start.x;
p1.y = msg->lines[i].start.y;
p1.z = 0.2;
geometry_msgs::Point p2;
p2.x = msg->lines[i].end.x;
p2.y = msg->lines[i].end.y;
p2.z = 0.2;
lines.points.push_back(p1);
lines.points.push_back(p2);
}
} |
Code Block |
---|
language | cpp |
---|
title | Configure "lines", such as type, size, color, etc |
---|
|
lines.id = 1;
lines.header.frame_id = "slamware_map";
lines.type = visualization_msgs::Marker::LINE_LIST;
lines.ns = "lines";
lines.action = visualization_msgs::Marker::ADD;
lines.pose.orientation.w = 1.0;
lines.scale.x = 0.1;
lines.color.r = 1.0;
lines.color.a = 1.0; |
Code Block |
---|
language | cpp |
---|
title | Publish "lines" |
---|
|
ros::Rate r(30);
while(running)
{
lines.header.stamp = ros::Time::now();
pub.publish(lines);
r.sleep();
} |