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.
MockDriverNode.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}
24MockDriverNode::MockDriverNode(bool dummy) : dummy_(dummy)
25{
26}
27
29{
30 if (dummy_)
31 {
32 return "dummy_mock_driver";
33 }
34
35 return ros::this_node::getName();
36}
37
38void MockDriverNode::spin(double rate) const
39{
40 if (!dummy_)
41 {
42 ros::CARMANodeHandle::setSpinRate(rate);
43 ros::CARMANodeHandle::spin();
44 }
45}
46
47void MockDriverNode::setSpinCallback(std::function<bool()> cb) const
48{
49 if (!dummy_)
50 {
51 ros::CARMANodeHandle::setSpinRate(10.0); // Set spin to avoid exception until spin is called and this value updated
52 ros::CARMANodeHandle::setSpinCallback(cb);
53 }
54}
55
57{
58 if (!dummy_)
59 {
60 cnh_ = boost::make_shared<ros::CARMANodeHandle>(ros::CARMANodeHandle());
61 }
62}
63
64} // namespace mock_drivers
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 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)
boost::shared_ptr< ros::CARMANodeHandle > cnh_