Skip to content

Commit 94cfa00

Browse files
change back msgs and other things
Signed-off-by: Daniel Sanchez <danielsanchezaran@gmail.com>
1 parent 82bb53b commit 94cfa00

File tree

14 files changed

+370
-557
lines changed

14 files changed

+370
-557
lines changed

common/tier4_autoware_utils/include/tier4_autoware_utils/geometry/geometry.hpp

+21
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,27 @@ inline geometry_msgs::msg::Pose calcOffsetPose(
343343
tf2::toMsg(tf_pose * tf_offset, pose);
344344
return pose;
345345
}
346+
347+
/**
348+
* @brief Calculate offset pose. The offset values are defined in the local coordinate of the input
349+
* pose.
350+
*/
351+
inline geometry_msgs::msg::Pose calcOffsetPose(
352+
const geometry_msgs::msg::Pose & p, const double x, const double y, const double z,
353+
const double yaw)
354+
{
355+
geometry_msgs::msg::Pose pose;
356+
geometry_msgs::msg::Transform transform;
357+
transform.translation = createTranslation(x, y, z);
358+
transform.rotation = createQuaternionFromYaw(yaw);
359+
tf2::Transform tf_pose;
360+
tf2::Transform tf_offset;
361+
tf2::fromMsg(transform, tf_offset);
362+
tf2::fromMsg(p, tf_pose);
363+
tf2::toMsg(tf_pose * tf_offset, pose);
364+
return pose;
365+
}
366+
346367
} // namespace tier4_autoware_utils
347368

348369
#endif // TIER4_AUTOWARE_UTILS__GEOMETRY__GEOMETRY_HPP_
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,253 @@
1+
// Copyright 2024 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+
#ifndef AUTOWARE__UNIVERSE_UTILS__ROS__POLLING_SUBSCRIBER_HPP_
15+
#define AUTOWARE__UNIVERSE_UTILS__ROS__POLLING_SUBSCRIBER_HPP_
16+
17+
#include <rclcpp/rclcpp.hpp>
18+
19+
#include <memory>
20+
#include <stdexcept>
21+
#include <string>
22+
#include <vector>
23+
24+
namespace autoware::universe_utils
25+
{
26+
27+
/**
28+
* @brief Creates a SensorDataQoS profile with a single depth.
29+
* @return rclcpp::SensorDataQoS The QoS profile with depth set to 1.
30+
*/
31+
inline rclcpp::SensorDataQoS SingleDepthSensorQoS()
32+
{
33+
rclcpp::SensorDataQoS qos;
34+
qos.get_rmw_qos_profile().depth = 1;
35+
return qos;
36+
}
37+
38+
namespace polling_policy
39+
{
40+
41+
/**
42+
* @brief Polling policy that keeps the latest received message.
43+
*
44+
* This policy retains the latest received message and provides it when requested. If a new message
45+
* is received, it overwrites the previously stored message.
46+
*
47+
* @tparam MessageT The message type.
48+
*/
49+
template <typename MessageT>
50+
class Latest
51+
{
52+
private:
53+
typename MessageT::ConstSharedPtr data_{nullptr}; ///< Data pointer to store the latest data
54+
55+
protected:
56+
/**
57+
* @brief Check the QoS settings for the subscription.
58+
*
59+
* @param qos The QoS profile to check.
60+
* @throws std::invalid_argument If the QoS depth is not 1.
61+
*/
62+
void checkQoS(const rclcpp::QoS & qos)
63+
{
64+
if (qos.get_rmw_qos_profile().depth > 1) {
65+
throw std::invalid_argument(
66+
"InterProcessPollingSubscriber will be used with depth > 1, which may cause inefficient "
67+
"serialization while updateLatestData()");
68+
}
69+
}
70+
71+
public:
72+
/**
73+
* @brief Retrieve the latest data. If no new data has been received, the previously received data
74+
*
75+
* @return typename MessageT::ConstSharedPtr The latest data.
76+
*/
77+
typename MessageT::ConstSharedPtr takeData();
78+
};
79+
80+
/**
81+
* @brief Polling policy that keeps the newest received message.
82+
*
83+
* @tparam MessageT The message type.
84+
*/
85+
template <typename MessageT>
86+
class Newest
87+
{
88+
protected:
89+
/**
90+
* @brief Check the QoS settings for the subscription.
91+
*
92+
* @param qos The QoS profile to check.
93+
* @throws std::invalid_argument If the QoS depth is not 1.
94+
*/
95+
void checkQoS(const rclcpp::QoS & qos)
96+
{
97+
if (qos.get_rmw_qos_profile().depth > 1) {
98+
throw std::invalid_argument(
99+
"InterProcessPollingSubscriber will be used with depth > 1, which may cause inefficient "
100+
"serialization while updateLatestData()");
101+
}
102+
}
103+
104+
public:
105+
/**
106+
* @brief Retrieve the newest data. If no new data has been received, nullptr is returned.
107+
*
108+
* @return typename MessageT::ConstSharedPtr The newest data.
109+
*/
110+
typename MessageT::ConstSharedPtr takeData();
111+
};
112+
113+
/**
114+
* @brief Polling policy that keeps all received messages.
115+
*
116+
* @tparam MessageT The message type.
117+
*/
118+
template <typename MessageT>
119+
class All
120+
{
121+
protected:
122+
/**
123+
* @brief Check the QoS settings for the subscription.
124+
*
125+
* @param qos The QoS profile to check.
126+
*/
127+
void checkQoS(const rclcpp::QoS &) {}
128+
129+
public:
130+
/**
131+
* @brief Retrieve all data.
132+
*
133+
* @return std::vector<typename MessageT::ConstSharedPtr> The list of all received data.
134+
*/
135+
std::vector<typename MessageT::ConstSharedPtr> takeData();
136+
};
137+
138+
} // namespace polling_policy
139+
140+
/**
141+
* @brief Subscriber class that uses a specified polling policy.
142+
*
143+
* @tparam MessageT The message type.
144+
* @tparam PollingPolicy The polling policy to use.
145+
*/
146+
template <typename MessageT, template <typename> class PollingPolicy = polling_policy::Latest>
147+
class InterProcessPollingSubscriber : public PollingPolicy<MessageT>
148+
{
149+
friend PollingPolicy<MessageT>;
150+
151+
private:
152+
typename rclcpp::Subscription<MessageT>::SharedPtr subscriber_; ///< Subscription object
153+
154+
public:
155+
using SharedPtr = std::shared_ptr<InterProcessPollingSubscriber<MessageT, PollingPolicy>>;
156+
157+
/**
158+
* @brief Construct a new InterProcessPollingSubscriber object.
159+
*
160+
* @param node The node to attach the subscriber to.
161+
* @param topic_name The topic name to subscribe to.
162+
* @param qos The QoS profile to use for the subscription.
163+
*/
164+
explicit InterProcessPollingSubscriber(
165+
rclcpp::Node * node, const std::string & topic_name, const rclcpp::QoS & qos = rclcpp::QoS{1})
166+
{
167+
this->checkQoS(qos);
168+
169+
auto noexec_callback_group =
170+
node->create_callback_group(rclcpp::CallbackGroupType::MutuallyExclusive, false);
171+
172+
auto noexec_subscription_options = rclcpp::SubscriptionOptions();
173+
noexec_subscription_options.callback_group = noexec_callback_group;
174+
175+
subscriber_ = node->create_subscription<MessageT>(
176+
topic_name, qos,
177+
[node]([[maybe_unused]] const typename MessageT::ConstSharedPtr msg) { assert(false); },
178+
noexec_subscription_options);
179+
}
180+
181+
/**
182+
* @brief Create a subscription.
183+
*
184+
* @param node The node to attach the subscriber to.
185+
* @param topic_name The topic name to subscribe to.
186+
* @param qos The QoS profile to use for the subscription.
187+
* @return SharedPtr The created subscription.
188+
*/
189+
static SharedPtr create_subscription(
190+
rclcpp::Node * node, const std::string & topic_name, const rclcpp::QoS & qos = rclcpp::QoS{1})
191+
{
192+
return std::make_shared<InterProcessPollingSubscriber<MessageT, PollingPolicy>>(
193+
node, topic_name, qos);
194+
}
195+
196+
typename rclcpp::Subscription<MessageT>::SharedPtr subscriber() { return subscriber_; }
197+
};
198+
199+
namespace polling_policy
200+
{
201+
202+
template <typename MessageT>
203+
typename MessageT::ConstSharedPtr Latest<MessageT>::takeData()
204+
{
205+
auto & subscriber =
206+
static_cast<InterProcessPollingSubscriber<MessageT, Latest> *>(this)->subscriber_;
207+
auto new_data = std::make_shared<MessageT>();
208+
rclcpp::MessageInfo message_info;
209+
const bool success = subscriber->take(*new_data, message_info);
210+
if (success) {
211+
data_ = new_data;
212+
}
213+
214+
return data_;
215+
}
216+
217+
template <typename MessageT>
218+
typename MessageT::ConstSharedPtr Newest<MessageT>::takeData()
219+
{
220+
auto & subscriber =
221+
static_cast<InterProcessPollingSubscriber<MessageT, Newest> *>(this)->subscriber_;
222+
auto new_data = std::make_shared<MessageT>();
223+
rclcpp::MessageInfo message_info;
224+
const bool success = subscriber->take(*new_data, message_info);
225+
if (success) {
226+
return new_data;
227+
}
228+
return nullptr;
229+
}
230+
231+
template <typename MessageT>
232+
std::vector<typename MessageT::ConstSharedPtr> All<MessageT>::takeData()
233+
{
234+
auto & subscriber =
235+
static_cast<InterProcessPollingSubscriber<MessageT, All> *>(this)->subscriber_;
236+
std::vector<typename MessageT::ConstSharedPtr> data;
237+
rclcpp::MessageInfo message_info;
238+
for (;;) {
239+
auto datum = std::make_shared<MessageT>();
240+
if (subscriber->take(*datum, message_info)) {
241+
data.push_back(datum);
242+
} else {
243+
break;
244+
}
245+
}
246+
return data;
247+
}
248+
249+
} // namespace polling_policy
250+
251+
} // namespace autoware::universe_utils
252+
253+
#endif // AUTOWARE__UNIVERSE_UTILS__ROS__POLLING_SUBSCRIBER_HPP_

