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.
bsm_generator::BSMGeneratorWorker Class Reference

The class containing the primary business logic for the BSM Generator Package. More...

#include <bsm_generator_worker.hpp>

Collaboration diagram for bsm_generator::BSMGeneratorWorker:
Collaboration graph

Public Member Functions

 BSMGeneratorWorker ()
 Default Constructor for BSMGeneratorWorker. More...
 
uint8_t getNextMsgCount ()
 Function to increment the BSM message counter and obtain the new counter value. Counter restarts at 0 once it reaches a value of 128. More...
 
std::vector< uint8_t > getMsgId (const rclcpp::Time now, double secs)
 Function to obtain the current BSM message ID. The ID is updated to a new random BSM message ID every 5 minutes. More...
 
uint16_t getSecMark (const rclcpp::Time now)
 Function to obtain the 'milliseconds' mark of the provided time within the last minute. More...
 
float getSpeedInRange (const double speed)
 Function to apply minimum and maximum limits to a speed value. Minimum limit is 0.0, and maximum limit is 163.8. More...
 
float getSteerWheelAngleInRange (const double angle)
 Function to apply minimum and maximum limits to a steering wheel angle value. Minimum limit is -189.0, maximum limit is 189.0. More...
 
float getLongAccelInRange (const float accel)
 Function to apply minimum and maximum limits to a longitudinal acceleration value. Minimum limit is -20.0, maximum limit is 20.0. More...
 
float getYawRateInRange (const double yaw_rate)
 Function to apply minimum and maximum limits to a yaw rate value. Minimum limit is -327.67, maximum limit is 327.67. More...
 
uint8_t getBrakeAppliedStatus (const double brake)
 Function to convert the current applied brake status to a value used within the BSM message. More...
 
float getHeadingInRange (const float heading)
 Function to apply minimum and maximum limits to a vehicle heading value. Minimum limit is 0.0, maximum limit is 359.9875. More...
 

Private Attributes

std::default_random_engine generator_
 
uint8_t msg_count_ {0}
 
int random_id_ {0}
 
rclcpp::Time last_id_generation_time_
 
bool first_msg_id_ = true
 

Detailed Description

The class containing the primary business logic for the BSM Generator Package.

Definition at line 32 of file bsm_generator_worker.hpp.

Constructor & Destructor Documentation

◆ BSMGeneratorWorker()

bsm_generator::BSMGeneratorWorker::BSMGeneratorWorker ( )

Default Constructor for BSMGeneratorWorker.

Definition at line 23 of file bsm_generator_worker.cpp.

23{}

Member Function Documentation

◆ getBrakeAppliedStatus()

uint8_t bsm_generator::BSMGeneratorWorker::getBrakeAppliedStatus ( const double  brake)

Function to convert the current applied brake status to a value used within the BSM message.

Parameters
brakeThe current applied brake status
Returns
Converted brake status value

Definition at line 91 of file bsm_generator_worker.cpp.

92 {
93 return brake >= 0.05 ? 0b1111 : 0;
94 }

◆ getHeadingInRange()

float bsm_generator::BSMGeneratorWorker::getHeadingInRange ( const float  heading)

Function to apply minimum and maximum limits to a vehicle heading value. Minimum limit is 0.0, maximum limit is 359.9875.

Parameters
headingThe current vehicle heading value
Returns
Vehicle heading value (minimum limit is 0.0, maximum limit is 359.9875)

Definition at line 96 of file bsm_generator_worker.cpp.

97 {
98 return std::max(std::min(heading, 359.9875f), 0.0f);
99 }

◆ getLongAccelInRange()

float bsm_generator::BSMGeneratorWorker::getLongAccelInRange ( const float  accel)

Function to apply minimum and maximum limits to a longitudinal acceleration value. Minimum limit is -20.0, maximum limit is 20.0.

Parameters
accelThe current longitudinal acceleration value
Returns
Longitudinal acceleration value (minimum limit is -20.0, maximum limit is 20.0)

Definition at line 81 of file bsm_generator_worker.cpp.

82 {
83 return std::max(std::min(accel, 20.0f), -20.0f);
84 }

◆ getMsgId()

std::vector< uint8_t > bsm_generator::BSMGeneratorWorker::getMsgId ( const rclcpp::Time  now,
double  secs 
)

Function to obtain the current BSM message ID. The ID is updated to a new random BSM message ID every 5 minutes.

Parameters
nowThe current time
secsId change period in sec
Returns
The current BSM message ID

Definition at line 36 of file bsm_generator_worker.cpp.

