Skip to content

Commit 277b5f4

Browse files
feat: autoware trajectory kinematics rviz (autowarefoundation#392) (#39)
* feat: new panel trajectory kinematic rviz * fix * chore: fix cspell * chore: font name Segoe should be allowed --------- Signed-off-by: YuxuanLiuTier4Desktop <619684051@qq.com>
1 parent ec1d088 commit 277b5f4

19 files changed

Lines changed: 2723 additions & 1 deletion

.cspell-partial.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"usecols",
3030
"velb",
3131
"viridis",
32-
"zdata"
32+
"zdata",
33+
"Segoe"
3334
]
3435
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
cmake_minimum_required(VERSION 3.14)
2+
project(autoware_trajectory_kinematics_rviz_plugin)
3+
4+
find_package(autoware_cmake REQUIRED)
5+
autoware_package()
6+
7+
find_package(Qt5 REQUIRED Core Widgets Charts)
8+
set(QT_LIBRARIES Qt5::Widgets Qt5::Charts)
9+
set(CMAKE_AUTOMOC ON)
10+
set(CMAKE_INCLUDE_CURRENT_DIR ON)
11+
add_definitions(-DQT_NO_KEYWORDS)
12+
13+
ament_auto_add_library(${PROJECT_NAME} SHARED
14+
src/trajectory_message_adapter.cpp
15+
src/trajectory_series_manager.cpp
16+
src/trajectory_kinematics_chart_view.cpp
17+
src/trajectory_kinematics_plot_widget.cpp
18+
src/trajectory_kinematics_panel.cpp
19+
)
20+
21+
target_link_libraries(${PROJECT_NAME}
22+
${QT_LIBRARIES}
23+
)
24+
25+
pluginlib_export_plugin_description_file(rviz_common plugins/plugin_description.xml)
26+
27+
ament_auto_package(
28+
INSTALL_TO_SHARE
29+
icons
30+
plugins
31+
)
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# autoware_trajectory_kinematics_rviz_plugin
2+
3+
RViz2 **panel plugin** that plots kinematic quantities along planned paths and compares **multiple trajectories** on one Qt Charts graph.
4+
5+
## Features
6+
7+
- Subscribe to one or more topics publishing:
8+
- `autoware_planning_msgs/msg/Trajectory`, or
9+
- `autoware_internal_planning_msgs/msg/ScoredCandidateTrajectories`
10+
- Choose **X** (time from start or arc length) and **Y** (velocity, acceleration, curvature, lateral acceleration).
11+
- Checkbox which series to plot; optional **fixed X/Y axis ranges**; hover tooltip with crosshair.
12+
- Panel layout and topic list are stored in the RViz config (`save` / `load`).
13+
14+
## Usage
15+
16+
1. Build the workspace with this package in the overlay (standard `colcon build`).
17+
2. Start RViz2, **Add Panel** → select **`autoware_trajectory_kinematics_rviz_plugin/TrajectoryKinematicsPanel`**.
18+
3. Choose message kind, add topics (dropdown or “Other topic”), tick trajectories to plot, set axes.
19+
20+
## ROS interfaces
21+
22+
- **Subscribes** (user-configured): topics you add, as `Trajectory` or `ScoredCandidateTrajectories` depending on the kind selector.
23+
- **Does not publish** topics.
18.4 KB
Loading
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0"?>
2+
<?xml-model href="http://download.ros.org/schema/package_format3.xsd" schematypens="http://www.w3.org/2001/XMLSchema"?>
3+
<package format="3">
4+
<name>autoware_trajectory_kinematics_rviz_plugin</name>
5+
<version>0.46.0</version>
6+
<description>RViz2 panel to plot trajectory kinematics (velocity, acceleration, curvature, lateral acceleration) from Trajectory or ScoredCandidateTrajectories topics.</description>
7+
<maintainer email="taiki.tanaka@tier4.jp">Taiki Tanaka</maintainer>
8+
<license>Apache License 2.0</license>
9+
10+
<buildtool_depend>ament_cmake_auto</buildtool_depend>
11+
<buildtool_depend>autoware_cmake</buildtool_depend>
12+
13+
<depend>autoware_internal_planning_msgs</depend>
14+
<depend>autoware_planning_msgs</depend>
15+
<depend>libqt5-charts-dev</depend>
16+
<depend>pluginlib</depend>
17+
<depend>rclcpp</depend>
18+
<depend>rviz_common</depend>
19+
20+
<test_depend>ament_cmake_gtest</test_depend>
21+
<test_depend>ament_lint_auto</test_depend>
22+
<test_depend>autoware_lint_common</test_depend>
23+
24+
<export>
25+
<build_type>ament_cmake</build_type>
26+
</export>
27+
</package>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<library path="autoware_trajectory_kinematics_rviz_plugin">
2+
<class
3+
name="autoware_trajectory_kinematics_rviz_plugin/TrajectoryKinematicsPanel"
4+
type="autoware::visualization::trajectory_kinematics_rviz_plugin::TrajectoryKinematicsPanel"
5+
base_class_type="rviz_common::Panel">
6+
<description>Plot kinematics along autoware_planning_msgs/Trajectory or autoware_internal_planning_msgs/ScoredCandidateTrajectories (multi-series comparison).</description>
7+
</class>
8+
</library>
Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
// Copyright 2026 TIER IV, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef KINEMATICS_TYPES_HPP_
16+
#define KINEMATICS_TYPES_HPP_
17+
18+
#include <cstdint>
19+
#include <string>
20+
#include <vector>
21+
22+
namespace autoware::visualization::trajectory_kinematics_rviz_plugin
23+
{
24+
25+
/// @brief One sample along a trajectory polyline with derived kinematics for plotting.
26+
struct SeriesPoint
27+
{
28+
double time_from_start_sec{0.0};
29+
double arc_length_m{0.0};
30+
double longitudinal_velocity_mps{0.0};
31+
double acceleration_mps2{0.0};
32+
/// Signed planar curvature [1/m] (Menger estimate on XY).
33+
double curvature_1pm{0.0};
34+
/// Approximate lateral acceleration [m/s²] using a_lat ≈ v_x² κ (planar bicycle-style estimate).
35+
double lateral_acceleration_mps2{0.0};
36+
};
37+
38+
/// @brief A plottable series: ROS topic, logical key, human-readable label, and sampled points.
39+
struct TrajectorySeriesData
40+
{
41+
std::string topic;
42+
/// Stable id within the topic (e.g. "trajectory", "candidate_3").
43+
std::string key;
44+
std::string label;
45+
std::vector<SeriesPoint> points;
46+
};
47+
48+
/// @brief Selects which scalar is read from SeriesPoint for an axis or tooltip.
49+
enum class AxisId : std::uint8_t {
50+
TIME_FROM_START = 0,
51+
ARC_LENGTH,
52+
LONGITUDINAL_VELOCITY,
53+
ACCELERATION,
54+
CURVATURE,
55+
LATERAL_ACCELERATION,
56+
};
57+
58+
/// @brief Human-readable labels and units for axis titles and tooltips.
59+
struct AxisDefinition
60+
{
61+
AxisId id;
62+
const char * label;
63+
const char * unit;
64+
};
65+
66+
/// @brief X-axis choices (time or arc length).
67+
inline const std::vector<AxisDefinition> & xAxisDefinitions()
68+
{
69+
static const std::vector<AxisDefinition> defs = {
70+
{AxisId::TIME_FROM_START, "Time from start", "s"},
71+
{AxisId::ARC_LENGTH, "Arc length", "m"},
72+
};
73+
return defs;
74+
}
75+
76+
/// @brief Y-axis choices (longitudinal/lateral motion and curvature).
77+
inline const std::vector<AxisDefinition> & yAxisDefinitions()
78+
{
79+
static const std::vector<AxisDefinition> defs = {
80+
{AxisId::LONGITUDINAL_VELOCITY, "Longitudinal velocity", "m/s"},
81+
{AxisId::ACCELERATION, "Acceleration", "m/s²"},
82+
{AxisId::CURVATURE, "Curvature (signed)", "1/m"},
83+
{AxisId::LATERAL_ACCELERATION, "Lateral acceleration (v²κ)", "m/s²"},
84+
};
85+
return defs;
86+
}
87+
88+
/// @brief Maps a kinematics axis id to the corresponding field in `p`.
89+
inline double accessAxisValue(const SeriesPoint & p, AxisId id)
90+
{
91+
switch (id) {
92+
case AxisId::TIME_FROM_START:
93+
return p.time_from_start_sec;
94+
case AxisId::ARC_LENGTH:
95+
return p.arc_length_m;
96+
case AxisId::LONGITUDINAL_VELOCITY:
97+
return p.longitudinal_velocity_mps;
98+
case AxisId::ACCELERATION:
99+
return p.acceleration_mps2;
100+
case AxisId::CURVATURE:
101+
return p.curvature_1pm;
102+
case AxisId::LATERAL_ACCELERATION:
103+
return p.lateral_acceleration_mps2;
104+
}
105+
#if defined(__GNUC__) || defined(__clang__)
106+
__builtin_unreachable();
107+
#else
108+
return 0.0;
109+
#endif
110+
}
111+
112+
/// @brief Looks up axis metadata from xAxisDefinitions() then yAxisDefinitions().
113+
inline const AxisDefinition * findAxisDefinition(AxisId id)
114+
{
115+
for (const auto & d : xAxisDefinitions()) {
116+
if (d.id == id) {
117+
return &d;
118+
}
119+
}
120+
for (const auto & d : yAxisDefinitions()) {
121+
if (d.id == id) {
122+
return &d;
123+
}
124+
}
125+
return nullptr;
126+
}
127+
128+
/// @brief Returns the display label for `id`, or `"?"` if unknown.
129+
inline const char * axisLabel(AxisId id)
130+
{
131+
const AxisDefinition * d = findAxisDefinition(id);
132+
return d ? d->label : "?";
133+
}
134+
135+
/// @brief Returns the unit string for `id`, or empty if unknown.
136+
inline const char * axisUnit(AxisId id)
137+
{
138+
const AxisDefinition * d = findAxisDefinition(id);
139+
return d ? d->unit : "";
140+
}
141+
142+
/// @brief Optional fixed axis ranges for the plot (honored only when the corresponding lock flag is
143+
/// true).
144+
struct PlotAxisRangeOptions
145+
{
146+
bool lock_x{false};
147+
double x_min{0.0};
148+
double x_max{1.0};
149+
bool lock_y{false};
150+
double y_min{-1.0};
151+
double y_max{1.0};
152+
};
153+
154+
} // namespace autoware::visualization::trajectory_kinematics_rviz_plugin
155+
156+
#endif // KINEMATICS_TYPES_HPP_
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
// Copyright 2026 TIER IV, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
//
15+
// Duplicated from tier4_state_rviz_plugin/src/include/material_colors.hpp for a self-contained
16+
// dependency graph. Palette matches AutowareStatePanel styling.
17+
18+
#ifndef MATERIAL_COLORS_HPP_
19+
#define MATERIAL_COLORS_HPP_
20+
21+
#include <QColor>
22+
23+
#include <string>
24+
25+
namespace autoware::visualization::trajectory_kinematics_rviz_plugin::style
26+
{
27+
28+
/// @brief Material Design 3–style palette as hex strings for RViz panel QSS and QColor
29+
/// construction.
30+
struct MaterialColors
31+
{
32+
std::string primary = "#8BD0F0";
33+
std::string surface_tint = "#8BD0F0";
34+
std::string on_primary = "#003546";
35+
std::string primary_container = "#004D64";
36+
std::string on_primary_container = "#BEE9FF";
37+
std::string secondary = "#B4CAD6";
38+
std::string on_secondary = "#1F333C";
39+
std::string secondary_container = "#354A54";
40+
std::string on_secondary_container = "#D0E6F2";
41+
std::string tertiary = "#C6C2EA";
42+
std::string on_tertiary = "#2F2D4D";
43+
std::string tertiary_container = "#454364";
44+
std::string on_tertiary_container = "#E3DFFF";
45+
std::string error = "#FFB4AB";
46+
std::string on_error = "#690005";
47+
std::string error_container = "#820008";
48+
std::string error_press = "#982127";
49+
std::string on_error_container = "#8c0f16";
50+
std::string background = "#0F1417";
51+
std::string on_background = "#DFE3E7";
52+
std::string surface = "#0F1417";
53+
std::string on_surface = "#DFE3E7";
54+
std::string surface_variant = "#40484C";
55+
std::string on_surface_variant = "#C0C8CD";
56+
std::string outline = "#8A9297";
57+
std::string outline_variant = "#40484C";
58+
std::string shadow = "#000000";
59+
std::string scrim = "#000000";
60+
std::string inverse_surface = "#DFE3E7";
61+
std::string inverse_on_surface = "#2C3134";
62+
std::string inverse_primary = "#126682";
63+
std::string primary_fixed = "#BEE9FF";
64+
std::string on_primary_fixed = "#001F2A";
65+
std::string primary_fixed_dim = "#8BD0F0";
66+
std::string on_primary_fixed_variant = "#004D64";
67+
std::string secondary_fixed = "#D0E6F2";
68+
std::string on_secondary_fixed = "#081E27";
69+
std::string secondary_fixed_dim = "#B4CAD6";
70+
std::string on_secondary_fixed_variant = "#354A54";
71+
std::string tertiary_fixed = "#E3DFFF";
72+
std::string on_tertiary_fixed = "#1A1836";
73+
std::string tertiary_fixed_dim = "#C6C2EA";
74+
std::string on_tertiary_fixed_variant = "#454364";
75+
std::string surface_dim = "#0F1417";
76+
std::string surface_bright = "#353A3D";
77+
std::string surface_container_lowest = "#0A0F11";
78+
std::string surface_container_low = "#171C1F";
79+
std::string surface_container = "#1B2023";
80+
std::string surface_container_high = "#262B2E";
81+
std::string surface_container_highest = "#303538";
82+
std::string disabled_elevated_button_bg = "#292D30";
83+
std::string success = "#8DF08B";
84+
std::string warning = "#EEF08B";
85+
std::string info = "#8BD0F0";
86+
std::string danger = "#F08B8B";
87+
88+
std::string enabled_button_bg = "#8BD0F0";
89+
std::string hover_button_bg = "#84c2e6";
90+
std::string pressed_button_bg = "#699BB8";
91+
std::string checked_button_bg = "#699BB8";
92+
std::string disabled_button_bg = "#292d30";
93+
std::string disabled_button_text = "#6e7276";
94+
95+
std::string on_surface_hover_bg = "#212429";
96+
std::string on_surface_pressed_bg = "#292d32";
97+
std::string on_surface_disabled = "#5e6266";
98+
99+
std::string surface_container_low_hover = "#262931";
100+
std::string surface_container_low_pressed = "#2d303a";
101+
};
102+
103+
inline const MaterialColors default_colors{};
104+
105+
/// Convert a CSS-style `#RGB` string from the palette to `QColor`.
106+
inline QColor hexToQColor(const std::string & hex)
107+
{
108+
return QColor(QString::fromStdString(hex));
109+
}
110+
111+
} // namespace autoware::visualization::trajectory_kinematics_rviz_plugin::style
112+
113+
#endif // MATERIAL_COLORS_HPP_

0 commit comments

Comments
 (0)