17#include <tf2_ros/transform_listener.h>
18#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
19#include <tf2/LinearMath/Quaternion.h>
20#include <tf2/transform_datatypes.h>
21#include <tf2_ros/transform_listener.h>
22#include <tf2_eigen/tf2_eigen.h>
29 : obj_pub_(obj_pub), tf_lookup_(tf_lookup), logger_(logger) {}
33 return obj.classification.end() != std::find_if(obj.classification.begin(), obj.classification.end(),
34 [&class_id](
auto o){ return o.classification == class_id; }
42 carma_perception_msgs::msg::ExternalObjectList msg;
43 msg.header = obj_array->header;
50 RCLCPP_WARN_STREAM(
logger_->get_logger(),
"Ignoring fix message: Could not locate static transforms exception.");
54 geometry_msgs::msg::TransformStamped object_frame_tf = transform.get();
56 for (
size_t i = 0;
i < obj_array->objects.size();
i++)
58 carma_perception_msgs::msg::ExternalObject obj;
61 obj.header = msg.header;
66 obj.presence_vector = obj.presence_vector | obj.ID_PRESENCE_VECTOR;
67 obj.presence_vector = obj.presence_vector | obj.POSE_PRESENCE_VECTOR;
68 obj.presence_vector = obj.presence_vector | obj.VELOCITY_PRESENCE_VECTOR;
69 obj.presence_vector = obj.presence_vector | obj.SIZE_PRESENCE_VECTOR;
70 obj.presence_vector = obj.presence_vector | obj.OBJECT_TYPE_PRESENCE_VECTOR;
71 obj.presence_vector = obj.presence_vector | obj.DYNAMIC_OBJ_PRESENCE;
72 obj.presence_vector = obj.presence_vector | obj.CONFIDENCE_PRESENCE_VECTOR;
75 obj.id = obj_array->objects[
i].object_id;
78 geometry_msgs::msg::PoseStamped input_object_pose;
79 input_object_pose.header = obj_array->header;
80 input_object_pose.pose.position = obj_array->objects[
i].kinematics.centroid_position;
81 input_object_pose.pose.orientation = obj_array->objects[
i].kinematics.orientation;
83 geometry_msgs::msg::PoseStamped output_pose;
85 tf2::doTransform(input_object_pose, output_pose, object_frame_tf);
87 obj.pose.pose = output_pose.pose;
92 auto xx = obj_array->objects[
i].kinematics.position_covariance[0];
93 auto xy = obj_array->objects[
i].kinematics.position_covariance[1];
94 auto xz = obj_array->objects[
i].kinematics.position_covariance[2];
95 auto yx = obj_array->objects[
i].kinematics.position_covariance[3];
96 auto yy = obj_array->objects[
i].kinematics.position_covariance[4];
97 auto yz = obj_array->objects[
i].kinematics.position_covariance[5];
98 auto zx = obj_array->objects[
i].kinematics.position_covariance[6];
99 auto zy = obj_array->objects[
i].kinematics.position_covariance[7];
100 auto zz = obj_array->objects[
i].kinematics.position_covariance[8];
103 std::array<double, 36> input_covariance = {
113 tf2::Transform covariance_transform;
114 tf2::fromMsg(object_frame_tf.transform, covariance_transform);
118 obj.confidence = obj_array->objects[
i].existence_probability;
121 obj.velocity = obj_array->objects[
i].kinematics.twist;
128 double minX = std::numeric_limits<double>::max();
129 double maxX = std::numeric_limits<double>::lowest();
130 double minY = std::numeric_limits<double>::max();
131 double maxY = std::numeric_limits<double>::lowest();
132 double maxHeight = std::numeric_limits<double>::lowest();
134 for(
auto shape : obj_array->objects[
i].shape) {
135 for (
auto point : shape.polygon.points) {
149 if (shape.height > maxHeight)
150 maxHeight = shape.height;
153 double dX = maxX - minX;
154 double dY = maxY - minY;
156 obj.size.x = dX / 2.0;
157 obj.size.y = dY / 2.0;
160 obj.size.z = maxHeight / 2.0;
165 if (
isClass(obj_array->objects[
i], autoware_auto_msgs::msg::ObjectClassification::MOTORCYCLE))
167 obj.object_type = obj.MOTORCYCLE;
169 else if (
isClass(obj_array->objects[
i], autoware_auto_msgs::msg::ObjectClassification::BICYCLE))
171 obj.object_type = obj.MOTORCYCLE;
173 else if (
isClass(obj_array->objects[
i], autoware_auto_msgs::msg::ObjectClassification::CAR))
175 obj.object_type = obj.SMALL_VEHICLE;
177 else if (
isClass(obj_array->objects[
i], autoware_auto_msgs::msg::ObjectClassification::TRUCK))
179 obj.object_type = obj.LARGE_VEHICLE;
181 else if (
isClass(obj_array->objects[
i], autoware_auto_msgs::msg::ObjectClassification::TRAILER))
183 obj.object_type = obj.LARGE_VEHICLE;
185 else if (
isClass(obj_array->objects[
i], autoware_auto_msgs::msg::ObjectClassification::PEDESTRIAN))
187 obj.object_type = obj.PEDESTRIAN;
191 obj.object_type = obj.UNKNOWN;
196 if ((fabs(obj.velocity.twist.linear.x || obj.velocity.twist.linear.y || obj.velocity.twist.linear.z)) > 0.75)
205 msg.objects.emplace_back(obj);
PublishObjectCallback obj_pub_
ObjectDetectionTrackingWorker(PublishObjectCallback obj_pub, TransformLookupCallback tf_lookup, rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger)
Constructor.
bool isClass(const autoware_auto_msgs::msg::TrackedObject &obj, uint8_t class_id)
Helper method to check if the provided tracked object has the provided class type.
void detectedObjectCallback(autoware_auto_msgs::msg::TrackedObjects::UniquePtr msg)
detectedObjectCallback populates detected object along with its velocity,yaw, yaw_rate and static/dyn...
rclcpp::node_interfaces::NodeLoggingInterface::SharedPtr logger_
void setMapFrame(std::string map_frame)
std::function< void(const carma_perception_msgs::msg::ExternalObjectList &)> PublishObjectCallback
std::function< boost::optional< geometry_msgs::msg::TransformStamped >(const std::string &, const std::string &, const rclcpp::Time &stamp)> TransformLookupCallback
TransformLookupCallback tf_lookup_
geometry_msgs::msg::PoseWithCovariance::_covariance_type transformCovariance(const geometry_msgs::msg::PoseWithCovariance::_covariance_type &cov_in, const tf2::Transform &transform)
Transform the covariance matrix of a PoseWithCovariance message to a new frame.