2024-06-12 22:51:59 +00:00
|
|
|
#ifndef CAM_APPLICATION_HPP_EUIC2VFR
|
|
|
|
#define CAM_APPLICATION_HPP_EUIC2VFR
|
|
|
|
|
|
|
|
#include "autoware_v2x/application.hpp"
|
2024-10-28 10:19:01 +00:00
|
|
|
#include "autoware_v2x/positioning.hpp"
|
2024-06-12 22:51:59 +00:00
|
|
|
#include "rclcpp/rclcpp.hpp"
|
2024-10-28 10:19:01 +00:00
|
|
|
|
|
|
|
#include <vanetza/asn1/cam.hpp>
|
|
|
|
|
|
|
|
#include "autoware_adapi_v1_msgs/msg/vehicle_dimensions.hpp"
|
2024-09-09 14:41:54 +00:00
|
|
|
#include "autoware_auto_vehicle_msgs/msg/gear_report.hpp"
|
|
|
|
#include "autoware_auto_vehicle_msgs/msg/steering_report.hpp"
|
2024-10-28 10:19:01 +00:00
|
|
|
#include "autoware_auto_vehicle_msgs/msg/velocity_report.hpp"
|
|
|
|
|
|
|
|
#include <boost/asio/io_service.hpp>
|
|
|
|
#include <boost/asio/steady_timer.hpp>
|
|
|
|
|
|
|
|
#include <etsi_its_cam_ts_coding/cam_ts_CAM.h>
|
2024-06-12 22:51:59 +00:00
|
|
|
|
|
|
|
namespace v2x
|
|
|
|
{
|
|
|
|
class V2XNode;
|
|
|
|
class CamApplication : public Application
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
CamApplication(V2XNode *node, vanetza::Runtime &, bool is_sender);
|
|
|
|
PortType port() override;
|
|
|
|
void indicate(const DataIndication &, UpPacketPtr) override;
|
|
|
|
void set_interval(vanetza::Clock::duration);
|
|
|
|
void updateMGRS(double *, double *);
|
2024-10-11 14:43:11 +00:00
|
|
|
void updateRP(const double *, const double *, const double *);
|
|
|
|
void updateHeading(const double *);
|
2024-07-08 10:08:49 +00:00
|
|
|
void setVehicleDimensions(const autoware_adapi_v1_msgs::msg::VehicleDimensions &);
|
|
|
|
void updateVelocityReport(const autoware_auto_vehicle_msgs::msg::VelocityReport::ConstSharedPtr);
|
2024-09-09 14:41:54 +00:00
|
|
|
void updateGearReport(const autoware_auto_vehicle_msgs::msg::GearReport::ConstSharedPtr);
|
|
|
|
void updateSteeringReport(const autoware_auto_vehicle_msgs::msg::SteeringReport::ConstSharedPtr);
|
2024-06-12 22:51:59 +00:00
|
|
|
void send();
|
|
|
|
|
|
|
|
private:
|
2024-10-11 14:43:11 +00:00
|
|
|
void calc_interval();
|
2024-06-12 22:51:59 +00:00
|
|
|
void schedule_timer();
|
|
|
|
void on_timer(vanetza::Clock::time_point);
|
2024-10-28 10:19:01 +00:00
|
|
|
static void build_etsi_its_cam_ts_from_vanetza(vanetza::asn1::Cam &, cam_ts_CAM_t &);
|
2024-06-12 22:51:59 +00:00
|
|
|
|
|
|
|
V2XNode *node_;
|
|
|
|
vanetza::Runtime &runtime_;
|
2024-09-04 15:18:20 +00:00
|
|
|
vanetza::Clock::duration cam_interval_{};
|
2024-06-12 22:51:59 +00:00
|
|
|
|
|
|
|
struct VehicleDimensions {
|
2024-09-10 11:22:40 +00:00
|
|
|
float wheel_radius = 0.0;
|
|
|
|
float wheel_width = 0.0;
|
|
|
|
float wheel_base = 0.0;
|
|
|
|
float wheel_tread = 0.0;
|
|
|
|
float front_overhang = 0.0;
|
|
|
|
float rear_overhang = 0.0;
|
|
|
|
float left_overhang = 0.0;
|
|
|
|
float right_overhang = 0.0;
|
|
|
|
float height = 0.0;
|
2024-06-12 22:51:59 +00:00
|
|
|
};
|
|
|
|
VehicleDimensions vehicleDimensions_;
|
|
|
|
|
|
|
|
struct Ego_station {
|
|
|
|
double mgrs_x;
|
|
|
|
double mgrs_y;
|
|
|
|
double latitude;
|
|
|
|
double longitude;
|
|
|
|
double altitude;
|
|
|
|
double heading;
|
|
|
|
};
|
|
|
|
Ego_station ego_;
|
|
|
|
|
2024-07-03 13:31:27 +00:00
|
|
|
class PositionsDeque {
|
|
|
|
public:
|
|
|
|
void insert(double value) {
|
|
|
|
if (deque.size() >= maxSize) {
|
|
|
|
total -= deque.front();
|
|
|
|
deque.pop_front();
|
|
|
|
}
|
|
|
|
total += value;
|
|
|
|
mean = total / deque.size();
|
|
|
|
deque.push_back(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
int getSize() {
|
|
|
|
return deque.size();
|
|
|
|
}
|
|
|
|
|
2024-09-04 15:18:20 +00:00
|
|
|
[[nodiscard]] double getMean() const {
|
2024-07-03 13:31:27 +00:00
|
|
|
return this->mean;
|
|
|
|
}
|
|
|
|
|
|
|
|
using iterator = std::deque<double>::const_iterator;
|
|
|
|
|
2024-09-04 15:18:20 +00:00
|
|
|
[[nodiscard]] iterator begin() const {
|
2024-07-03 13:31:27 +00:00
|
|
|
return deque.begin();
|
|
|
|
}
|
|
|
|
|
2024-09-04 15:18:20 +00:00
|
|
|
[[nodiscard]] iterator end() const {
|
2024-07-03 13:31:27 +00:00
|
|
|
return deque.end();
|
|
|
|
}
|
|
|
|
|
|
|
|
double operator[](std::size_t index) const {
|
|
|
|
if (index >= deque.size())
|
|
|
|
throw std::out_of_range("[PositionDeque] Index out of range");
|
|
|
|
return deque[index];
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const std::size_t maxSize = 5;
|
|
|
|
std::deque<double> deque;
|
|
|
|
|
|
|
|
double total = 0;
|
|
|
|
double mean = 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PositionConfidenceEllipse {
|
|
|
|
PositionsDeque x;
|
|
|
|
PositionsDeque y;
|
|
|
|
|
2024-09-04 15:18:20 +00:00
|
|
|
double semiMajorConfidence{};
|
|
|
|
double semiMinorConfidence{};
|
|
|
|
double semiMajorOrientation{};
|
2024-07-03 13:31:27 +00:00
|
|
|
};
|
|
|
|
PositionConfidenceEllipse positionConfidenceEllipse_;
|
|
|
|
|
2024-06-12 22:51:59 +00:00
|
|
|
struct VelocityReport {
|
|
|
|
rclcpp::Time stamp;
|
|
|
|
float heading_rate;
|
|
|
|
float lateral_velocity;
|
|
|
|
float longitudinal_velocity;
|
2024-10-11 14:43:11 +00:00
|
|
|
float speed;
|
2024-06-12 22:51:59 +00:00
|
|
|
float longitudinal_acceleration;
|
|
|
|
};
|
|
|
|
VelocityReport velocityReport_;
|
2024-06-28 13:11:04 +00:00
|
|
|
|
2024-07-09 13:54:53 +00:00
|
|
|
struct VehicleStatus {
|
|
|
|
uint8_t gear;
|
2024-06-28 13:11:04 +00:00
|
|
|
float steering_tire_angle;
|
|
|
|
};
|
2024-07-09 13:54:53 +00:00
|
|
|
VehicleStatus vehicleStatus_;
|
2024-06-28 13:11:04 +00:00
|
|
|
|
2024-06-12 22:51:59 +00:00
|
|
|
bool sending_;
|
|
|
|
bool is_sender_;
|
|
|
|
|
2024-07-12 11:58:48 +00:00
|
|
|
unsigned long stationId_;
|
2024-06-12 22:51:59 +00:00
|
|
|
|
|
|
|
bool use_dynamic_generation_rules_;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CAM_APPLICATION_HPP_EUIC2VFR */
|