/
move_group.cpp
213 lines (186 loc) · 7.63 KB
/
move_group.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
/*********************************************************************
* Software License Agreement (BSD License)
*
* Copyright (c) 2012, Willow Garage, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution.
* * Neither the name of Willow Garage nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*********************************************************************/
/* Author: Ioan Sucan */
#include <moveit/planning_scene_monitor/planning_scene_monitor.h>
#include <tf/transform_listener.h>
#include <moveit/move_group/capability_names.h>
#include <moveit/move_group/move_group_capability.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/tokenizer.hpp>
#include <moveit/macros/console_colors.h>
#include <moveit/move_group/node_name.h>
#include <memory>
#include <set>
static const std::string ROBOT_DESCRIPTION =
"robot_description"; // name of the robot description (a param name, so it can be changed externally)
namespace move_group
{
class MoveGroupExe
{
public:
MoveGroupExe(const planning_scene_monitor::PlanningSceneMonitorPtr& psm, bool debug) : node_handle_("~")
{
// if the user wants to be able to disable execution of paths, they can just set this ROS param to false
bool allow_trajectory_execution;
node_handle_.param("allow_trajectory_execution", allow_trajectory_execution, true);
context_.reset(new MoveGroupContext(psm, allow_trajectory_execution, debug));
// start the capabilities
configureCapabilities();
}
~MoveGroupExe()
{
capabilities_.clear();
context_.reset();
capability_plugin_loader_.reset();
}
void status()
{
if (context_)
{
if (context_->status())
{
if (capabilities_.empty())
printf(MOVEIT_CONSOLE_COLOR_BLUE "\nmove_group is running but no capabilities are "
"loaded.\n\n" MOVEIT_CONSOLE_COLOR_RESET);
else
printf(MOVEIT_CONSOLE_COLOR_GREEN "\nYou can start planning now!\n\n" MOVEIT_CONSOLE_COLOR_RESET);
fflush(stdout);
}
}
else
ROS_ERROR("No MoveGroup context created. Nothing will work.");
}
private:
void configureCapabilities()
{
try
{
capability_plugin_loader_.reset(
new pluginlib::ClassLoader<MoveGroupCapability>("moveit_ros_move_group", "move_group::MoveGroupCapability"));
}
catch (pluginlib::PluginlibException& ex)
{
ROS_FATAL_STREAM("Exception while creating plugin loader for move_group capabilities: " << ex.what());
return;
}
std::set<std::string> capabilities;
// add default capabilities
for (size_t i = 0; i < sizeof(DEFAULT_CAPABILITIES) / sizeof(DEFAULT_CAPABILITIES[0]); ++i)
capabilities.insert(DEFAULT_CAPABILITIES[i]);
// add capabilities listed in ROS parameter
std::string capability_plugins;
if (node_handle_.getParam("capabilities", capability_plugins))
{
boost::char_separator<char> sep(" ");
boost::tokenizer<boost::char_separator<char> > tok(capability_plugins, sep);
capabilities.insert(tok.begin(), tok.end());
}
// drop capabilities that have been explicitly disabled
if (node_handle_.getParam("disable_capabilities", capability_plugins))
{
boost::char_separator<char> sep(" ");
boost::tokenizer<boost::char_separator<char> > tok(capability_plugins, sep);
for (boost::tokenizer<boost::char_separator<char> >::iterator cap_name = tok.begin(); cap_name != tok.end();
++cap_name)
capabilities.erase(*cap_name);
}
for (std::set<std::string>::iterator plugin = capabilities.cbegin(); plugin != capabilities.cend(); ++plugin)
{
try
{
printf(MOVEIT_CONSOLE_COLOR_CYAN "Loading '%s'...\n" MOVEIT_CONSOLE_COLOR_RESET, plugin->c_str());
MoveGroupCapability* cap = capability_plugin_loader_->createUnmanagedInstance(*plugin);
cap->setContext(context_);
cap->initialize();
capabilities_.push_back(MoveGroupCapabilityPtr(cap));
}
catch (pluginlib::PluginlibException& ex)
{
ROS_ERROR_STREAM("Exception while loading move_group capability '"
<< *plugin << "': " << ex.what() << std::endl
<< "Available capabilities: "
<< boost::algorithm::join(capability_plugin_loader_->getDeclaredClasses(), ", "));
}
}
std::stringstream ss;
ss << std::endl;
ss << std::endl;
ss << "********************************************************" << std::endl;
ss << "* MoveGroup using: " << std::endl;
for (std::size_t i = 0; i < capabilities_.size(); ++i)
ss << "* - " << capabilities_[i]->getName() << std::endl;
ss << "********************************************************" << std::endl;
ROS_INFO_STREAM(ss.str());
}
ros::NodeHandle node_handle_;
MoveGroupContextPtr context_;
std::shared_ptr<pluginlib::ClassLoader<MoveGroupCapability> > capability_plugin_loader_;
std::vector<MoveGroupCapabilityPtr> capabilities_;
};
}
int main(int argc, char** argv)
{
ros::init(argc, argv, move_group::NODE_NAME);
ros::AsyncSpinner spinner(1);
spinner.start();
boost::shared_ptr<tf::TransformListener> tf(new tf::TransformListener(ros::Duration(10.0)));
planning_scene_monitor::PlanningSceneMonitorPtr planning_scene_monitor(
new planning_scene_monitor::PlanningSceneMonitor(ROBOT_DESCRIPTION, tf));
if (planning_scene_monitor->getPlanningScene())
{
bool debug = false;
for (int i = 1; i < argc; ++i)
if (strncmp(argv[i], "--debug", 7) == 0)
{
debug = true;
break;
}
if (debug)
ROS_INFO("MoveGroup debug mode is ON");
else
ROS_INFO("MoveGroup debug mode is OFF");
printf(MOVEIT_CONSOLE_COLOR_CYAN "Starting context monitors...\n" MOVEIT_CONSOLE_COLOR_RESET);
planning_scene_monitor->startSceneMonitor();
planning_scene_monitor->startWorldGeometryMonitor();
planning_scene_monitor->startStateMonitor();
printf(MOVEIT_CONSOLE_COLOR_CYAN "Context monitors started.\n" MOVEIT_CONSOLE_COLOR_RESET);
move_group::MoveGroupExe mge(planning_scene_monitor, debug);
planning_scene_monitor->publishDebugInformation(debug);
mge.status();
ros::waitForShutdown();
}
else
ROS_ERROR("Planning scene not configured");
return 0;
}