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.
carma_wm_ctrl::GeofenceSchedule Class Reference

#include <GeofenceSchedule.hpp>

Collaboration diagram for carma_wm_ctrl::GeofenceSchedule:
Collaboration graph

Public Types

using DayOfTheWeekSet = std::unordered_set< boost::gregorian::greg_weekday, std::hash< int > >
 

Public Member Functions

 GeofenceSchedule ()
 Default Constructor does not initialize any members. More...
 
 GeofenceSchedule (rclcpp::Time schedule_start, rclcpp::Time schedule_end, rclcpp::Duration control_start, rclcpp::Duration control_duration, rclcpp::Duration control_offset, rclcpp::Duration control_span, rclcpp::Duration control_period, DayOfTheWeekSet week_day_set={ 0, 1, 2, 3, 4, 5, 6 })
 Constructor. More...
 
bool scheduleExpired (const rclcpp::Time &time) const
 Returns true if the schedule has expired by the provided time. More...
 
bool scheduleStarted (const rclcpp::Time &time) const
 Returns true if the schedule has started by the provided time. More...
 
std::pair< bool, rclcpp::Time > getNextInterval (const rclcpp::Time &time) const
 Returns the start time of the next active interval defined by this schedule. More...
 

Public Attributes

rclcpp::Time schedule_start_
 
rclcpp::Time schedule_end_
 
rclcpp::Duration control_start_ {0, 0}
 
rclcpp::Duration control_duration_ {0, 0}
 
rclcpp::Duration control_offset_ {0, 0}
 
rclcpp::Duration control_span_ {0, 0}
 
rclcpp::Duration control_period_ {0, 0}
 
DayOfTheWeekSet week_day_set_
 

Detailed Description

Definition at line 26 of file GeofenceSchedule.hpp.

Member Typedef Documentation

◆ DayOfTheWeekSet

using carma_wm_ctrl::GeofenceSchedule::DayOfTheWeekSet = std::unordered_set<boost::gregorian::greg_weekday, std::hash<int> >

Definition at line 38 of file GeofenceSchedule.hpp.

Constructor & Destructor Documentation

◆ GeofenceSchedule() [1/2]

carma_wm_ctrl::GeofenceSchedule::GeofenceSchedule ( )

Default Constructor does not initialize any members.

Definition at line 22 of file GeofenceSchedule.cpp.

23{
24}

◆ GeofenceSchedule() [2/2]

carma_wm_ctrl::GeofenceSchedule::GeofenceSchedule ( rclcpp::Time  schedule_start,
rclcpp::Time  schedule_end,
rclcpp::Duration  control_start,
rclcpp::Duration  control_duration,
rclcpp::Duration  control_offset,
rclcpp::Duration  control_span,
rclcpp::Duration  control_period,
DayOfTheWeekSet  week_day_set = { 0, 1, 2, 3, 4, 5, 6 } 
)

Constructor.

Parameters
schedule_startOverall schedule start in UTC
schedule_endOverall schedule end in UTC
control_startDuration from start of day
control_durationDuration from start of control_start
control_offsetDuration from start of day (specifies start time for repeat parameters - span, period)
control_spanDuration of active status. Starts from offset
control_periodInterval between active status within control_duration since control_start
week_day_setSet of days of the week which this schedule applies to. Defaults as all days of the week

Definition at line 26 of file GeofenceSchedule.cpp.

28 :
29 schedule_start_(schedule_start), schedule_end_(schedule_end),
30 control_start_ (control_start), control_duration_ (control_duration),
31 control_offset_ (control_offset), control_span_ (control_span), control_period_ (control_period), week_day_set_(week_day_set)
32{}

Member Function Documentation

◆ getNextInterval()

std::pair< bool, rclcpp::Time > carma_wm_ctrl::GeofenceSchedule::getNextInterval ( const rclcpp::Time &  time) const

Returns the start time of the next active interval defined by this schedule.

Parameters
timeUTC time to compare
Returns
Returns a pair with the following semantics First Element: A boolean indicating if the provided time is within a currently active control period Second Element: The start time of the next scheduled active control interval within the current day. Returns rclcpp::Time(0) when the schedule is expired or the next interval will be on a different day of the week or after schedule end

TODO the UTC offset is provided in the geofence spec but for now we will ignore and assume all times are UTC

Definition at line 46 of file GeofenceSchedule.cpp.

