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.
MockControllerDriver.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{
21std::vector<DriverType> MockControllerDriver::getDriverTypes()
22{
23 return { DriverType::CONTROLLER };
24}
25
27{
28 return cav_msgs::DriverStatus::OPERATIONAL;
29}
30
31void MockControllerDriver::vehicleCmdCallback(const autoware_msgs::VehicleCmd::ConstPtr& msg)
32{
33 robot_enabled_ = true; // If a command was received set the robot enabled status to true
34}
35
36bool MockControllerDriver::enableRoboticSrv(const cav_srvs::SetEnableRobotic::Request& req,
37 cav_srvs::SetEnableRobotic::Response& res)
38{
39 if (robot_enabled_ && req.set == cav_srvs::SetEnableRobotic::Request::ENABLE)
40 {
41 robot_active_ = true;
42 }
43 else
44 {
45 robot_active_ = false;
46 }
47
48 return true;
49}
50
52{
54
56 boost::make_shared<ROSComms<cav_msgs::RobotEnabled>>(CommTypes::pub, false, 10, robot_status_topic_);
57
58 vehicle_cmd_ptr_ = boost::make_shared<ConstPtrRefROSComms<autoware_msgs::VehicleCmd>>(
59 std::bind(&MockControllerDriver::vehicleCmdCallback, this, std::placeholders::_1), CommTypes::sub, false, 10,
61
63 boost::make_shared<ROSComms<cav_srvs::SetEnableRobotic::Request&, cav_srvs::SetEnableRobotic::Response&>>(
64 std::bind(&MockControllerDriver::enableRoboticSrv, this, std::placeholders::_1, std::placeholders::_2),
66}
67
69{
70 cav_msgs::RobotEnabled robot_status;
71 robot_status.robot_active = robot_active_;
72 robot_status.robot_enabled = robot_enabled_;
73
74 mock_driver_node_.publishDataNoHeader<cav_msgs::RobotEnabled>(robot_status_topic_, robot_status);
75
76 return true;
77}
78
80{
81 return 20; // 20 Hz as default spin rate to match expected controller data rate
82}
83
85{
86 // driver publisher, subscriber, and service
90
91 return 0;
92}
93
94} // namespace mock_drivers
std::vector< DriverType > getDriverTypes() override
Pure Virtual method which child classes must override that returns the list of all driver types that ...
boost::shared_ptr< ROSComms< cav_srvs::SetEnableRobotic::Request &, cav_srvs::SetEnableRobotic::Response & > > enable_robotic_ptr_
bool enableRoboticSrv(const cav_srvs::SetEnableRobotic::Request &req, cav_srvs::SetEnableRobotic::Response &res)
Callback for the enable robotic service. Triggering this callback will modify the RobotEnabled messag...
ConstPtrRefROSCommsPtr< autoware_msgs::VehicleCmd > vehicle_cmd_ptr_
boost::shared_ptr< ROSComms< cav_msgs::RobotEnabled > > robot_status_ptr_
unsigned int getRate() override
Pure virtual method that returns the desired operational rate of a child class.
int onRun() override
Pure virtual method which must be implemented by child classes. This method will be run once at start...
uint8_t getDriverStatus() override
Pure Virtual method. Returns an integer value which corresponds to the cav_msgs/DriverStatus enum fel...
bool onSpin() override
Virtual method which child classes can override to add functionality which will occur during each spi...
void vehicleCmdCallback(const autoware_msgs::VehicleCmd::ConstPtr &msg)
Callback for the vehicle command topic. This callback must be triggered at least once before the enab...
Node class which connects to the ROS network.
void addSub(T comm)
Function to add a subscriber from a ROSComms object.
void publishDataNoHeader(std::string topic, T msg)
Publish data with no header on a desired topic.
void addSrv(T comm)
Function to add a service from a ROSComms object.
void addPub(T comm)
Function to add a publisher from a ROSComms object.
MockDriverNode mock_driver_node_
Definition: MockDriver.h:59