Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
collision_detection.hpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2022 LEIDOS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
17#include <carma_perception_msgs/msg/roadway_obstacle_list.hpp>
18#include <carma_perception_msgs/msg/roadway_obstacle.hpp>
19#include <carma_v2x_msgs/msg/vehicle_size.hpp>
20#include <carma_planning_msgs/msg/trajectory_plan.hpp>
21#include <geometry_msgs/msg/vector3.hpp>
22
23#include <boost/geometry.hpp>
24#include <boost/geometry/geometries/point_xy.hpp>
25#include <boost/foreach.hpp>
26#include <vector>
27#include <boost/assign/std/vector.hpp>
28
29#include <iostream>
30#include <fstream>
31
32#include <carma_wm/Geometry.hpp>
33#include <tf2/LinearMath/Transform.h>
34#include <tf2_geometry_msgs/tf2_geometry_msgs.h>
35
36#include <rclcpp/rclcpp.hpp>
37
38namespace carma_wm {
39
40 namespace collision_detection {
41
42 typedef boost::geometry::model::point<double, 2, boost::geometry::cs::cartesian> point_t;
43 typedef boost::geometry::model::polygon<point_t> polygon_t;
44
45 //TODO: verify correctness of descriptions for each of these elements
46 struct MovingObject {
47 polygon_t object_polygon; //current exterior outline of the object in the x-y plane
48 geometry_msgs::msg::Vector3 linear_velocity;//current velocity vector of the object's centroid, m/s
49 std::vector<std::tuple <__uint64_t, polygon_t>> fp; //zero or more predicted future outline polygons; each
50 // element is (t, polygon), where t is time in future, ms
51 };
52
66 std::vector<carma_perception_msgs::msg::RoadwayObstacle> WorldCollisionDetection(const carma_perception_msgs::msg::RoadwayObstacleList& rwol,
67 const carma_planning_msgs::msg::TrajectoryPlan& tp, const geometry_msgs::msg::Vector3& size,
68 const geometry_msgs::msg::Twist& velocity);
69
74 collision_detection::MovingObject ConvertRoadwayObstacleToMovingObject(const carma_perception_msgs::msg::RoadwayObstacle& rwo);
75
82 collision_detection::MovingObject ConvertVehicleToMovingObject(const carma_planning_msgs::msg::TrajectoryPlan& tp, const geometry_msgs::msg::Vector3& size, const geometry_msgs::msg::Twist& veloctiy);
83
91
96
100 bool DetectCollision(collision_detection::MovingObject const &ob_1, collision_detection::MovingObject const &ob_2, __uint64_t target_time);
101
105 template <class P>
106 P ObjectToBoostPolygon(const geometry_msgs::msg::Pose& pose, const geometry_msgs::msg::Vector3& size);
107 }
108}
bool DetectCollision(collision_detection::MovingObject const &ob_1, collision_detection::MovingObject const &ob_2, __uint64_t target_time)
.function is used in WorldCollisionDetection to detection collision between two Moving Object
boost::geometry::model::polygon< point_t > polygon_t
collision_detection::MovingObject ConvertVehicleToMovingObject(const carma_planning_msgs::msg::TrajectoryPlan &tp, const geometry_msgs::msg::Vector3 &size, const geometry_msgs::msg::Twist &veloctiy)
Creates collision_detection::MovingObject for the host vehicle using the veloctiy,...
boost::geometry::model::point< double, 2, boost::geometry::cs::cartesian > point_t
collision_detection::MovingObject ConvertRoadwayObstacleToMovingObject(const carma_perception_msgs::msg::RoadwayObstacle &rwo)
Convert RodwayObstable object to the collision_detection::MovingObject.
bool CheckPolygonIntersection(collision_detection::MovingObject const &ob_1, collision_detection::MovingObject const &ob_2)
.check Intersection between polygons
collision_detection::MovingObject PredictObjectPosition(collision_detection::MovingObject const &op, __uint64_t target_time)
.function is to create a monving object with a polygon that represents area that object is going to a...
std::vector< carma_perception_msgs::msg::RoadwayObstacle > WorldCollisionDetection(const carma_perception_msgs::msg::RoadwayObstacleList &rwol, const carma_planning_msgs::msg::TrajectoryPlan &tp, const geometry_msgs::msg::Vector3 &size, const geometry_msgs::msg::Twist &velocity)
Main collision detection function to be called when needed to check for collision detection of the ve...
P ObjectToBoostPolygon(const geometry_msgs::msg::Pose &pose, const geometry_msgs::msg::Vector3 &size)
function to create a polygon representing and object
std::vector< std::tuple< __uint64_t, polygon_t > > fp