Skip to content

Commit e66144b

Browse files
committed
TODO: add ego information handling
Signed-off-by: ktro2828 <kotaro.uetake@tier4.jp>
1 parent 4d54696 commit e66144b

File tree

8 files changed

+41
-16
lines changed

8 files changed

+41
-16
lines changed

perception/tensorrt_mtr/CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ if (CUDA_FOUND)
2323
PATH_SUFFIXES lib lib64 bin
2424
DOC "CUDNN library.")
2525
else()
26-
message(FAITAL_ERROR "Can not find CUDA")
26+
message(FATAL_ERROR "Can not find CUDA")
2727
endif()
2828

2929
list(APPEND TRT_PLUGINS "nvinfer")
3030
list(APPEND TRT_PLUGINS "nvonnxparser")
3131
list(APPEND TRT_PLUGINS "nvparsers")
3232
foreach(libName ${TRT_PLUGINS})
33-
find_library(${libName}_lib NAMES ${libName} "/usr" PATH_SUFFIES lib)
33+
find_library(${libName}_lib NAMES ${libName} "/usr" PATH_SUFFIXES lib)
3434
list(APPEND TRT_PLUGINS ${${libName}_lib})
3535
endforeach()
3636

perception/tensorrt_mtr/include/tensorrt_mtr/node.hpp

+7-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ using autoware_auto_perception_msgs::msg::TrackedObject;
5656
using autoware_auto_perception_msgs::msg::TrackedObjects;
5757
using nav_msgs::msg::Odometry;
5858

59+
// TODO(ktro2828): use received ego size topic
60+
constexpr float EGO_LENGTH = 4.0f;
61+
constexpr float EGO_WIDTH = 2.0f;
62+
constexpr float EGO_HEIGHT = 1.0f;
63+
5964
class PolylineTypeMap
6065
{
6166
public:
@@ -179,10 +184,11 @@ class MTRNode : public rclcpp::Node
179184
tier4_autoware_utils::TransformListener transform_listener_;
180185

181186
// MTR parameters
182-
std::unique_ptr<MtrConfig> config_ptr_;
187+
std::unique_ptr<MTRConfig> config_ptr_;
183188
std::unique_ptr<TrtMTR> model_ptr_;
184189
PolylineTypeMap polyline_type_map_;
185190
std::shared_ptr<PolylineData> polyline_ptr_;
191+
std::vector<AgentState> ego_states_;
186192
std::vector<float> timestamps_;
187193
}; // class MTRNode
188194
} // namespace trt_mtr