47{
48 auto clock_type = time.get_clock_type();
49 if (scheduleExpired(time))
50 {
51 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("carma_wm_ctrl"), "Geofence schedule expired");
52 return std::make_pair(false, rclcpp::Time(0, 0, clock_type)); // If the schedule has expired or was never started
53 }
54
55 boost::posix_time::ptime boost_time = boost::posix_time::from_time_t(time.seconds());
56 boost_time += boost::posix_time::microseconds((int)((time.seconds()-std::floor(time.seconds()))*1e6));
57 boost::gregorian::date date = boost_time.date();
58
59 if (week_day_set_.find(date.day_of_week()) == week_day_set_.end())
60 {
61 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("carma_wm_ctrl"), "Geofence wrong day of the week");
62 return std::make_pair(false, rclcpp::Time(0, 0, clock_type)); // This geofence is not active on this day
63 }
64
65 auto time_of_day = boost_time.time_of_day();
66
67
68 // Convert schedule into workable components
69 boost::posix_time::ptime ptime_start_of_day(date, boost::posix_time::hours(0)); // Get absolute start time of the day
70
71 rclcpp::Time ros_time_of_day = rclcpp::Time(lanelet::time::toSec(time_of_day) * 1e9, clock_type);
72
73 rclcpp::Time abs_day_start = rclcpp::Time(lanelet::time::toSec(ptime_start_of_day) * 1e9, clock_type);
74 rclcpp::Duration cur_start = control_start_ + control_offset_; // accounting for the shift of repetition start
75
76 // Check if current time is after end of control
77 if (ros_time_of_day > rclcpp::Time((control_start_ + control_duration_).nanoseconds(), clock_type))
78 {
79 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("carma_wm_ctrl"), "Geofence schedule too late in the day");
80 // The requested time is after control end so there will not be another interval
81 return std::make_pair(false, rclcpp::Time(0, 0, clock_type));
82 }
83
84 // Iterate over the day to find the next control interval
85 constexpr int num_sec_in_day = 86400;
86 const rclcpp::Duration full_day(num_sec_in_day* 1e9);
87 bool time_in_active_period = false; // Flag indicating if the requested time is within an active control span
88
89 while (cur_start < full_day && ros_time_of_day > rclcpp::Time(cur_start.nanoseconds(), clock_type))
90 {
91 // Check if the requested time is within the control period being evaluated
92 if (rclcpp::Time(cur_start.nanoseconds(), clock_type) < ros_time_of_day &&
93 ros_time_of_day < rclcpp::Time((cur_start + control_span_).nanoseconds(), clock_type))
94 {
95 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("carma_wm_ctrl"), "Geofence schedule active!");
96
97 time_in_active_period = true;
98 }
99 cur_start = cur_start + control_period_;
100
101 }
102
103
104 // check if the only next interval is after the schedule end or past the end of the day
105 if (abs_day_start + cur_start > schedule_end_ || cur_start > full_day || cur_start > (control_start_ + control_duration_))
106 {
107 RCLCPP_DEBUG_STREAM(rclcpp::get_logger("carma_wm_ctrl"), "Geofence schedule beyond end time");
108 return std::make_pair(time_in_active_period, rclcpp::Time(0, 0, clock_type));
109 }
110
111 // At this point we should have the next start time which is still within the schedule and day
112 return std::make_pair(time_in_active_period, abs_day_start + cur_start);
113}
bool scheduleExpired(const rclcpp::Time &time) const
Returns true if the schedule has expired by the provided time.

References control_duration_, control_offset_, control_period_, control_span_, control_start_, schedule_end_, scheduleExpired(), and week_day_set_.

Here is the call graph for this function:

◆ scheduleExpired()

bool carma_wm_ctrl::GeofenceSchedule::scheduleExpired ( const rclcpp::Time &  time) const

Returns true if the schedule has expired by the provided time.

Parameters
timeUTC time to compare
Returns
True if time > schedule_end

Definition at line 34 of file GeofenceSchedule.cpp.

35{
36 return schedule_end_ < time;
37}

References schedule_end_.

Referenced by getNextInterval().

Here is the caller graph for this function:

◆ scheduleStarted()

bool carma_wm_ctrl::GeofenceSchedule::scheduleStarted ( const rclcpp::Time &  time) const

Returns true if the schedule has started by the provided time.

Parameters
timeUTC time to compare
Returns
True if time > schedule_start

Definition at line 39 of file GeofenceSchedule.cpp.

40{
41 return schedule_start_ <= time;
42}

References schedule_start_.

Member Data Documentation

◆ control_duration_

rclcpp::Duration carma_wm_ctrl::GeofenceSchedule::control_duration_ {0, 0}

Definition at line 33 of file GeofenceSchedule.hpp.

Referenced by getNextInterval().

◆ control_offset_

rclcpp::Duration carma_wm_ctrl::GeofenceSchedule::control_offset_ {0, 0}

Definition at line 34 of file GeofenceSchedule.hpp.

Referenced by getNextInterval().

◆ control_period_

rclcpp::Duration carma_wm_ctrl::GeofenceSchedule::control_period_ {0, 0}

Definition at line 36 of file GeofenceSchedule.hpp.

Referenced by getNextInterval().

◆ control_span_

rclcpp::Duration carma_wm_ctrl::GeofenceSchedule::control_span_ {0, 0}

Definition at line 35 of file GeofenceSchedule.hpp.

Referenced by getNextInterval().

◆ control_start_

rclcpp::Duration carma_wm_ctrl::GeofenceSchedule::control_start_ {0, 0}

Definition at line 32 of file GeofenceSchedule.hpp.

Referenced by getNextInterval().

◆ schedule_end_

rclcpp::Time carma_wm_ctrl::GeofenceSchedule::schedule_end_

Definition at line 30 of file GeofenceSchedule.hpp.

Referenced by getNextInterval(), and scheduleExpired().

◆ schedule_start_

rclcpp::Time carma_wm_ctrl::GeofenceSchedule::schedule_start_

Definition at line 29 of file GeofenceSchedule.hpp.

Referenced by scheduleStarted().

◆ week_day_set_

DayOfTheWeekSet carma_wm_ctrl::GeofenceSchedule::week_day_set_

Definition at line 41 of file GeofenceSchedule.hpp.

Referenced by getNextInterval().


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