37 {
38 // need to change ID every designated period
39 rclcpp::Duration id_timeout(secs * 1e9);
40
41 generator_.seed(std::random_device{}()); // guarantee randomness
42 std::uniform_int_distribution<int> dis(0,INT_MAX);
43
44 std::vector<uint8_t> id(4);
45
46 if (first_msg_id_) {
48 first_msg_id_ = false;
50 }
51
52 if(now - last_id_generation_time_ >= id_timeout)
53 {
55 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("bsm_generator"), "Newly generated random id: " << random_id_);
57 }
58
59 for(int i = 0; i < id.size(); ++i)
60 {
61 id[i] = random_id_ >> (8 * i);
62 }
63 return id;
64 }
std::default_random_engine generator_

References first_msg_id_, generator_, process_bag::i, last_id_generation_time_, and random_id_.

◆ getNextMsgCount()

uint8_t bsm_generator::BSMGeneratorWorker::getNextMsgCount ( )

Function to increment the BSM message counter and obtain the new counter value. Counter restarts at 0 once it reaches a value of 128.

Returns
The updated BSM message counter value

Definition at line 25 of file bsm_generator_worker.cpp.

26 {
27 uint8_t old_msg_count = msg_count_;
28 msg_count_++;
29 if(msg_count_ == 128)
30 {
31 msg_count_ = 0;
32 }
33 return old_msg_count;
34 }

References msg_count_.

◆ getSecMark()

uint16_t bsm_generator::BSMGeneratorWorker::getSecMark ( const rclcpp::Time  now)

Function to obtain the 'milliseconds' mark of the provided time within the last minute.

Parameters
nowThe current time
Returns
The 'milliseconds' mark of the provided time within the last minute

Definition at line 66 of file bsm_generator_worker.cpp.

67 {
68 return static_cast<uint16_t>((now.nanoseconds() / 1000000) % 60000);
69 }

◆ getSpeedInRange()

float bsm_generator::BSMGeneratorWorker::getSpeedInRange ( const double  speed)

Function to apply minimum and maximum limits to a speed value. Minimum limit is 0.0, and maximum limit is 163.8.

Parameters
speedThe current vehicle speed
Returns
Speed value (minimum limit is 0.0, maximum limit is 163.8)

Definition at line 71 of file bsm_generator_worker.cpp.

72 {
73 return static_cast<float>(std::max(std::min(speed, 163.8), 0.0));
74 }

◆ getSteerWheelAngleInRange()

float bsm_generator::BSMGeneratorWorker::getSteerWheelAngleInRange ( const double  angle)

Function to apply minimum and maximum limits to a steering wheel angle value. Minimum limit is -189.0, maximum limit is 189.0.

Parameters
angleThe current steering wheel angle
Returns
Steering wheel angle value (minimum limit is -189.0, maximum limit is 189.0)

Definition at line 76 of file bsm_generator_worker.cpp.

77 {
78 return static_cast<float>(std::max(std::min(angle * 57.2958, 189.0), -189.0));
79 }

◆ getYawRateInRange()

float bsm_generator::BSMGeneratorWorker::getYawRateInRange ( const double  yaw_rate)

Function to apply minimum and maximum limits to a yaw rate value. Minimum limit is -327.67, maximum limit is 327.67.

Parameters
yaw_rateThe current yaw rate value
Returns
Yaw Rate value (minimum limit is -327.67, maximum limit is 327.67)

Definition at line 86 of file bsm_generator_worker.cpp.

87 {
88 return static_cast<float>(std::max(std::min(yaw_rate, 327.67), -327.67));
89 }

Member Data Documentation

◆ first_msg_id_

bool bsm_generator::BSMGeneratorWorker::first_msg_id_ = true
private

Definition at line 126 of file bsm_generator_worker.hpp.

Referenced by getMsgId().

◆ generator_

std::default_random_engine bsm_generator::BSMGeneratorWorker::generator_
private

Definition at line 113 of file bsm_generator_worker.hpp.

Referenced by getMsgId().

◆ last_id_generation_time_

rclcpp::Time bsm_generator::BSMGeneratorWorker::last_id_generation_time_
private

Definition at line 122 of file bsm_generator_worker.hpp.

Referenced by getMsgId().

◆ msg_count_

uint8_t bsm_generator::BSMGeneratorWorker::msg_count_ {0}
private

Definition at line 116 of file bsm_generator_worker.hpp.

Referenced by getNextMsgCount().

◆ random_id_

int bsm_generator::BSMGeneratorWorker::random_id_ {0}
private

Definition at line 119 of file bsm_generator_worker.hpp.

Referenced by getMsgId().


The documentation for this class was generated from the following files: