SMACC
Loading...
Searching...
No Matches
cp_costmap_switch.cpp
Go to the documentation of this file.
2
3namespace cl_move_base_z
4{
5
6std::array<std::string, 4>
8 {
9 "global_costmap/obstacles_layer",
10 "local_costmap/obstacles_layer"
11 "global_costmap/inflater_layer",
12 "local_costmap/inflater_layer"};
13
14void CostmapSwitch::registerProxyFromDynamicReconfigureServer(std::string costmapName, std::string enablePropertyName)
15{
16 ROS_INFO("[CostmapSwitch] registering costmap type: %s", costmapName.c_str());
17 auto proxy = std::make_shared<CostmapProxy>(this->moveBaseClient_->name_ + "/" + costmapName, enablePropertyName);
18 costmapProxies[costmapName] = proxy;
19}
20
22{
23}
24
26{
27 this->moveBaseClient_ = dynamic_cast<cl_move_base_z::ClMoveBaseZ *>(owner_);
28
29 if (this->moveBaseClient_ == nullptr)
30 {
31 ROS_ERROR("the owner of the CostmapSwitch must be a ClMoveBaseZ");
32 }
33
38}
39
41{
42 return CostmapSwitch::layerNames[(int)layertype];
43}
44
45bool CostmapSwitch::exists(std::string layerName)
46{
47 if (!this->costmapProxies.count(layerName))
48 {
49 return false;
50 }
51
52 return true;
53}
54
55void CostmapSwitch::enable(std::string layerName)
56{
57 ROS_INFO("[CostmapSwitch] enabling %s", layerName.c_str());
58
59 if (!exists(layerName))
60 {
61 ROS_ERROR("[CostmapSwitch] costmap %s does not exist", layerName.c_str());
62 return;
63 }
64 else
65 {
66 ROS_INFO("[CostmapSwitch] costmap %s found. Calling dynamic reconfigure server.", layerName.c_str());
67 costmapProxies[layerName]->setCostmapEnabled(true);
68 }
69}
70
72{
73 this->enable(getStandardCostmapName(layerType));
74}
75
76void CostmapSwitch::disable(std::string layerName)
77{
78 ROS_INFO("[CostmapSwitch] disabling %s", layerName.c_str());
79
80 if (!exists(layerName))
81 {
82 ROS_ERROR("[CostmapSwitch] costmap %s does not exist", layerName.c_str());
83 return;
84 }
85 else
86 {
87 ROS_INFO("[CostmapSwitch] costmap %s found. Calling dynamic reconfigure server.", layerName.c_str());
88 costmapProxies[layerName]->setCostmapEnabled(false);
89 }
90}
91
93{
94 this->disable(getStandardCostmapName(layerType));
95}
96
97//-------------------------------------------------------------------------
98
99CostmapProxy::CostmapProxy(std::string costmap_name, std::string enablePropertyName)
100{
101 this->costmapName_ = costmap_name + "/set_parameters";
102 dynamic_reconfigure::BoolParameter enableField;
103 enableField.name = "enabled";
104 enableField.value = true;
105
106 enableReq.bools.push_back(enableField);
107
108 enableField.value = false;
109 disableReq.bools.push_back(enableField);
110}
111
113{
114 dynamic_reconfigure::ReconfigureRequest srv_req;
115 dynamic_reconfigure::ReconfigureResponse srv_resp;
116
117 if (value)
118 srv_req.config = enableReq;
119 else
120 srv_req.config = disableReq;
121
122 if (ros::service::exists(costmapName_, true))
123 {
124 ROS_INFO("sending dynamic reconfigure request: %s", costmapName_.c_str());
125 ros::service::call(costmapName_, srv_req, srv_resp);
126 }
127 else
128 {
129 ROS_WARN("could not call dynamic reconfigure server. It does not exist: %s", costmapName_.c_str());
130 }
131}
132
133void CostmapProxy::dynreconfCallback(const dynamic_reconfigure::Config::ConstPtr &configuration_update)
134{
135 // auto gp = std::find_if(configuration_update->strs.begin(), configuration_update->strs.begin(),
136 // [&](const dynamic_reconfigure::StrParameter &p) { return p.name == "base_global_planner" && p.value == desired_global_planner_; });
137}
138}
dynamic_reconfigure::Config disableReq
void dynreconfCallback(const dynamic_reconfigure::Config::ConstPtr &configuration_update)
CostmapProxy(std::string costmap_name, std::string enablePropertyName)
dynamic_reconfigure::Config enableReq
void registerProxyFromDynamicReconfigureServer(std::string costmapName, std::string enablePropertyName="enabled")
std::map< std::string, std::shared_ptr< CostmapProxy > > costmapProxies
static std::string getStandardCostmapName(StandardLayers layertype)
cl_move_base_z::ClMoveBaseZ * moveBaseClient_
void enable(std::string layerName)
virtual void onInitialize() override
bool exists(std::string layerName)
static std::array< std::string, 4 > layerNames
void disable(std::string layerName)
ISmaccClient * owner_
Definition: component.h:57