joint_state_listener_node.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, 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 the 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 
36 
39 
40 using namespace std;
41 using namespace ros;
42 using namespace KDL;
43 using namespace robot_state_publisher;
44 
45 int main(int argc, char** argv)
46 {
47  // Initialize ros
48  ros::init(argc, argv, "robot_state_publisher");
49  NodeHandle node;
50 
52  std::string exe_name = argv[0];
53  std::size_t slash = exe_name.find_last_of("/");
54  if (slash != std::string::npos) {
55  exe_name = exe_name.substr(slash + 1);
56  }
57  if (exe_name == "state_publisher") {
58  ROS_WARN("The 'state_publisher' executable is deprecated. Please use 'robot_state_publisher' instead");
59  }
61 
62  // gets the location of the robot description on the parameter server
63  urdf::Model model;
64  if (!model.initParam("robot_description"))
65  return 1;
66 
67  KDL::Tree tree;
68  if (!kdl_parser::treeFromUrdfModel(model, tree)) {
69  ROS_ERROR("Failed to extract kdl tree from xml robot description");
70  return 1;
71  }
72 
73  MimicMap mimic;
74 
75  for(std::map< std::string, urdf::JointSharedPtr >::iterator i = model.joints_.begin(); i != model.joints_.end(); i++) {
76  if(i->second->mimic) {
77  mimic.insert(make_pair(i->first, i->second->mimic));
78  }
79  }
80 
81  JointStateListener state_publisher(tree, mimic, model);
82  ros::spin();
83 
84  return 0;
85 }
KDL_PARSER_PUBLIC bool treeFromUrdfModel(const urdf::ModelInterface &robot_model, KDL::Tree &tree)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
int main(int argc, char **argv)
#define ROS_ERROR(...)
#define ROS_WARN(...)
ROSCPP_DECL void spin()
URDF_EXPORT bool initParam(const std::string &param)
std::map< std::string, urdf::JointMimicSharedPtr > MimicMap


robot_state_publisher
Author(s): Ioan Sucan , Jackie Kay , Wim Meeussen
autogenerated on Mon Feb 28 2022 23:26:24