ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
missiondataconverter.h
Go to the documentation of this file.
1 /********************************************************************************
2  * Copyright (C) 2017-2020 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  * Jan Lauermann - initial API and implementation
13  ********************************************************************************/
14 
15 #pragma once
16 #include <adore/fun/missiondata.h>
18 #include <adore_if_ros_msg/MissionState.h>
19 #include <std_msgs/UInt8.h>
20 
21 
22 namespace adore
23 {
24  namespace if_ROS
25  {
30  class MissionDataReader:public adore::mad::AReader<adore::fun::MissionData>
31  {
32  private:
33  ros::Subscriber mission_state_subscriber_;
35  bool changed_;
37 
38  void receive_mission_state(std_msgs::UInt8ConstPtr msg)
39  {
42  changed_ = true;
43  }
44 
45  public:
46  MissionDataReader(ros::NodeHandle* n,
47  const std::string mission_state_topic,
48  int qsize)
50  changed_(false)
51  {
52  bool no_delay;
53  n->param("/tcp_no_delay", no_delay, false);
54  mission_state_subscriber_ = n->subscribe(mission_state_topic,qsize,&MissionDataReader::receive_mission_state,this,ros::TransportHints().tcpNoDelay(no_delay));
55  }
56  virtual bool hasData() const override
57  {
59  }
60  virtual bool hasUpdate() const override
61  {
62  return hasData() && changed_;
63  }
64  virtual void getData(adore::fun::MissionData& value) override
65  {
66  value = data_;
67  }
68 
69  };
70 
71 
76  class MissionDataWriter: public adore::mad::AWriter<adore::fun::MissionData>
77  {
78  private:
79  ros::Publisher mission_state_publisher_;
80 
81  public:
82  MissionDataWriter(ros::NodeHandle* n,
83  const std::string& mission_state_topic,
84  int qsize)
85  {
86  mission_state_publisher_ = n->advertise<std_msgs::UInt8>(mission_state_topic,qsize);
87  }
88  virtual bool canWriteMore() const override
89  {
90  return true;
91  }
92  //sends out data value
93  virtual void write(const adore::fun::MissionData& value) override
94  {
95  std_msgs::UInt8 msg;
96  msg.data = (uint)value.getMissionState();
97  mission_state_publisher_.publish(msg);
98  }
99  };
100  }
101 }
Definition: missiondata.h:25
void setMissionState(MissionState missionState)
Definition: missiondata.h:45
MissionState getMissionState() const
Definition: missiondata.h:42
MissionState
Definition: missiondata.h:28
Definition: missiondataconverter.h:31
void receive_mission_state(std_msgs::UInt8ConstPtr msg)
Definition: missiondataconverter.h:38
bool changed_
Definition: missiondataconverter.h:35
MissionDataReader(ros::NodeHandle *n, const std::string mission_state_topic, int qsize)
Definition: missiondataconverter.h:46
virtual bool hasUpdate() const override
Definition: missiondataconverter.h:60
virtual void getData(adore::fun::MissionData &value) override
Definition: missiondataconverter.h:64
virtual bool hasData() const override
Definition: missiondataconverter.h:56
bool mission_state_initialized_
Definition: missiondataconverter.h:34
adore::fun::MissionData data_
Definition: missiondataconverter.h:36
ros::Subscriber mission_state_subscriber_
Definition: missiondataconverter.h:33
Definition: missiondataconverter.h:77
virtual bool canWriteMore() const override
Definition: missiondataconverter.h:88
MissionDataWriter(ros::NodeHandle *n, const std::string &mission_state_topic, int qsize)
Definition: missiondataconverter.h:82
virtual void write(const adore::fun::MissionData &value) override
Definition: missiondataconverter.h:93
ros::Publisher mission_state_publisher_
Definition: missiondataconverter.h:79
Definition: com_patterns.h:68
Definition: com_patterns.h:97
Definition: areaofeffectconverter.h:20