perception/tensorrt_mtr/include/tensorrt_mtr/trt_mtr.hpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ namespace trt_mtr
3636
/**
3737
* @brief A configuration of MTR.
3838
*/
39-
struct MtrConfig
39+
struct MTRConfig
4040
{
4141
/**
42-
* @brief Construct a new Mtr Config object
42+
* @brief Construct a new instance.
4343
*
4444
* @param target_labels An array of target label names.
4545
* @param num_mode The number of modes.
@@ -49,7 +49,7 @@ struct MtrConfig
4949
* @param intention_point_filepath The path to intention points file.
5050
* @param num_intention_point_cluster The number of clusters for intension points.
5151
*/
52-
MtrConfig(
52+
MTRConfig(
5353
const std::vector<std::string> & target_labels = {"VEHICLE", "PEDESTRIAN", "CYCLIST"},
5454
const size_t num_past = 10, const size_t num_mode = 6, const size_t num_future = 80,
5555
const size_t max_num_polyline = 768, const size_t max_num_point = 20,
@@ -81,7 +81,7 @@ struct MtrConfig
8181
std::array<float, 2> offset_xy;
8282
std::string intention_point_filepath;
8383
size_t num_intention_point_cluster;
84-
};
84+
}; // struct MTRConfig
8585

8686
/**
8787
* @brief A class to inference with MTR.
@@ -101,7 +101,7 @@ class TrtMTR
101101
*/
102102
TrtMTR(
103103
const std::string & model_path, const std::string & precision,
104-
const MtrConfig & config = MtrConfig(), const BatchConfig & batch_config = {1, 1, 1},
104+
const MTRConfig & config = MTRConfig(), const BatchConfig & batch_config = {1, 1, 1},
105105
const size_t max_workspace_size = (1ULL << 30),
106106
const BuildConfig & build_config = BuildConfig());
107107

@@ -122,7 +122,7 @@ class TrtMTR
122122
*
123123
* @return const MtrConfig& The model configuration which can not be updated.
124124
*/
125-
const MtrConfig & config() const { return config_; }
125+
const MTRConfig & config() const { return config_; }
126126

127127
private:
128128
/**
@@ -152,7 +152,7 @@ class TrtMTR
152152
bool postProcess(AgentData & agent_data, std::vector<PredictedTrajectory> & trajectories);
153153

154154
// model parameters
155-
MtrConfig config_;
155+
MTRConfig config_;
156156

157157
std::unique_ptr<MTRBuilder> builder_;
158158
cudaStream_t stream_{nullptr};

perception/tensorrt_mtr/lib/include/postprocess/postprocess_kernel.cuh

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
*
2424
* @param B The number of target agents.
2525
* @param M The number of modes.
26-
* @param T The number of future timestmaps.
26+
* @param T The number of future timestamps.
2727
* @param inDim The number of input agent state dimensions.
2828
* @param targetState Source target agent states at latest timestamp, in shape [B*inDim].
2929
* @param outDim The number of output state dimensions.

perception/tensorrt_mtr/lib/include/preprocess/polyline_preprocess_kernel.cuh

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ __global__ void calculatePolylineCenterKernel(
8282

8383
/**
8484
* @brief In cases of the number of batch polylines (L) is greater than K,
85-
* extacts the topK elements.
85+
* extracts the topK elements.
8686
*
8787
* @param L The number of source polylines.
8888
* @param K The number of polylines expected as the model input.

perception/tensorrt_mtr/package.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<package format="3">
44
<name>tensorrt_mtr</name>
55
<version>0.1.0</version>
6-
<description>ROS 2 Node of Motion Transfomer(a.k.a MTR).</description>
6+
<description>ROS 2 Node of Motion Transfromer(a.k.a MTR).</description>
77
<maintainer email="kotaro.uetake@tier4.jp">kotarouetake</maintainer>
88
<license>Apache-2.0</license>
99

perception/tensorrt_mtr/src/node.cpp

+21-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ MTRNode::MTRNode(const rclcpp::NodeOptions & node_options)
182182
declare_parameter<std::string>("intention_point_filepath");
183183
const auto num_intention_point_cluster =
184184
static_cast<size_t>(declare_parameter<int>("num_intention_point_cluster"));
185-
config_ptr_ = std::make_unique<MtrConfig>(
185+
config_ptr_ = std::make_unique<MTRConfig>(
186186
target_labels, num_past, num_mode, num_future, max_num_polyline, max_num_point,
187187
point_break_distance, offset_xy, intention_point_filepath, num_intention_point_cluster);
188188
model_ptr_ = std::make_unique<TrtMTR>(model_path, precision, *config_ptr_.get());
@@ -289,7 +289,26 @@ void MTRNode::onMap(const HADMapBin::ConstSharedPtr map_msg)
289289

290290
void MTRNode::onEgo(const Odometry::ConstSharedPtr ego_msg)
291291
{
292-
RCLCPP_INFO_STREAM(get_logger(), "Ego msg is received: " << ego_msg->header.frame_id);
292+
constexpr size_t max_buffer_size = 100;
293+
const auto & position = ego_msg->pose.pose.position;
294+
const auto & twist = ego_msg->twist.twist;
295+
const auto yaw = static_cast<float>(tf2::getYaw(ego_msg->pose.pose.orientation));
296+
float ax = 0.0f, ay = 0.0f;
297+
if (!ego_states_.empty()) {
298+
const auto & latest_state = ego_states_.back();
299+
ax = static_cast<float>(twist.linear.x) - latest_state.vx();
300+
ay = static_cast<float>(twist.linear.y) - latest_state.vy();
301+
}
302+
303+
// TODO(ktro2828): use received ego size topic
304+
ego_states_.emplace_back(
305+
static_cast<float>(position.x), static_cast<float>(position.y), static_cast<float>(position.z),
306+
EGO_LENGTH, EGO_WIDTH, EGO_HEIGHT, yaw, static_cast<float>(twist.linear.x),
307+
static_cast<float>(twist.linear.y), ax, ay, true);
308+
309+
if (max_buffer_size < ego_states_.size()) {
310+
ego_states_.erase(ego_states_.begin(), ego_states_.begin());
311+
}
293312
}
294313

295314
bool MTRNode::convertLaneletToPolyline()

perception/tensorrt_mtr/src/trt_mtr.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
namespace trt_mtr
2222
{
2323
TrtMTR::TrtMTR(
24-
const std::string & model_path, const std::string & precision, const MtrConfig & config,
24+
const std::string & model_path, const std::string & precision, const MTRConfig & config,
2525
const BatchConfig & batch_config, const size_t max_workspace_size,
2626
const BuildConfig & build_config)
2727
: config_(config),

0 commit comments

Comments
 (0)