35 void appendJoint(
const KDL::SegmentMap::const_iterator segment, std::vector<const KDL::Joint*>& joints) {
36 joints.push_back(&(segment->second.segment.getJoint()));
37 ROS_DEBUG_STREAM(
"append joint: " << segment->second.segment.getJoint().getName() <<
" at " << segment->first <<
", childrensize: " << segment->second.children.size());
38 for (
int i = 0; i < segment->second.children.size(); i++) {
39 appendJoint(segment->second.children[i], joints);
44 std::string robot_description;
45 if (!robot_hw_nh.
getParam(
"robot_description", robot_description)) {
46 ROS_ERROR(
"Failed to get robot_description");
51 ROS_ERROR(
"Failed to parse robot_description");
57 ROS_ERROR(
"Failed to create tree from urdf");
60 KDL::SegmentMap::const_iterator root_segment = tree.
getRootSegment();
61 std::vector<const KDL::Joint*> joints;
62 appendJoint(root_segment->second.children[0], joints);
64 auto new_end = std::remove_if(joints.begin(), joints.end(),
67 joints.erase(new_end, joints.end());
69 int num_joints = joints.size();
70 cmd_.resize(num_joints);
71 pos_.resize(num_joints);
72 vel_.resize(num_joints);
73 eff_.resize(num_joints);
74 a_pos_.resize(num_joints);
75 a_pos_prev_.resize(num_joints);
76 a_vel_.resize(num_joints);
77 a_eff_.resize(num_joints);
78 a_cmd_.resize(num_joints);
80 a_state_data_.resize(num_joints);
81 a_cmd_data_.resize(num_joints);
82 j_state_data_.resize(num_joints);
83 j_cmd_data_.resize(num_joints);
87 for (
int i = 0; i < joints.size(); i++) {
89 jnt_state_interface_.registerHandle(state_handle);
91 j_state_data_[i].position.push_back(&pos_[i]);
92 j_state_data_[i].velocity.push_back(&vel_[i]);
93 j_state_data_[i].effort.push_back(&eff_[i]);
94 a_state_data_[i].position.push_back(&a_pos_[i]);
95 a_state_data_[i].velocity.push_back(&a_vel_[i]);
96 a_state_data_[i].effort.push_back(&a_eff_[i]);
98 registerInterface(&jnt_state_interface_);
101 for (
int i = 0; i < joints.size(); i++) {
102 std::string jointname = joints[i]->getName();
104 jnt_eff_interface_.registerHandle(pos_handle);
106 a_cmd_data_[i].position.push_back(&a_cmd_[i]);
107 j_cmd_data_[i].position.push_back(&cmd_[i]);
123 const bool urdf_limits_ok =
getJointLimits(model.getJoint(jointname), limits);
124 if (!urdf_limits_ok) {
125 ROS_WARN(
"urdf limits int joint %s is not defined", jointname.c_str());
127 const bool urdf_soft_limits_ok =
getSoftJointLimits(model.getJoint(jointname), soft_limits);
128 if (!urdf_soft_limits_ok) {
129 ROS_WARN(
"urdf soft limits int joint %s is not defined", jointname.c_str());
138 jnt_limits_interface_.registerHandle(limits_handle);
140 registerInterface(&jnt_eff_interface_);
142 if (!robot_->initialize(root_nh, num_joints)) {
143 ROS_ERROR(
"failed to initialize denso robot");
147 if(!robot_->read(a_pos_)) {
148 ROS_WARN(
"failed to read joint values from robot");
153 std::copy(a_pos_.begin(), a_pos_.end(), a_pos_prev_.begin());
154 act_to_jnt_state_.propagate();
165 jnt_limits_interface_.enforceLimits(period);
166 jnt_to_act_pos_.propagate();
170 if(!robot_->write(a_cmd_, a_pos_)) {
173 for (
int i = 0; i < a_pos_.size(); i++) {
174 a_vel_[i] = (a_pos_[i] - a_pos_prev_[i])/period.
toSec();
176 act_to_jnt_state_.propagate();
177 std::copy(a_pos_.begin(), a_pos_.end(), a_pos_prev_.begin());
boost::shared_ptr< DensoRobot > robot_
URDF_EXPORT bool initString(const std::string &xmlstring)
SimpleTransmission m_mm_trans_
std::vector< double > vel_
std::string getName(void *handle)
std::vector< double > a_eff_
bool getSoftJointLimits(const std::string &joint_name, const ros::NodeHandle &nh, SoftJointLimits &soft_limits)
std::vector< JointData > j_state_data_
std::vector< double > pos_
std::vector< double > eff_
virtual bool init(ros::NodeHandle &root_nh, ros::NodeHandle &robot_hw_nh)
std::vector< double > a_cmd_
std::vector< ActuatorData > a_state_data_
ActuatorToJointStateInterface act_to_jnt_state_
ros::Duration getPeriod() const
bool getJointLimits(const std::string &joint_name, const ros::NodeHandle &nh, JointLimits &limits)
hardware_interface::JointStateInterface jnt_state_interface_
void write(const ros::Time &time, const ros::Duration &period)
std::vector< double > cmd_
void read(const ros::Time &time, const ros::Duration &period)
ros::Time getTime() const
KDL_PARSER_PUBLIC bool treeFromString(const std::string &xml, KDL::Tree &tree)
void appendJoint(const KDL::SegmentMap::const_iterator segment, std::vector< const KDL::Joint * > &joints)
#define ROS_DEBUG_STREAM(args)
hardware_interface::PositionJointInterface jnt_eff_interface_
std::vector< double > a_pos_prev_
PositionJointSoftLimitsInterface jnt_limits_interface_
SegmentMap::const_iterator getRootSegment() const
JointToActuatorPositionInterface jnt_to_act_pos_
bool getParam(const std::string &key, std::string &s) const
std::vector< ActuatorData > a_cmd_data_
SimpleTransmission raddeg_trans_
std::vector< double > a_vel_
std::vector< JointData > j_cmd_data_