initialize_demo_db.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2012, Willow Garage, Inc.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of Willow Garage nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  *********************************************************************/
34 
35 /* Author: Ioan Sucan */
36 
43 #include <boost/algorithm/string/join.hpp>
44 #include <boost/program_options/cmdline.hpp>
45 #include <boost/program_options/options_description.hpp>
46 #include <boost/program_options/parsers.hpp>
47 #include <boost/program_options/variables_map.hpp>
48 #include <boost/math/constants/constants.hpp>
49 #include <ros/ros.h>
50 
51 static const std::string ROBOT_DESCRIPTION = "robot_description";
52 
53 int main(int argc, char** argv)
54 {
55  ros::init(argc, argv, "initialize_demo_db", ros::init_options::AnonymousName);
56 
57  boost::program_options::options_description desc;
58  desc.add_options()("help", "Show help message")("host", boost::program_options::value<std::string>(),
59  "Host for the "
60  "DB.")("port", boost::program_options::value<std::size_t>(),
61  "Port for the DB.");
62 
63  boost::program_options::variables_map vm;
64  boost::program_options::store(boost::program_options::parse_command_line(argc, argv, desc), vm);
65  boost::program_options::notify(vm);
66 
67  if (vm.count("help"))
68  {
69  std::cout << desc << std::endl;
70  return 1;
71  }
72  // Set up db
74  if (vm.count("host") && vm.count("port"))
75  conn->setParams(vm["host"].as<std::string>(), vm["port"].as<std::size_t>());
76  if (!conn->connect())
77  return 1;
78 
80  spinner.start();
81 
82  ros::NodeHandle nh;
84  if (!psm.getPlanningScene())
85  {
86  ROS_ERROR("Unable to initialize PlanningSceneMonitor");
87  return 1;
88  }
89 
93  pss.reset();
94  cs.reset();
95  rs.reset();
96 
97  // add default planning scenes
98  moveit_msgs::PlanningScene psmsg;
99  psm.getPlanningScene()->getPlanningSceneMsg(psmsg);
100  psmsg.name = "default";
101  pss.addPlanningScene(psmsg);
102  ROS_INFO("Added default scene: '%s'", psmsg.name.c_str());
103 
104  moveit_msgs::RobotState rsmsg;
105  robot_state::robotStateToRobotStateMsg(psm.getPlanningScene()->getCurrentState(), rsmsg);
106  rs.addRobotState(rsmsg, "default");
107  ROS_INFO("Added default state");
108 
109  const std::vector<std::string>& gnames = psm.getRobotModel()->getJointModelGroupNames();
110  for (std::size_t i = 0; i < gnames.size(); ++i)
111  {
112  const robot_model::JointModelGroup* jmg = psm.getRobotModel()->getJointModelGroup(gnames[i]);
113  if (!jmg->isChain())
114  continue;
115  const std::vector<std::string>& lnames = jmg->getLinkModelNames();
116  if (lnames.empty())
117  continue;
118 
119  moveit_msgs::OrientationConstraint ocm;
120  ocm.link_name = lnames.back();
121  ocm.header.frame_id = psm.getRobotModel()->getModelFrame();
122  ocm.orientation.x = 0.0;
123  ocm.orientation.y = 0.0;
124  ocm.orientation.z = 0.0;
125  ocm.orientation.w = 1.0;
126  ocm.absolute_x_axis_tolerance = 0.1;
127  ocm.absolute_y_axis_tolerance = 0.1;
128  ocm.absolute_z_axis_tolerance = boost::math::constants::pi<double>();
129  ocm.weight = 1.0;
130  moveit_msgs::Constraints cmsg;
131  cmsg.orientation_constraints.resize(1, ocm);
132  cmsg.name = ocm.link_name + ":upright";
133  cs.addConstraints(cmsg, psm.getRobotModel()->getName(), jmg->getName());
134  ROS_INFO("Added default constraint: '%s'", cmsg.name.c_str());
135  }
136  ROS_INFO("Default MoveIt! Warehouse was reset.");
137 
138  ros::shutdown();
139 
140  return 0;
141 }
void addRobotState(const moveit_msgs::RobotState &msg, const std::string &name, const std::string &robot="")
void addConstraints(const moveit_msgs::Constraints &msg, const std::string &robot="", const std::string &group="")
static const std::string ROBOT_DESCRIPTION
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
const robot_model::RobotModelConstPtr & getRobotModel() const
#define ROS_ERROR(...)
void spinner()
const planning_scene::PlanningScenePtr & getPlanningScene()
warehouse_ros::DatabaseConnection::Ptr loadDatabase()
Load a database connection.
#define ROS_INFO(...)
void addPlanningScene(const moveit_msgs::PlanningScene &scene)
ROSCPP_DECL void shutdown()
int main(int argc, char **argv)


warehouse
Author(s): Ioan Sucan
autogenerated on Fri Aug 20 2021 03:01:32