Skip to content

Commit 44edda6

Browse files
committed
chore: apply ktro2828/autoware_mtr
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
1 parent 9c054ca commit 44edda6

22 files changed

+395
-161
lines changed

perception/autoware_mtr/.gitignore

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
devel/
2+
logs/
3+
build/
4+
bin/
5+
msg_gen/
6+
srv_gen/
7+
data/*onnx
8+
msg/*Action.msg
9+
msg/*ActionFeedback.msg
10+
msg/*ActionGoal.msg
11+
msg/*ActionResult.msg
12+
msg/*Feedback.msg
13+
msg/*Goal.msg
14+
msg/*Result.msg
15+
msg/_*.py
16+
build_isolated/
17+
devel_isolated/
18+
19+
# Generated by dynamic reconfigure
20+
*.cfgc
21+
/cfg/cpp/
22+
/cfg/*.py
23+
24+
# Ignore generated docs
25+
*.dox
26+
*.wikidoc
27+
28+
# eclipse stuff
29+
.project
30+
.cproject
31+
32+
# qcreator stuff
33+
CMakeLists.txt.user
34+
35+
srv/_*.py
36+
*.pcd
37+
*.pyc
38+
qtcreator-*
39+
*.user
40+
41+
/planning/cfg
42+
/planning/docs
43+
/planning/src
44+
45+
*~
46+
47+
# Emacs
48+
.#*
49+
50+
# Catkin custom files
51+
CATKIN_IGNORE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
repos:
2+
- repo: https://github.com/tcort/markdown-link-check
3+
rev: v3.12.2
4+
hooks:
5+
- id: markdown-link-check
6+
args: [--quiet, --config=.markdown-link-check.json]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
ci:
2+
autofix_commit_msg: "style(pre-commit): autofix"
3+
4+
repos:
5+
- repo: https://github.com/pre-commit/pre-commit-hooks
6+
rev: v4.6.0
7+
hooks:
8+
- id: check-json
9+
- id: check-merge-conflict
10+
- id: check-toml
11+
- id: check-xml
12+
- id: check-yaml
13+
args: [--unsafe]
14+
- id: detect-private-key
15+
- id: end-of-file-fixer
16+
- id: mixed-line-ending
17+
- id: trailing-whitespace
18+
args: [--markdown-linebreak-ext=md]
19+
20+
- repo: https://github.com/igorshubovych/markdownlint-cli
21+
rev: v0.41.0
22+
hooks:
23+
- id: markdownlint
24+
args: [-c, .markdownlint.yaml, --fix]
25+
26+
- repo: https://github.com/pre-commit/mirrors-prettier
27+
rev: v4.0.0-alpha.8
28+
hooks:
29+
- id: prettier
30+
31+
- repo: https://github.com/adrienverge/yamllint
32+
rev: v1.35.1
33+
hooks:
34+
- id: yamllint
35+
36+
- repo: https://github.com/tier4/pre-commit-hooks-ros
37+
rev: v0.10.0
38+
hooks:
39+
- id: flake8-ros
40+
- id: prettier-xacro
41+
- id: prettier-launch-xml
42+
- id: prettier-package-xml
43+
- id: ros-include-guard
44+
- id: sort-package-xml
45+
46+
- repo: https://github.com/shellcheck-py/shellcheck-py
47+
rev: v0.10.0.1
48+
hooks:
49+
- id: shellcheck
50+
51+
- repo: https://github.com/scop/pre-commit-shfmt
52+
rev: v3.9.0-1
53+
hooks:
54+
- id: shfmt
55+
args: [-w, -s, -i=4]
56+
57+
- repo: https://github.com/pycqa/isort
58+
rev: 5.13.2
59+
hooks:
60+
- id: isort
61+
62+
- repo: https://github.com/psf/black
63+
rev: 24.8.0
64+
hooks:
65+
- id: black
66+
args: [--line-length=100]
67+
68+
- repo: https://github.com/pre-commit/mirrors-clang-format
69+
rev: v18.1.8
70+
hooks:
71+
- id: clang-format
72+
types_or: [c++, c, cuda]
73+
74+
- repo: https://github.com/cpplint/cpplint
75+
rev: 1.6.1
76+
hooks:
77+
- id: cpplint
78+
args: [--quiet]
79+
exclude: .cu
80+
81+
- repo: https://github.com/python-jsonschema/check-jsonschema
82+
rev: 0.29.2
83+
hooks:
84+
- id: check-metaschema
85+
files: ^.+/schema/.*schema\.json$
86+
87+
- repo: local
88+
hooks:
89+
- id: prettier-svg
90+
name: prettier svg
91+
description: Apply Prettier with plugin-xml to svg.
92+
entry: prettier --write --list-different --ignore-unknown --print-width 200 --xml-self-closing-space false --xml-whitespace-sensitivity ignore
93+
language: node
94+
files: .svg$
95+
additional_dependencies: [prettier@2.7.1, "@prettier/plugin-xml@2.2.0"]

perception/autoware_mtr/LICENSE

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
Apache License
32
Version 2.0, January 2004
43
http://www.apache.org/licenses/

perception/autoware_mtr/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
# Motion TRansformer (MTR)
1+
# autoware-mtr

perception/autoware_mtr/config/mtr.param.yaml

-3
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
intention_point_filepath: "$(var data_path)/intention_point.csv"
1313
num_intention_point_cluster: 64
1414
polyline_label_path: "$(var data_path)/polyline_label.txt"
15-
static_inference:
16-
num_target: 2
17-
num_agent: 7
1815
build_params:
1916
is_dynamic: false
2017
precision: "FP32"

perception/autoware_mtr/include/autoware/mtr/builder.hpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -155,10 +155,10 @@ class MTRBuilder
155155
*
156156
* @return True if plugins were initialized successfully.
157157
*/
158-
bool isInitialized() const;
158+
[[nodiscard]] bool isInitialized() const;
159159

