18#include <boost/date_time/posix_time/posix_time.hpp>
27 rclcpp::Duration control_duration, rclcpp::Duration control_offset,
28 rclcpp::Duration control_span, rclcpp::Duration control_period,
DayOfTheWeekSet week_day_set):
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)
48 auto clock_type = time.get_clock_type();
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));
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();
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));
65 auto time_of_day = boost_time.time_of_day();
69 boost::posix_time::ptime ptime_start_of_day(date, boost::posix_time::hours(0));
71 rclcpp::Time ros_time_of_day = rclcpp::Time(lanelet::time::toSec(time_of_day) * 1e9, clock_type);
73 rclcpp::Time abs_day_start = rclcpp::Time(lanelet::time::toSec(ptime_start_of_day) * 1e9, clock_type);
79 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"carma_wm_ctrl"),
"Geofence schedule too late in the day");
81 return std::make_pair(
false, rclcpp::Time(0, 0, clock_type));
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;
89 while (cur_start < full_day && ros_time_of_day > rclcpp::Time(cur_start.nanoseconds(), clock_type))
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))
95 RCLCPP_DEBUG_STREAM(rclcpp::get_logger(
"carma_wm_ctrl"),
"Geofence schedule active!");
97 time_in_active_period =
true;
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));
112 return std::make_pair(time_in_active_period, abs_day_start + cur_start);
bool scheduleStarted(const rclcpp::Time &time) const
Returns true if the schedule has started by the provided time.
rclcpp::Duration control_span_
rclcpp::Time schedule_start_
rclcpp::Duration control_start_
std::pair< bool, rclcpp::Time > getNextInterval(const rclcpp::Time &time) const
Returns the start time of the next active interval defined by this schedule.
rclcpp::Duration control_period_
rclcpp::Time schedule_end_
GeofenceSchedule()
Default Constructor does not initialize any members.
std::unordered_set< boost::gregorian::greg_weekday, std::hash< int > > DayOfTheWeekSet
DayOfTheWeekSet week_day_set_
rclcpp::Duration control_offset_
bool scheduleExpired(const rclcpp::Time &time) const
Returns true if the schedule has expired by the provided time.
rclcpp::Duration control_duration_