common/tier4_autoware_utils/include/tier4_autoware_utils/tier4_autoware_utils.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "tier4_autoware_utils/ros/debug_publisher.hpp"
2828
#include "tier4_autoware_utils/ros/debug_traits.hpp"
2929
#include "tier4_autoware_utils/ros/marker_helper.hpp"
30+
#include "tier4_autoware_utils/ros/polling_subscriber.hpp"
3031
#include "tier4_autoware_utils/ros/processing_time_publisher.hpp"
3132
#include "tier4_autoware_utils/ros/self_pose_listener.hpp"
3233
#include "tier4_autoware_utils/ros/transform_listener.hpp"

control/autoware_autonomous_emergency_braking/CMakeLists.txt

+5-5
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ rclcpp_components_register_node(${AEB_NODE}
2929
EXECUTABLE ${PROJECT_NAME}
3030
)
3131

32-
if(BUILD_TESTING)
33-
ament_add_ros_isolated_gtest(test_aeb
34-
test/test.cpp)
32+
# if(BUILD_TESTING)
33+
# ament_add_ros_isolated_gtest(test_aeb
34+
# test/test.cpp)
3535

36-
target_link_libraries(test_aeb ${AEB_NODE})
36+
# target_link_libraries(test_aeb ${AEB_NODE})
3737

38-
endif()
38+
# endif()
3939

