Carma-platform v4.2.0
CARMA Platform is built on robot operating system (ROS) and utilizes open source software (OSS) that enables Cooperative Driving Automation (CDA) features to allow Automated Driving Systems to interact and cooperate with infrastructure and other vehicles through communication.
MockDriver.cpp
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020-2021 LEIDOS.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License. You may obtain a copy of
6 * the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13 * License for the specific language governing permissions and limitations under
14 * the License.
15 */
16
18
19namespace mock_drivers
20{
22{
23}
24
26{
27 return mock_driver_node_;
28}
29
31{
32 return true;
33}
34
37
38 // driver discovery publisher
41
42 int return_val = onRun();
43
44 if (return_val != 0) {
45 return return_val;
46 }
47
49
50 return 0;
51}
52
54{
55 if (last_discovery_pub_ == ros::Time(0) || (ros::Time::now() - last_discovery_pub_).toSec() > 0.95)
56 {
58 last_discovery_pub_ = ros::Time::now();
59 }
60 return onSpin();
61}
62
64{
65 cav_msgs::DriverStatus discovery_msg;
66
67 discovery_msg.name = mock_driver_node_.getGraphName();
68 discovery_msg.status = getDriverStatus();
69
70 for (DriverType type : getDriverTypes())
71 {
72 switch (type)
73 {
74 case DriverType::CAN:
75 discovery_msg.can = true;
76 break;
78 discovery_msg.radar = true;
79 break;
81 discovery_msg.gnss = true;
82 break;
84 discovery_msg.lidar = true;
85 break;
87 discovery_msg.roadway_sensor = true;
88 break;
90 discovery_msg.comms = true;
91 break;
93 discovery_msg.controller = true;
94 break;
96 discovery_msg.camera = true;
97 break;
98 case DriverType::IMU:
99 discovery_msg.imu = true;
100 break;
102 discovery_msg.trailer_angle_sensor = true;
103 break;
105 discovery_msg.lightbar = true;
106 break;
107
108 default:
109 std::invalid_argument("Unsupported DriverType provided by getDriverTypes");
110 break;
111 }
112 }
113
114 mock_driver_node_.publishDataNoHeader<cav_msgs::DriverStatus>(driver_discovery_topic_, discovery_msg);
115}
116} // namespace mock_drivers
DriverType
Enum defining the different possible types of drivers.
Definition: DriverType.h:22
@ TRAILER_ANGLE_SENSOR
Node class which connects to the ROS network.
void spin(double rate) const
Begin the ros node.
std::string getGraphName() const
Returns the fully qualified name of this node in the ROS network graph.
void publishDataNoHeader(std::string topic, T msg)
Publish data with no header on a desired topic.
void setSpinCallback(std::function< bool()> cb) const
Set the spin callback for the ros node.
void init()
Initialize the CARMA Node Handle pointer for the MockDriverNode (must be called before spin)
void addPub(T comm)
Function to add a publisher from a ROSComms object.
MockDriverNode getMockDriverNode() const
Returns the mock driver node for the mock driver (used for testing)
Definition: MockDriver.cpp:25
virtual int onRun()=0
Pure virtual method which must be implemented by child classes. This method will be run once at start...
virtual bool onSpin()
Virtual method which child classes can override to add functionality which will occur during each spi...
Definition: MockDriver.cpp:30
ros::Time last_discovery_pub_
Definition: MockDriver.h:70
const std::string driver_discovery_topic_
Definition: MockDriver.h:65
ROSCommsPtr< cav_msgs::DriverStatus > driver_discovery_pub_ptr_
Definition: MockDriver.h:67
MockDriverNode mock_driver_node_
Definition: MockDriver.h:59
void driverDiscovery()
Helper function to publish the driver discovery message.
Definition: MockDriver.cpp:63
bool spinCallback()
Callback which will be triggered at the rate specified by getRate(). This callback will also trigger ...
Definition: MockDriver.cpp:53
int run()
A function to initialize the publishers and subsricers and start the node. In child classes,...
Definition: MockDriver.cpp:35
virtual unsigned int getRate()=0
Pure virtual method that returns the desired operational rate of a child class.
virtual std::vector< DriverType > getDriverTypes()=0
Pure Virtual method which child classes must override that returns the list of all driver types that ...
virtual uint8_t getDriverStatus()=0
Pure Virtual method. Returns an integer value which corresponds to the cav_msgs/DriverStatus enum fel...