SMACC2
Loading...
Searching...
No Matches
cp_costmap_switch.cpp
Go to the documentation of this file.
1// Copyright 2025 Robosoft Inc.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
16
17namespace cl_nav2z
18{
19std::array<std::string, 4> CpCostmapSwitch::layerNames = {
20 "global_costmap/obstacles_layer",
21 "local_costmap/obstacles_layer"
22 "global_costmap/inflater_layer",
23 "local_costmap/inflater_layer"};
24
26 std::string costmapName, std::string enablePropertyName)
27{
28 RCLCPP_INFO(getLogger(), "[CpCostmapSwitch] registering costmap type: %s", costmapName.c_str());
29 auto proxy = std::make_shared<CpCostmapProxy>(
30 this->nav2zClient_->getName() + "/" + costmapName, enablePropertyName, getNode());
31 costmapProxies[costmapName] = proxy;
32}
33
35
54
56{
57 return CpCostmapSwitch::layerNames[(int)layertype];
58}
59
60bool CpCostmapSwitch::exists(std::string layerName)
61{
62 if (!this->costmapProxies.count(layerName))
63 {
64 return false;
65 }
66
67 return true;
68}
69
70void CpCostmapSwitch::enable(std::string layerName)
71{
72 RCLCPP_INFO(getLogger(), "[CpCostmapSwitch] enabling %s", layerName.c_str());
73
74 if (!exists(layerName))
75 {
76 RCLCPP_ERROR(getLogger(), "[CpCostmapSwitch] costmap %s does not exist", layerName.c_str());
77 return;
78 }
79 else
80 {
81 RCLCPP_INFO(
82 getLogger(), "[CpCostmapSwitch] costmap %s found. Calling dynamic reconfigure server.",
83 layerName.c_str());
84 costmapProxies[layerName]->setCostmapEnabled(true);
85 }
86}
87
89{
90 this->enable(getStandardCostmapName(layerType));
91}
92
93void CpCostmapSwitch::disable(std::string layerName)
94{
95 RCLCPP_INFO(getLogger(), "[CpCostmapSwitch] disabling %s", layerName.c_str());
96
97 if (!exists(layerName))
98 {
99 RCLCPP_ERROR(getLogger(), "[CpCostmapSwitch] costmap %s does not exist", layerName.c_str());
100 return;
101 }
102 else
103 {
104 RCLCPP_INFO(
105 getLogger(), "[CpCostmapSwitch] costmap %s found. Calling dynamic reconfigure server.",
106 layerName.c_str());
107 costmapProxies[layerName]->setCostmapEnabled(false);
108 }
109}
110
112{
113 this->disable(getStandardCostmapName(layerType));
114}
115
116//-------------------------------------------------------------------------
117
119 std::string /*costmap_name*/, std::string /*enablePropertyName*/, rclcpp::Node::SharedPtr nh)
120: nh_(nh)
121{
122 RCLCPP_ERROR(nh->get_logger(), "costmap switch not implemented %s", costmapName_.c_str());
123}
124
126{
127 RCLCPP_ERROR(nh_->get_logger(), "costmap switch not implemented %s", costmapName_.c_str());
128}
129} // namespace cl_nav2z
rclcpp::Node::SharedPtr nh_
CpCostmapProxy(std::string costmap_name, std::string enablePropertyName, rclcpp::Node::SharedPtr nh)
cl_nav2z::ClNav2Z * nav2zClient_
void disable(std::string layerName)
std::map< std::string, std::shared_ptr< CpCostmapProxy > > costmapProxies
void registerProxyFromDynamicReconfigureServer(std::string costmapName, std::string enablePropertyName="enabled")
static std::string getStandardCostmapName(StandardLayers layertype)
bool exists(std::string layerName)
static std::array< std::string, 4 > layerNames
void enable(std::string layerName)
virtual std::string getName() const
Definition client.cpp:42
ISmaccClient * owner_
Definition component.hpp:88
rclcpp::Logger getLogger() const
rclcpp::Node::SharedPtr getNode()