4040
ament_auto_package(
4141
INSTALL_TO_SHARE

control/autoware_autonomous_emergency_braking/include/autoware/autonomous_emergency_braking/node.hpp

+14-17
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,21 @@
1515
#ifndef AUTOWARE__AUTONOMOUS_EMERGENCY_BRAKING__NODE_HPP_
1616
#define AUTOWARE__AUTONOMOUS_EMERGENCY_BRAKING__NODE_HPP_
1717

18-
#include <autoware/motion_utils/trajectory/trajectory.hpp>
19-
#include <autoware/universe_utils/geometry/geometry.hpp>
20-
#include <autoware/universe_utils/ros/polling_subscriber.hpp>
21-
#include <autoware_vehicle_info_utils/vehicle_info_utils.hpp>
2218
#include <diagnostic_updater/diagnostic_updater.hpp>
2319
#include <pcl_ros/transforms.hpp>
2420
#include <rclcpp/rclcpp.hpp>
21+
#include <tier4_autoware_utils/tier4_autoware_utils.hpp>
22+
#include <vehicle_info_util/vehicle_info_util.hpp>
2523

26-
#include <autoware_perception_msgs/msg/predicted_objects.hpp>
27-
#include <autoware_planning_msgs/msg/trajectory.hpp>
28-
#include <autoware_system_msgs/msg/autoware_state.hpp>
29-
#include <autoware_vehicle_msgs/msg/velocity_report.hpp>
24+
#include <autoware_auto_perception_msgs/msg/predicted_objects.hpp>
25+
#include <autoware_auto_planning_msgs/msg/trajectory.hpp>
26+
#include <autoware_auto_system_msgs/msg/autoware_state.hpp>
27+
#include <autoware_auto_vehicle_msgs/msg/velocity_report.hpp>
3028
#include <geometry_msgs/msg/vector3.hpp>
3129
#include <nav_msgs/msg/odometry.hpp>
3230
#include <sensor_msgs/msg/imu.hpp>
3331
#include <sensor_msgs/msg/point_cloud2.hpp>
3432
#include <visualization_msgs/msg/marker.hpp>
35-
#include <visualization_msgs/msg/marker_array.hpp>
3633

3734
#include <boost/optional.hpp>
3835

@@ -53,23 +50,23 @@
5350
namespace autoware::motion::control::autonomous_emergency_braking
5451
{
5552

56-
using autoware_planning_msgs::msg::Trajectory;
57-
using autoware_system_msgs::msg::AutowareState;
58-
using autoware_vehicle_msgs::msg::VelocityReport;
53+
using autoware_auto_planning_msgs::msg::Trajectory;
54+
using autoware_auto_system_msgs::msg::AutowareState;
55+
using autoware_auto_vehicle_msgs::msg::VelocityReport;
5956
using nav_msgs::msg::Odometry;
6057
using sensor_msgs::msg::Imu;
6158
using sensor_msgs::msg::PointCloud2;
6259
using PointCloud = pcl::PointCloud<pcl::PointXYZ>;
63-
using autoware::universe_utils::Polygon2d;
64-
using autoware::vehicle_info_utils::VehicleInfo;
6560
using diagnostic_updater::DiagnosticStatusWrapper;
6661
using diagnostic_updater::Updater;
62+
using tier4_autoware_utils::Polygon2d;
63+
using vehicle_info_util::VehicleInfo;
6764
using visualization_msgs::msg::Marker;
6865
using visualization_msgs::msg::MarkerArray;
6966
using Path = std::vector<geometry_msgs::msg::Pose>;
7067
using Vector3 = geometry_msgs::msg::Vector3;
71-
using autoware_perception_msgs::msg::PredictedObject;
72-
using autoware_perception_msgs::msg::PredictedObjects;
68+
using autoware_auto_perception_msgs::msg::PredictedObject;
69+
using autoware_auto_perception_msgs::msg::PredictedObjects;
7370

7471
/**
7572
* @brief Struct to store object data
@@ -276,7 +273,7 @@ class CollisionDataKeeper
276273
const double p_vel = p_dist / p_dt;
277274

278275
const auto nearest_idx =
279-
autoware::motion_utils::findNearestIndex(path, nearest_collision_point);
276+
tier4_autoware_utils::findNearestIndex(path, nearest_collision_point);
280277
const auto & nearest_path_pose = path.at(nearest_idx);
281278
// When the ego moves backwards, the direction of movement axis is reversed
282279
const auto & traj_yaw = (current_ego_speed > 0.0)

0 commit comments

Comments
 (0)