160160
// Return true if the model supports dynamic shape inference.
161-
bool isDynamic() const;
161+
[[nodiscard]] bool isDynamic() const;
162162

163163
// Set binding dimensions for specified for dynamic shape inference.
164164
bool setBindingDimensions(int index, nvinfer1::Dims dimensions);
@@ -184,7 +184,7 @@ class MTRBuilder
184184
bool loadEngine(const std::string & filepath);
185185

186186
// Create a cache path of engine file.
187-
fs::path createEngineCachePath() const;
187+
[[nodiscard]] fs::path createEngineCachePath() const;
188188

189189
/**
190190
* @brief Build engine from onnx file.

perception/autoware_mtr/include/autoware/mtr/cuda_helper.hpp

-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323

2424
#include <cuda_runtime_api.h>
2525

26-
#include <iostream>
2726
#include <memory>
2827
#include <sstream>
2928
#include <stdexcept>

perception/autoware_mtr/include/autoware/mtr/node.hpp

+27-27
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,13 @@
2222

2323
#include <autoware/object_recognition_utils/object_classification.hpp>
2424
#include <autoware/universe_utils/geometry/geometry.hpp>
25+
#include <autoware/universe_utils/ros/polling_subscriber.hpp>
2526
#include <autoware/universe_utils/ros/transform_listener.hpp>
2627
#include <autoware/universe_utils/ros/uuid_helper.hpp>
28+
#include <autoware_vehicle_info_utils/vehicle_info_utils.hpp>
2729
#include <rclcpp/rclcpp.hpp>
2830

31+
#include <autoware_map_msgs/msg/detail/lanelet_map_bin__struct.hpp>
2932
#include <autoware_map_msgs/msg/lanelet_map_bin.hpp>
3033
#include <autoware_perception_msgs/msg/object_classification.hpp>
3134
#include <autoware_perception_msgs/msg/predicted_object_kinematics.hpp>
@@ -47,7 +50,8 @@
4750

4851
namespace autoware::mtr
4952
{
50-
using autoware_map_msgs::msg::LaneletMapBin;
53+
using HADMapBin = autoware_map_msgs::msg::LaneletMapBin;
54+
using autoware::vehicle_info_utils::VehicleInfo;
5155
using autoware_perception_msgs::msg::ObjectClassification;
5256
using autoware_perception_msgs::msg::PredictedObject;
5357
using autoware_perception_msgs::msg::PredictedObjectKinematics;
@@ -57,17 +61,6 @@ using autoware_perception_msgs::msg::TrackedObject;
5761
using autoware_perception_msgs::msg::TrackedObjects;
5862
using nav_msgs::msg::Odometry;
5963

60-
// TODO(ktro2828): use received ego size topic
61-
// wheel_base: between front wheel center and rear wheel center [m]
62-
// wheel_tread: between left wheel center and right wheel center [m]
63-
// front_overhang: between front wheel center and vehicle front [m]
64-
// rear_overhang: between rear wheel center and vehicle rear [m]
65-
// left_overhang: between left wheel center and vehicle left [m]
66-
// right_overhang: between right wheel center and vehicle right [m]
67-
constexpr float EGO_LENGTH = 4.0f;
68-
constexpr float EGO_WIDTH = 2.0f;
69-
constexpr float EGO_HEIGHT = 1.0f;
70-
7164
class PolylineTypeMap
7265
{
7366
public:
@@ -88,9 +81,9 @@ class PolylineTypeMap
8881
}
8982
}
9083

91-
// Return the ID corresponding to the label type. If specified type is not contained in map,
84+
// Return the ID of the corresponding label type. If specified type is not contained in map,
9285
// return `-1`.
93-
int type_to_id(const std::string & type) const
86+
[[nodiscard]] int getTypeID(const std::string & type) const
9487
{
9588
return label_map_.count(type) == 0 ? -1 : label_map_.at(type);
9689
}
@@ -112,42 +105,47 @@ class MTRNode : public rclcpp::Node
112105
void callback(const TrackedObjects::ConstSharedPtr object_msg);
113106

114107
// Callback being invoked when the HD map topic is subscribed.
115-
void on_map(const LaneletMapBin::ConstSharedPtr map_msg);
108+
void onMap(const HADMapBin::ConstSharedPtr map_msg);
116109

117-
// Callback being invoked when the Ego's odometry topic is subscribed.
118-
void on_ego(const Odometry::ConstSharedPtr ego_msg);
110+
// Fetch data of Ego's odometry topic.
111+
bool fetchData();
119112

120113
// Convert Lanelet to `PolylineData`.
121-
bool lanelet_to_polyline();
114+
bool convertLaneletToPolyline();
122115

123116
// Remove ancient agent histories.
124-
void remove_ancient_history(
117+
void removeAncientAgentHistory(
125118
const float current_time, const TrackedObjects::ConstSharedPtr objects_msg);
126119

127120
// Appends new states to history.
128-
void update_history(const float current_time, const TrackedObjects::ConstSharedPtr objects_msg);
121+
void updateAgentHistory(
122+
const float current_time, const TrackedObjects::ConstSharedPtr objects_msg);
129123

130124
// Extract ego state stored in the buffer which has the nearest timestamp from current timestamp.
131-
AgentState lookup_ego_state(const float current_time) const;
125+
AgentState extractNearestEgo(const float current_time) const;
126+
127+
[[nodiscard]] TrackedObject makeEgoTrackedObject(const Odometry::ConstSharedPtr ego_msg) const;
132128

133129
// Extract target agents and return corresponding indices.
134130
// NOTE: Extract targets in order of proximity, closest first.
135-
std::vector<size_t> extract_target_agents(const std::vector<AgentHistory> & histories);
131+
std::vector<size_t> extractTargetAgent(const std::vector<AgentHistory> & histories);
136132

137133
// Return the timestamps relative from the first element.Return the timestamps relative from the
138134
// first element.
139-
std::vector<float> get_relative_timestamps() const;
135+
std::vector<float> getRelativeTimestamps() const;
140136

141137
// Generate `PredictedObject` from `PredictedTrajectory`.
142-
PredictedObject to_predicted_object(
138+
PredictedObject generatePredictedObject(
143139
const TrackedObject & object, const PredictedTrajectory & trajectory);
144140

145141
// ROS Publisher and Subscriber
146142
// TODO(ktro2828): add debug publisher
147143
rclcpp::Publisher<PredictedObjects>::SharedPtr pub_objects_;
148144
rclcpp::Subscription<TrackedObjects>::SharedPtr sub_objects_;
149-
rclcpp::Subscription<LaneletMapBin>::SharedPtr sub_map_;
150-
rclcpp::Subscription<Odometry>::SharedPtr sub_ego_;
145+
rclcpp::Subscription<HADMapBin>::SharedPtr sub_map_;
146+
// polling subscriber
147+
autoware::universe_utils::InterProcessPollingSubscriber<Odometry> sub_ego_{
148+
this, "/localization/kinematic_state"};
151149

152150
// Lanelet map pointers
153151
std::shared_ptr<lanelet::LaneletMap> lanelet_map_ptr_;
@@ -157,6 +155,8 @@ class MTRNode : public rclcpp::Node
157155
// Agent history
158156
std::map<std::string, AgentHistory> agent_history_map_;
159157
std::map<std::string, TrackedObject> object_msg_map_;
158+
TrackedObject ego_tracked_object_;
159+
VehicleInfo vehicle_info_;
160160

161161
// Pose transform listener
162162
autoware::universe_utils::TransformListener transform_listener_;
@@ -168,7 +168,7 @@ class MTRNode : public rclcpp::Node
168168
PolylineTypeMap polyline_type_map_;
169169
std::shared_ptr<PolylineData> polyline_ptr_;
170170
std::vector<std::pair<float, AgentState>> ego_states_;
171-
std::vector<float> timestamps_;
171+
std::vector<double> timestamps_;
172172
}; // class MTRNode
173173
} // namespace autoware::mtr
174174
#endif // AUTOWARE__MTR__NODE_HPP_

perception/autoware_mtr/include/autoware/mtr/trt_mtr.hpp

+5-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <array>
3030
#include <memory>
3131
#include <string>
32+
#include <utility>
3233
#include <vector>
3334

3435
namespace autoware::mtr
@@ -50,12 +51,12 @@ struct MTRConfig
5051
* @param intention_point_filepath The path to intention points file.
5152
* @param num_intention_point_cluster The number of clusters for intension points.
5253
*/
53-
MTRConfig(
54+
explicit MTRConfig(
5455
const std::vector<std::string> & target_labels = {"VEHICLE", "PEDESTRIAN", "CYCLIST"},
5556
const size_t num_past = 11, const size_t num_mode = 6, const size_t num_future = 80,
5657
const size_t max_num_polyline = 768, const size_t max_num_point = 20,
5758
const float point_break_distance = 1.0f,
58-
const std::string & intention_point_filepath = "./data/intention_point.csv",
59+
std::string intention_point_filepath = "./data/intention_point.csv",
5960
const size_t num_intention_point_cluster = 64)
6061
: target_labels(target_labels),
6162
num_class(target_labels.size()),
@@ -65,7 +66,7 @@ struct MTRConfig
6566
max_num_polyline(max_num_polyline),
6667
max_num_point(max_num_point),
6768
point_break_distance(point_break_distance),
68-
intention_point_filepath(intention_point_filepath),
69+
intention_point_filepath(std::move(intention_point_filepath)),
6970
num_intention_point_cluster(num_intention_point_cluster)
7071
{
7172
}
@@ -97,7 +98,7 @@ class TrtMTR
9798
* @param max_workspace_size The max size of workspace.
9899
* @param build_config The configuration of build.
99100
*/
100-
TrtMTR(
101+
explicit TrtMTR(
101102
const std::string & model_path, const MTRConfig & config = MTRConfig(),
102103
const BuildConfig & build_config = BuildConfig(),
103104
const size_t max_workspace_size = (1ULL << 30));

perception/autoware_mtr/launch/mtr.launch.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<arg name="input/objects" default="/perception/object_recognition/tracking/objects"/>
77
<arg name="input/vector_map" default="/map/vector_map"/>
88
<arg name="input/ego" default="/localization/kinematic_state"/>
9-
<arg name="output/objects" default="objects"/>
9+
<arg name="output/objects" default="mtr/objects"/>
1010
<arg name="build_only" default="false"/>
1111

1212
<node pkg="autoware_mtr" exec="autoware_mtr" name="mtr" output="screen">

0 commit comments

Comments
 (0)