ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
schedulernotificationmanager.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017-2023 German Aerospace Center (DLR).
3  * Eclipse ADORe, Automated Driving Open Research https://eclipse.org/adore
4  *
5  * This program and the accompanying materials are made available under the
6  * terms of the Eclipse Public License 2.0 which is available at
7  * http://www.eclipse.org/legal/epl-2.0.
8  *
9  * SPDX-License-Identifier: EPL-2.0
10  *
11  * Contributors:
12  * Matthias Nichting - initial API and implementation
13  ********************************************************************************/
14 
15 #pragma once
16 
20 #include <ros/ros.h>
21 #include <std_msgs/String.h>
22 
23 #include <string>
24 #include <thread>
25 
27 {
32  {
33  private:
34  ros::NodeHandle *m_pN;
35  ros::Publisher m_notificationWriter;
36  ros::Publisher m_clientNameWriter;
38 
39  public:
40  SchedulerNotificationManager(ros::NodeHandle *n, unsigned int id, uint32_t duration, bool reg = true)
42  {
45  m_pN->advertise<adore_if_ros_scheduling_msg::SchedulerNotification>(adore_if_ros_scheduling::TOPIC_NAME_SCHEDULER_NOTIFICATION, 1);
46  while (!m_notificationWriter.getNumSubscribers())
47  {
48  std::cout << "wait for the scheduler ..." << std::endl;
49  std::this_thread::sleep_for(std::chrono::seconds(1));
50  }
51  m_sn.setID(id);
52  std::cout << "scheduler id : " << id << std::endl;
53  if (reg) registerAtScheduler();
54  }
55  void publishClientName(std::string name) override
56  {
57  std_msgs::String msg;
58  msg.data = std::to_string(m_sn.getID()) + ":" + name;
59  m_clientNameWriter.publish(msg);
60  }
61  void registerAtScheduler() override
62  {
65  }
66  void notifyScheduler(uint32_t sec, uint32_t nsec) override
67  {
68  m_sn.setUpperTimeLimit(sec, nsec + m_duration);
69  if (!m_pause)
70  {
72  }
73  }
74  void pause() override { m_pause = true; }
75  void resume() override
76  {
77  m_pause = false;
79  }
80  };
81 } // namespace adore_if_ros_scheduling
Definition: schedulernotificationconversion.h:25
Definition: schedulernotificationmanager.h:32
ros::Publisher m_notificationWriter
Definition: schedulernotificationmanager.h:35
void resume() override
Definition: schedulernotificationmanager.h:75
ros::Publisher m_clientNameWriter
Definition: schedulernotificationmanager.h:36
SchedulerNotificationConversion m_schedulerNotificationConversion
Definition: schedulernotificationmanager.h:37
void publishClientName(std::string name) override
Definition: schedulernotificationmanager.h:55
ros::NodeHandle * m_pN
Definition: schedulernotificationmanager.h:34
void registerAtScheduler() override
Definition: schedulernotificationmanager.h:61
SchedulerNotificationManager(ros::NodeHandle *n, unsigned int id, uint32_t duration, bool reg=true)
Definition: schedulernotificationmanager.h:40
void notifyScheduler(uint32_t sec, uint32_t nsec) override
Definition: schedulernotificationmanager.h:66
void pause() override
Definition: schedulernotificationmanager.h:74
Definition: aschedulernotificationmanager.h:24
uint32_t m_duration
Definition: aschedulernotificationmanager.h:27
adore_scheduling::SchedulerNotification m_sn
Definition: aschedulernotificationmanager.h:26
ASchedulerNotificationManager(uint32_t duration)
Definition: aschedulernotificationmanager.h:31
bool m_pause
Definition: aschedulernotificationmanager.h:28
void setUpperTimeLimit(uint32_t sec, uint32_t nsec)
Definition: schedulernotification.h:48
void setID(unsigned int id)
Definition: schedulernotification.h:68
unsigned int getID() const
Definition: schedulernotification.h:64
Definition: adore_if_ros_scheduling_constants.h:19
const char TOPIC_NAME_CLIENT_NAME[]
Definition: adore_if_ros_scheduling_constants.h:22
const char TOPIC_NAME_SCHEDULER_NOTIFICATION[]
Definition: adore_if_ros_scheduling_constants.h:23
Definition: aschedulernotificationmanager.h:19