ADORe
ADORe is a modular open source software library and toolkit for decision making, planning, control and simulation of automated vehicles
simfactory.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  * Daniel Heß - initial API and implementation
13  ********************************************************************************/
14 
15 #pragma once
16 
17 
18 #include <adore/sim/afactory.h>
20 
21 #include <std_msgs/Float32.h>
22 #include <std_msgs/Float64.h>
23 #include <std_msgs/String.h>
24 #include <std_msgs/Int8.h>
25 #include <std_msgs/Int64.h>
26 #include <std_msgs/Bool.h>
27 #include <rosgraph_msgs/Clock.h>
28 #include <nav_msgs/Odometry.h>
29 #include <tf2/LinearMath/Quaternion.h>
30 #include <geometry_msgs/Pose.h>
31 #include <geometry_msgs/Twist.h>
43 
44 
45 
46 namespace adore
47 {
48  namespace if_ROS
49  {
54  {
55  private:
56  ros::NodeHandle* n_;
57  public:
58  SIM_Factory(ros::NodeHandle* n):n_(n)
59  {
60 
61  }
62 
63  public: //overloaded methods
64  //read a motion command
66  {
67  return new MotionCommandReader(n_,"FUN/MotionCommand/acceleration","FUN/MotionCommand/steeringAngle",1);
68  }
69  //read a gear selection command
71  {
73  std_msgs::Int8ConstPtr,
74  GearSelectionCommandConverter>(n_,"FUN/GearSelectionCommand",1);
75  }
76  //read an indicator command
78  {
79  return new IndicatorCommandReader(n_,"FUN/IndicatorCommand/left","FUN/IndicatorCommand/right",1);
80  }
81  //write updates on the vehicle motion state
83  {
84  return new MotionStateWriter(n_,"utm","SIM/state","VEH/steering_angle_measured","VEH/ax",1);
85  }
88  {
89  return new MotionStateWriter(n_,"odom","odom","","",1);
90  }
93  {
94  return new MotionStateWriter(n_,"utm","localization","","",1);
95  }
98  {
99  return new MotionStateReader(n_,"SIM/state","VEH/steering_angle_measured","VEH/ax",1);
100  }
101  //write updates on the vehicle extended state (buttons, etc.)
103  {
104  return new VehicleExtendedStateWriter(n_,
105  "VEH/gear_state",
106  "VEH/AutomaticControlState/acceleration",
107  "VEH/AutomaticControlState/accelerationActive",
108  "VEH/AutomaticControlState/steering",
109  "VEH/IndicatorState/left",
110  "VEH/IndicatorState/right",
111  "VEH/Checkpoints/clearance",
112  1);
113  }
114  //read the simulation time
116  {
118  }
119 
120  //write the simulation time
122  {
123  return new Writer<double,std_msgs::Float64,StdConverter>(n_,"/SIM/utc",1);
124  }
125 
126  //write the clock time
128  {
129  return new Writer<std::pair<uint32_t,uint32_t>,rosgraph_msgs::Clock,ClockTimeConverter>(n_,"/clock",1);
130  }
131 
132  //read simulation commands for vehicle position and orientation resetting
134  {
135  return new Feed<sim::ResetVehiclePose,
136  geometry_msgs::PoseConstPtr,
137  SimVehicleResetConverter>(n_,"SIM/ResetVehiclePose",1);
138  }
139  //read simulation commands for vehicle speed resetting
141  {
142  return new Feed<sim::ResetVehicleTwist,
143  geometry_msgs::TwistConstPtr,
144  SimVehicleResetConverter>(n_,"SIM/ResetVehicleTwist",1);
145  }
146  //send simulation commands for vehicle position and orientation resetting
148  {
149  return new Writer<sim::ResetVehiclePose,
150  geometry_msgs::Pose,
151  SimVehicleResetConverter>(n_,"SIM/ResetVehiclePose",1);
152  }
154  {
155  return new Writer<sim::ResetVehicleTwist,
156  geometry_msgs::Twist,
157  SimVehicleResetConverter>(n_,"SIM/ResetVehicleTwist",1);
158  }
161  {
162  return new Feed<int64_t,std_msgs::Int64,StdConverter>(n_,"SIM/ResetSimulationID",10);
163  }
165  {
166  return new Feed<int64_t,std_msgs::Int64,StdConverter>(n_,"SIM/ResetV2XStationID",10);
167  }
170  {
172  adore_if_ros_msg::SimResetVehicleDimensions,
173  SimVehicleDimensionsConverter>(n_,ns + "SIM/ResetVehicleDimensions",1);
174  }
177  {
179  adore_if_ros_msg::SimResetVehicleDimensionsConstPtr,
180  SimVehicleDimensionsConverter>(n_,"SIM/ResetVehicleDimensions",1);
181  }
184  {
186  adore_if_ros_msg::TrafficParticipantSet,
187  TPSetConverter>(n_,"traffic",1);
188  }
191  {
193  adore_if_ros_msg::TrafficParticipantSimulation,
194  TPSimulationConverter>(n_,"/SIM/traffic",1);
195  }
198  {
199  // return new Feed<adore::env::traffic::Participant,
200  // adore_if_ros_msg::TrafficParticipantSimulationConstPtr,
201  // TPSimulationConverter>(n_,"/SIM/traffic",1000);
202  return new TrafficSimulationFeed(n_,"/SIM/traffic",1000,"/SIM/traffic/agg",20);
203  }
204  // send updates for simulated trafficlights
206  {
207  return new TrafficLightSimWriter(n_,"/SIM/SimTl",300);
208  }
209  // get updates for simulated trafficlights
211  {
212  return new TrafficLightSimReader(n_,"/SIM/SimTl",300);
213  }
214  // send id for transforming vehicle to ADORe vehicle
216  {
217  return new Writer<int64_t,std_msgs::Int64,StdConverter>(n_,"/SIM/transformtoadore",10);
218  }
219  };
220  }
221 }
Definition: ros_com_patterns.h:32
Definition: indicatorcommandconverter.h:72
Definition: motioncommandconverter.h:70
Definition: funvehiclemotionstateconverter.h:47
Definition: funvehiclemotionstateconverter.h:416
Definition: ros_com_patterns.h:113
Definition: simfactory.h:54
virtual TClockTimeWriter * getClockTimeWriter() override
write clock time
Definition: simfactory.h:127
virtual TVehicleMotionStateWriter * getOdometryEstimatedVehicleStateWriter() override
write updates on the odometry estimated vehicle motion state
Definition: simfactory.h:87
virtual TVehicleTwistResetWriter * getVehicleTwistResetWriter() override
send simulation commands for vehicle speed resetting
Definition: simfactory.h:153
virtual TVehicleDimensionsResetFeed * getVehicleDimensionsResetFeed() override
receive simulation commands for resetting vehicle dimensions
Definition: simfactory.h:176
SIM_Factory(ros::NodeHandle *n)
Definition: simfactory.h:58
virtual TParticipantWriter * getParticipantWriter() override
send ego state to simulation feed
Definition: simfactory.h:190
virtual TMotionCommandReader * getMotionCommandReader() override
read a motion command
Definition: simfactory.h:65
ros::NodeHandle * n_
Definition: simfactory.h:56
virtual TSimulationTimeWriter * getSimulationTimeWriter() override
write the simulation time
Definition: simfactory.h:121
virtual TVehicleMotionStateWriter * getLocalizationEstimatedVehicleStateWriter() override
write updates on the localization estimated vehicle motion state
Definition: simfactory.h:92
virtual TIndicatorCommandReader * getIndicatorCommandReader() override
read an indicator command
Definition: simfactory.h:77
virtual adore::mad::AWriter< adore::env::SimTrafficLight > * getTrafficLightWriter() override
send simulated traffic light states
Definition: simfactory.h:205
virtual TParticipantFeed * getParticipantFeed()
get state updates from all vehicles
Definition: simfactory.h:197
virtual TSimulationTimeReader * getSimulationTimeReader() override
read the simulation time
Definition: simfactory.h:115
virtual TParticipantSetWriter * getParticipantSetWriter() override
send simulated sensor data
Definition: simfactory.h:183
virtual TGearSelectionCommandReader * getGearSelectionCommandReader() override
read a gear selection command
Definition: simfactory.h:70
virtual TVehicleMotionStateWriter * getVehicleMotionStateWriter() override
write updates on the true vehicle motion state
Definition: simfactory.h:82
virtual TSimulationIDResetFeed * getSimulationIDResetFeed() override
send simulation commands for resetting simulation id and v2xstation id
Definition: simfactory.h:160
virtual TVehicleExtendedStateWriter * getVehicleExtendedStateWriter() override
write updates on the vehicle extended state (buttons, etc.)
Definition: simfactory.h:102
virtual TV2XStationIDResetFeed * getV2XStationIDResetFeed() override
read simulation commands for v2x station id resetting
Definition: simfactory.h:164
virtual TVehicleDimensionsResetWriter * getVehicleDimensionsResetWriter(std::string ns) override
send simulation commands for resetting vehicle dimensions
Definition: simfactory.h:169
virtual adore::mad::AReader< adore::env::SimTrafficLightMap > * getTrafficLightReader() override
receive simulated traffic light states
Definition: simfactory.h:210
virtual TVehiclePoseResetWriter * getVehiclePoseResetWriter() override
Definition: simfactory.h:147
virtual TVehicleMotionStateReader * getVehicleMotionStateReader() override
read updates on the true vehicle motion state
Definition: simfactory.h:97
virtual adore::mad::AWriter< int64_t > * getTransformIDtoAdoreWriter()
send id of vehicle to transform
Definition: simfactory.h:215
virtual TVehicleTwistResetFeed * getVehicleTwistResetFeed() override
read simulation commands for vehicle speed resetting
Definition: simfactory.h:140
virtual TVehiclePoseResetFeed * getVehiclePoseResetFeed() override
read simulation commands for vehicle position and orientation resetting
Definition: simfactory.h:133
Definition: trafficparticipantconverter.h:119
Definition: trafficparticipantconverter.h:200
Definition: trafficlightsimconverter.h:90
Definition: trafficlightsimconverter.h:32
Definition: trafficsimulationfeed.h:25
Definition: funvehiclemotionstateconverter.h:347
Definition: ros_com_patterns.h:153
abstract factory for adore::sim communication
Definition: afactory.h:43
std::vector< Participant > TParticipantSet
Definition: participant.h:164
Definition: areaofeffectconverter.h:20
Struct for representing a participant in traffic.
Definition: participant.h:30
Definition: gearselectioncommand.h:26
Definition: clocktimeconverter.h:25
Definition: gearselectioncommandconverter.h:39
Definition: simresetvehicledimensionsconverter.h:24
Definition: simvehicleresetconverter.h:33
provides encapsulation of values needed to reset the vehicle dimensions in a simulation
Definition: resetvehicledimensions.h:26
provides encapsulation of values needed to reset the vehicle pose in a simulation
Definition: resetvehiclepose.h:26
provides encapsulation of values needed to reset the vehicle twist (vx,vy and omega) in a simulation
Definition: resetvehicletwist.h:26