ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
motioncommandconverter.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  {
39  class MotionCommandWriter:public adore::mad::AWriter<adore::fun::MotionCommand>
40  {
41  private:
42  ros::Publisher accelerationPublisher_;
43  ros::Publisher steeringAnglePublisher_;
44  public:
45  MotionCommandWriter(ros::NodeHandle* n,const std::string axtopic,const std::string deltatopic,int qsize)
46  {
47  accelerationPublisher_ = n->advertise<std_msgs::Float32>(axtopic,qsize);
48  steeringAnglePublisher_ = n->advertise<std_msgs::Float32>(deltatopic,qsize);
49  }
51  virtual bool canWriteMore() const override
52  {
53  return true;
54  }
56  virtual void write(const adore::fun::MotionCommand& value)override
57  {
58  std_msgs::Float32 msg_acceleration,msg_steeringAngle;
59  msg_acceleration.data = value.getAcceleration();
60  msg_steeringAngle.data = value.getSteeringAngle();
61  accelerationPublisher_.publish(msg_acceleration);
62  steeringAnglePublisher_.publish(msg_steeringAngle);
63  }
64  };
69  class MotionCommandReader:public adore::mad::AReader<adore::fun::MotionCommand>
70  {
71  private:
72  bool changed_;
75  ros::Subscriber accelerationSubscriber_;
76  ros::Subscriber steeringSubscriber_;
77 
78 
80 
81  void receive_accelerationRequest(std_msgs::Float32ConstPtr msg)
82  {
83  data_.setAcceleration(msg->data);
85  changed_ = true;
86  }
87  void receive_steeringRequest(std_msgs::Float32ConstPtr msg)
88  {
89  data_.setSteeringAngle(msg->data);
90  steering_initialized_ = true;
91  changed_ = true;
92  }
93  public:
94  MotionCommandReader(ros::NodeHandle* n,const std::string axtopic,const std::string steeringtopic,int qsize)
95  {
97  steeringSubscriber_ = n->subscribe(steeringtopic,qsize,&MotionCommandReader::receive_steeringRequest,this);
98  changed_ = false;
100  steering_initialized_ = false;
101  }
103  virtual bool hasData() const override
104  {
106  }
108  virtual bool hasUpdate() const override
109  {
110  return changed_;
111  }
113  virtual void getData(adore::fun::MotionCommand& value)
114  {
115  changed_ = false;
116  value = data_;
117  }
118  };
119  }
120 }
Definition: motioncommand.h:26
void setAcceleration(double acceleration)
Definition: motioncommand.h:51
double getSteeringAngle() const
Definition: motioncommand.h:37
double getAcceleration() const
Definition: motioncommand.h:47
void setSteeringAngle(double steeringAngle)
Definition: motioncommand.h:41
Definition: motioncommandconverter.h:70
virtual void getData(adore::fun::MotionCommand &value)
getData returns the latest data item
Definition: motioncommandconverter.h:113
void receive_steeringRequest(std_msgs::Float32ConstPtr msg)
Definition: motioncommandconverter.h:87
ros::Subscriber accelerationSubscriber_
Definition: motioncommandconverter.h:75
void receive_accelerationRequest(std_msgs::Float32ConstPtr msg)
Definition: motioncommandconverter.h:81
bool steering_initialized_
Definition: motioncommandconverter.h:74
adore::fun::MotionCommand data_
Definition: motioncommandconverter.h:79
ros::Subscriber steeringSubscriber_
Definition: motioncommandconverter.h:76
MotionCommandReader(ros::NodeHandle *n, const std::string axtopic, const std::string steeringtopic, int qsize)
Definition: motioncommandconverter.h:94
virtual bool hasUpdate() const override
hasUpdate indicates whether the data item was updated since last getdata
Definition: motioncommandconverter.h:108
bool acceleration_initialized_
Definition: motioncommandconverter.h:73
bool changed_
Definition: motioncommandconverter.h:72
virtual bool hasData() const override
hasData indicates whether the data has been initialized with a first data item
Definition: motioncommandconverter.h:103
Definition: motioncommandconverter.h:40
virtual bool canWriteMore() const override
canWriteMore indicates whether more data can be written
Definition: motioncommandconverter.h:51
MotionCommandWriter(ros::NodeHandle *n, const std::string axtopic, const std::string deltatopic, int qsize)
Definition: motioncommandconverter.h:45
ros::Publisher accelerationPublisher_
Definition: motioncommandconverter.h:42
virtual void write(const adore::fun::MotionCommand &value) override
write sends out data value
Definition: motioncommandconverter.h:56
ros::Publisher steeringAnglePublisher_
Definition: motioncommandconverter.h:43
Definition: com_patterns.h:68
Definition: com_patterns.h:97
Definition: areaofeffectconverter.h:20