Skip to content

Commit 553c108

Browse files
naiveHoboruffsl
authored andcommitted
Add particle cloud display plugin for RViz (ros-navigation#1688)
* Add particle cloud display rviz plugin Signed-off-by: Sarthak Mittal <[email protected]> * General refactoring * Fix header guards * Update bringup rviz files and default values
1 parent 28cb51d commit 553c108

File tree

8 files changed

+834
-18
lines changed

8 files changed

+834
-18
lines changed

nav2_bringup/bringup/rviz/nav2_default_view.rviz

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -214,24 +214,19 @@ Visualization Manager:
214214
Use Timestamp: false
215215
Value: true
216216
- Alpha: 1
217-
Arrow Length: 0.019999999552965164
218-
Axes Length: 0.30000001192092896
219-
Axes Radius: 0.009999999776482582
220-
Class: rviz_default_plugins/PoseArray
217+
Class: nav2_rviz_plugins/ParticleCloud
221218
Color: 0; 180; 0
222219
Enabled: true
223-
Head Length: 0.07000000029802322
224-
Head Radius: 0.029999999329447746
220+
Max Arrow Length: 0.3
221+
Min Arrow Length: 0.02
225222
Name: Amcl Particle Swarm
226-
Shaft Length: 0.23000000417232513
227-
Shaft Radius: 0.009999999776482582
228223
Shape: Arrow (Flat)
229224
Topic:
230225
Depth: 5
231226
Durability Policy: Volatile
232227
History Policy: Keep Last
233228
Reliability Policy: Best Effort
234-
Value: /particlecloud
229+
Value: /particle_cloud
235230
Value: true
236231
- Class: rviz_common/Group
237232
Displays:

nav2_bringup/bringup/rviz/nav2_namespaced_view.rviz

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -164,24 +164,19 @@ Visualization Manager:
164164
Use Timestamp: false
165165
Value: true
166166
- Alpha: 1
167-
Arrow Length: 0.019999999552965164
168-
Axes Length: 0.30000001192092896
169-
Axes Radius: 0.009999999776482582
170-
Class: rviz_default_plugins/PoseArray
167+
Class: nav2_rviz_plugins/ParticleCloud
171168
Color: 0; 180; 0
172169
Enabled: true
173-
Head Length: 0.07000000029802322
174-
Head Radius: 0.029999999329447746
170+
Max Arrow Length: 0.3
171+
Min Arrow Length: 0.02
175172
Name: Amcl Particle Swarm
176-
Shaft Length: 0.23000000417232513
177-
Shaft Radius: 0.009999999776482582
178173
Shape: Arrow (Flat)
179174
Topic:
180175
Depth: 5
181176
Durability Policy: Volatile
182177
History Policy: Keep Last
183178
Reliability Policy: Best Effort
184-
Value: <robot_namespace>/particlecloud
179+
Value: <robot_namespace>/particle_cloud
185180
Value: true
186181
- Class: rviz_common/Group
187182
Displays:

nav2_rviz_plugins/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ set(nav2_rviz_plugins_headers_to_moc
3737
include/nav2_rviz_plugins/goal_common
3838
include/nav2_rviz_plugins/goal_tool.hpp
3939
include/nav2_rviz_plugins/nav2_panel.hpp
40+
include/nav2_rviz_plugins/particle_cloud_display/flat_weighted_arrows_array.hpp
41+
include/nav2_rviz_plugins/particle_cloud_display/particle_cloud_display.hpp
4042
)
4143

4244
include_directories(
@@ -48,6 +50,8 @@ set(library_name ${PROJECT_NAME})
4850
add_library(${library_name} SHARED
4951
src/goal_tool.cpp
5052
src/nav2_panel.cpp
53+
src/particle_cloud_display/flat_weighted_arrows_array.cpp
54+
src/particle_cloud_display/particle_cloud_display.cpp
5155
${nav2_rviz_plugins_headers_to_moc}
5256
)
5357

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Copyright (c) 2012, Willow Garage, Inc.
3+
* Copyright (c) 2018, Bosch Software Innovations GmbH.
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* * Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
* * Neither the name of the Willow Garage, Inc. nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
// Copyright (c) 2019 Intel Corporation
32+
// Copyright (c) 2020 Sarthak Mittal
33+
//
34+
// Licensed under the Apache License, Version 2.0 (the "License");
35+
// you may not use this file except in compliance with the License.
36+
// You may obtain a copy of the License at
37+
//
38+
// http://www.apache.org/licenses/LICENSE-2.0
39+
//
40+
// Unless required by applicable law or agreed to in writing, software
41+
// distributed under the License is distributed on an "AS IS" BASIS,
42+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43+
// See the License for the specific language governing permissions and
44+
// limitations under the License.
45+
46+
#ifndef NAV2_RVIZ_PLUGINS__PARTICLE_CLOUD_DISPLAY__FLAT_WEIGHTED_ARROWS_ARRAY_HPP_
47+
#define NAV2_RVIZ_PLUGINS__PARTICLE_CLOUD_DISPLAY__FLAT_WEIGHTED_ARROWS_ARRAY_HPP_
48+
49+
#include <vector>
50+
51+
#include <OgreManualObject.h>
52+
#include <OgreMaterialManager.h>
53+
#include <OgreSceneNode.h>
54+
#include <OgreVector3.h>
55+
#include <OgreQuaternion.h>
56+
57+
#include "nav2_rviz_plugins/particle_cloud_display/particle_cloud_display.hpp"
58+
59+
namespace nav2_rviz_plugins
60+
{
61+
62+
struct OgrePoseWithWeight;
63+
64+
class FlatWeightedArrowsArray
65+
{
66+
public:
67+
explicit FlatWeightedArrowsArray(Ogre::SceneManager * scene_manager_);
68+
~FlatWeightedArrowsArray();
69+
70+
void createAndAttachManualObject(Ogre::SceneNode * scene_node);
71+
void updateManualObject(
72+
Ogre::ColourValue color,
73+
float alpha,
74+
float min_length,
75+
float max_length,
76+
const std::vector<nav2_rviz_plugins::OgrePoseWithWeight> & poses);
77+
void clear();
78+
79+
private:
80+
void setManualObjectMaterial();
81+
void setManualObjectVertices(
82+
const Ogre::ColourValue & color,
83+
float min_length,
84+
float max_length,
85+
const std::vector<nav2_rviz_plugins::OgrePoseWithWeight> & poses);
86+
87+
Ogre::SceneManager * scene_manager_;
88+
Ogre::ManualObject * manual_object_;
89+
Ogre::MaterialPtr material_;
90+
};
91+
92+
} // namespace nav2_rviz_plugins
93+
94+
#endif // NAV2_RVIZ_PLUGINS__PARTICLE_CLOUD_DISPLAY__FLAT_WEIGHTED_ARROWS_ARRAY_HPP_
Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
/*
2+
* Copyright (c) 2012, Willow Garage, Inc.
3+
* Copyright (c) 2018, Bosch Software Innovations GmbH.
4+
* All rights reserved.
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
* * Redistributions in binary form must reproduce the above copyright
12+
* notice, this list of conditions and the following disclaimer in the
13+
* documentation and/or other materials provided with the distribution.
14+
* * Neither the name of the Willow Garage, Inc. nor the names of its
15+
* contributors may be used to endorse or promote products derived from
16+
* this software without specific prior written permission.
17+
*
18+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
22+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28+
* POSSIBILITY OF SUCH DAMAGE.
29+
*/
30+
31+
// Copyright (c) 2019 Intel Corporation
32+
// Copyright (c) 2020 Sarthak Mittal
33+
//
34+
// Licensed under the Apache License, Version 2.0 (the "License");
35+
// you may not use this file except in compliance with the License.
36+
// You may obtain a copy of the License at
37+
//
38+
// http://www.apache.org/licenses/LICENSE-2.0
39+
//
40+
// Unless required by applicable law or agreed to in writing, software
41+
// distributed under the License is distributed on an "AS IS" BASIS,
42+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
43+
// See the License for the specific language governing permissions and
44+
// limitations under the License.
45+
46+
#ifndef NAV2_RVIZ_PLUGINS__PARTICLE_CLOUD_DISPLAY__PARTICLE_CLOUD_DISPLAY_HPP_
47+
#define NAV2_RVIZ_PLUGINS__PARTICLE_CLOUD_DISPLAY__PARTICLE_CLOUD_DISPLAY_HPP_
48+
49+
#include <memory>
50+
#include <vector>
51+
52+
#include "nav2_msgs/msg/particle_cloud.hpp"
53+
54+
#include "rviz_rendering/objects/shape.hpp"
55+
#include "rviz_common/message_filter_display.hpp"
56+
57+
namespace Ogre
58+
{
59+
class ManualObject;
60+
} // namespace Ogre
61+
62+
namespace rviz_common
63+
{
64+
namespace properties
65+
{
66+
class EnumProperty;
67+
class ColorProperty;
68+
class FloatProperty;
69+
} // namespace properties
70+
} // namespace rviz_common
71+
72+
namespace rviz_rendering
73+
{
74+
class Arrow;
75+
class Axes;
76+
} // namespace rviz_rendering
77+
78+
namespace nav2_rviz_plugins
79+
{
80+
class FlatWeightedArrowsArray;
81+
struct OgrePoseWithWeight
82+
{
83+
Ogre::Vector3 position;
84+
Ogre::Quaternion orientation;
85+
float weight;
86+
};
87+
88+
/** @brief Displays a nav2_msgs/ParticleCloud message as a bunch of line-drawn weighted arrows. */
89+
class ParticleCloudDisplay : public rviz_common::MessageFilterDisplay<nav2_msgs::msg::ParticleCloud>
90+
{
91+
Q_OBJECT
92+
93+
public:
94+
// TODO(botteroa-si): Constructor for testing, remove once ros_nodes can be mocked and call
95+
// initialize instead
96+
ParticleCloudDisplay(
97+
rviz_common::DisplayContext * display_context,
98+
Ogre::SceneNode * scene_node);
99+
ParticleCloudDisplay();
100+
~ParticleCloudDisplay() override;
101+
102+
void processMessage(nav2_msgs::msg::ParticleCloud::ConstSharedPtr msg) override;
103+
void setShape(QString shape); // for testing
104+
105+
protected:
106+
void onInitialize() override;
107+
void reset() override;
108+
109+
private Q_SLOTS:
110+
/// Update the interface and visible shapes based on the selected shape type.
111+
void updateShapeChoice();
112+
113+
/// Update the arrow color.
114+
void updateArrowColor();
115+
116+
/// Update arrow geometry
117+
void updateGeometry();
118+
119+
private:
120+
void initializeProperties();
121+
bool validateFloats(const nav2_msgs::msg::ParticleCloud & msg);
122+
bool setTransform(std_msgs::msg::Header const & header);
123+
void updateDisplay();
124+
void updateArrows2d();
125+
void updateArrows3d();
126+
void updateAxes();
127+
void updateArrow3dGeometry();
128+
void updateAxesGeometry();
129+
130+
std::unique_ptr<rviz_rendering::Axes> makeAxes();
131+
std::unique_ptr<rviz_rendering::Arrow> makeArrow3d();
132+
133+
std::vector<OgrePoseWithWeight> poses_;
134+
std::unique_ptr<FlatWeightedArrowsArray> arrows2d_;
135+
std::vector<std::unique_ptr<rviz_rendering::Arrow>> arrows3d_;
136+
std::vector<std::unique_ptr<rviz_rendering::Axes>> axes_;
137+
138+
Ogre::SceneNode * arrow_node_;
139+
Ogre::SceneNode * axes_node_;
140+
141+
rviz_common::properties::EnumProperty * shape_property_;
142+
rviz_common::properties::ColorProperty * arrow_color_property_;
143+
rviz_common::properties::FloatProperty * arrow_alpha_property_;
144+
145+
rviz_common::properties::FloatProperty * arrow_min_length_property_;
146+
rviz_common::properties::FloatProperty * arrow_max_length_property_;
147+
148+
float min_length_;
149+
float max_length_;
150+
float length_scale_;
151+
float head_radius_scale_;
152+
float head_length_scale_;
153+
float shaft_radius_scale_;
154+
};
155+
156+
} // namespace nav2_rviz_plugins
157+
158+
#endif // NAV2_RVIZ_PLUGINS__PARTICLE_CLOUD_DISPLAY__PARTICLE_CLOUD_DISPLAY_HPP_

nav2_rviz_plugins/plugins_description.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,10 @@
1212
<description>The Navigation2 rviz panel.</description>
1313
</class>
1414

15+
<class name="nav2_rviz_plugins/ParticleCloud"
16+
type="nav2_rviz_plugins::ParticleCloudDisplay"
17+
base_class_type="rviz_common::Display">
18+
<description>The Particle Cloud rviz display.</description>
19+
</class>
20+
1521
</library>

0 commit comments

Comments
 (0)