ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
indicatorcommandconverter.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  * Daniel Heß - initial API and implementation
13  ********************************************************************************/
14 
15 #pragma once
16 
17 #include <adore/fun/afactory.h>
19 #include <adore_if_ros_msg/NavigationGoal.h>
20 #include <adore_if_ros_msg/SetPointRequest.h>
21 #include <adore_if_ros_msg/TerminalRequest.h>
22 #include <adore_if_ros_msg/WheelSpeed.h>
23 #include <tf/tf.h>
24 #include <tf/LinearMath/Quaternion.h>
25 #include <std_msgs/Float64.h>
26 #include <std_msgs/Float32.h>
27 #include <std_msgs/Int8.h>
28 #include <std_msgs/Bool.h>
29 #include <nav_msgs/Odometry.h>
30 
31 namespace adore
32 {
33  namespace if_ROS
34  {
35 
40  class IndicatorCommandWriter:public adore::mad::AWriter<adore::fun::IndicatorCommand>
41  {
42  private:
43  ros::Publisher leftPublisher_;
44  ros::Publisher rightPublisher_;
45  public:
46  IndicatorCommandWriter(ros::NodeHandle* n,const std::string lefttopic,const std::string righttopic,int qsize)
47  {
48  leftPublisher_ = n->advertise<std_msgs::Bool>(lefttopic,qsize);
49  rightPublisher_ = n->advertise<std_msgs::Bool>(righttopic,qsize);
50  }
52  virtual bool canWriteMore() const override
53  {
54  return true;
55  }
57  virtual void write(const adore::fun::IndicatorCommand& value)override
58  {
59  std_msgs::Bool msg_left,msg_right;
60  msg_left.data = value.getIndicatorLeftOn();
61  msg_right.data = value.getIndicatorRightOn();
62  leftPublisher_.publish(msg_left);
63  rightPublisher_.publish(msg_right);
64  }
65  };
66 
71  class IndicatorCommandReader:public adore::mad::AReader<adore::fun::IndicatorCommand>
72  {
73  private:
75  ros::Subscriber leftIndicatorSubscriber_;
76  ros::Subscriber rightIndicatorSubscriber_;
77  bool changed_;
78  void receive_left(std_msgs::BoolConstPtr msg)
79  {
80  bool old_state = data_.getIndicatorLeftOn();
81  data_.setIndicatorLeftOn(msg.get()->data);
82  changed_ = changed_ || data_.getIndicatorLeftOn() != old_state;
83  }
84  void receive_right(std_msgs::BoolConstPtr msg)
85  {
86  bool old_state = data_.getIndicatorRightOn();
87  data_.setIndicatorRightOn(msg.get()->data);
88  changed_ = changed_ || data_.getIndicatorRightOn() != old_state;
89  }
90  public:
91  IndicatorCommandReader(ros::NodeHandle* n,const std::string& topic_leftIndicator,const std::string& topic_rightIndicator,int qsize)
92  :changed_(false)
93  {
94  leftIndicatorSubscriber_ = n->subscribe(topic_leftIndicator,qsize,&IndicatorCommandReader::receive_left,this);
95  rightIndicatorSubscriber_ = n->subscribe(topic_rightIndicator,qsize,&IndicatorCommandReader::receive_right,this);
96  }
97  virtual bool hasData() const override
98  {
99  return true;
100  }
101  bool hasUpdate() const override
102  {
103  return hasData() && changed_;
104  }
105  virtual void getData(adore::fun::IndicatorCommand& value) override
106  {
107  value = data_;
108  }
109  };
110  }
111 }
Definition: indicatorcommandconverter.h:72
virtual bool hasData() const override
Definition: indicatorcommandconverter.h:97
IndicatorCommandReader(ros::NodeHandle *n, const std::string &topic_leftIndicator, const std::string &topic_rightIndicator, int qsize)
Definition: indicatorcommandconverter.h:91
ros::Subscriber leftIndicatorSubscriber_
Definition: indicatorcommandconverter.h:75
ros::Subscriber rightIndicatorSubscriber_
Definition: indicatorcommandconverter.h:76
void receive_left(std_msgs::BoolConstPtr msg)
Definition: indicatorcommandconverter.h:78
void receive_right(std_msgs::BoolConstPtr msg)
Definition: indicatorcommandconverter.h:84
virtual void getData(adore::fun::IndicatorCommand &value) override
Definition: indicatorcommandconverter.h:105
adore::fun::IndicatorCommand data_
Definition: indicatorcommandconverter.h:74
bool hasUpdate() const override
Definition: indicatorcommandconverter.h:101
bool changed_
Definition: indicatorcommandconverter.h:77
Definition: indicatorcommandconverter.h:41
IndicatorCommandWriter(ros::NodeHandle *n, const std::string lefttopic, const std::string righttopic, int qsize)
Definition: indicatorcommandconverter.h:46
ros::Publisher leftPublisher_
Definition: indicatorcommandconverter.h:43
virtual void write(const adore::fun::IndicatorCommand &value) override
write sends out data value
Definition: indicatorcommandconverter.h:57
virtual bool canWriteMore() const override
canWriteMore indicates whether more data can be written
Definition: indicatorcommandconverter.h:52
ros::Publisher rightPublisher_
Definition: indicatorcommandconverter.h:44
Definition: com_patterns.h:68
Definition: com_patterns.h:97
Definition: areaofeffectconverter.h:20
Definition: indicatorcommand.h:25
void setIndicatorRightOn(bool indicatorRightOn)
Definition: indicatorcommand.h:49
bool getIndicatorLeftOn() const
Definition: indicatorcommand.h:35
void setIndicatorLeftOn(bool indicatorLeftOn)
Definition: indicatorcommand.h:39
bool getIndicatorRightOn() const
Definition: indicatorcommand.h:45