fake_joint_driver.cpp
Go to the documentation of this file.
1 
10 #include <ros/ros.h>
11 #include <urdf/model.h>
15 
17 {
18  ros::NodeHandle pnh("~");
19  std::set<std::string> joint_set;
20  std::map<std::string, double> start_position_map;
21 
22  // Read parameters
23  pnh.param<bool>("use_robot_description", use_description_, true);
24  pnh.getParam("include_joints", include_joints_);
25  pnh.getParam("exclude_joints", exclude_joints_);
26  pnh.getParam("start_position", start_position_map);
27 
28  for (auto it=start_position_map.begin(); it!=start_position_map.end(); it++)
29  {
30  ROS_DEBUG_STREAM("start_position: " << it->first << ": " << it->second);
31  }
32 
33  for (auto i=0; i<include_joints_.size(); i++)
34  {
35  ROS_DEBUG_STREAM("include_joint[" << i << "]" << include_joints_[i]);
36  }
37  for (auto i=0; i<exclude_joints_.size(); i++)
38  {
39  ROS_DEBUG_STREAM("exclude_joint[" << i << "]" << exclude_joints_[i]);
40  }
41  // Read all joints in robot_description
42  if (use_description_)
43  {
44  urdf::Model urdf_model;
45  if (urdf_model.initParam("robot_description"))
46  {
47  for (auto it=urdf_model.joints_.begin(); it!=urdf_model.joints_.end(); it++)
48  {
49  urdf::Joint joint = *it->second;
50  // remove fixed and unknown joints
51  if (joint.type == urdf::Joint::FIXED || joint.type == urdf::Joint::UNKNOWN)
52  {
53  continue;
54  }
55  joint_set.insert(joint.name);
56  }
57  }
58  else
59  {
60  ROS_WARN("We cannot find the parameter robot_description.");
61  }
62  }
63  // Include joints into joint_set
64  for (auto i=0; i< include_joints_.size(); i++)
65  {
66  joint_set.insert(include_joints_[i]);
67  }
68  // Exclude joints in joint_set
69  for (auto i=0; i< exclude_joints_.size(); i++)
70  {
71  joint_set.erase(exclude_joints_[i]);
72  }
73  // Convert to vector (joint_names_)
74  std::copy(joint_set.begin(), joint_set.end(), std::back_inserter(joint_names_));
75  // Check the emptyness of joints
76  if (joint_names_.size() == 0) {
77  ROS_ERROR("No joints is specified. Please use include_joints parameters.");
78  ros::shutdown();
79  }
80  // Resize members
81  cmd_dis.resize(joint_names_.size());
82  act_dis.resize(joint_names_.size());
83  act_vel.resize(joint_names_.size());
84  act_eff.resize(joint_names_.size());
85 
86  // Set start position
87  for (auto it=start_position_map.begin(); it!=start_position_map.end(); it++)
88  {
89  for (auto i=0; i<joint_names_.size(); i++)
90  {
91  if (joint_names_[i] == it->first)
92  {
93  act_dis[i] = it->second;
94  cmd_dis[i] = it->second;
95  }
96  }
97  }
98 
99  // Create joint_state_interface and position_joint_interface
100  for (int i = 0; i< joint_names_.size(); i++)
101  {
102  ROS_DEBUG_STREAM("joint[" << i << "]:" << joint_names_[i]);
103  // Connect and register the joint_state_interface
106 
107  // Connect and register the position_joint_interface
110  }
113 }
114 
116 {
117 }
118 
123 {
124  // only do loopback
125  act_dis = cmd_dis;
126 }
127 
std::vector< std::string > joint_names_
std::vector< double > act_eff
std::vector< double > act_dis
std::vector< double > cmd_dis
#define ROS_WARN(...)
std::vector< double > act_vel
bool param(const std::string &param_name, T &param_val, const T &default_val) const
hardware_interface::PositionJointInterface position_joint_interface
hardware_interface::JointStateInterface joint_state_interface
URDF_EXPORT bool initParam(const std::string &param)
#define ROS_DEBUG_STREAM(args)
void registerHandle(const JointStateHandle &handle)
JointStateHandle getHandle(const std::string &name)
void update(void)
Update function to call all of the update function of motors.
std::vector< std::string > exclude_joints_
bool getParam(const std::string &key, std::string &s) const
ROSCPP_DECL void shutdown()
#define ROS_ERROR(...)
std::vector< std::string > include_joints_


fake_joint_driver
Author(s): Ryosuke Tajima
autogenerated on Thu Dec 19 2019 03:31:40