Skip to content

Commit 8828a43

Browse files
committed
loads URDF model from parameter server
1 parent c3ed998 commit 8828a43

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

ur_robot_driver/include/ur_robot_driver/ros/hardware_interface.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <ur_msgs/SetIO.h>
4646
#include "ur_msgs/SetSpeedSliderFraction.h"
4747

48+
#include <urdf/model.h>
4849
#include <ur_controllers/speed_scaling_interface.h>
4950
#include <ur_controllers/scaled_joint_command_interface.h>
5051

@@ -156,6 +157,13 @@ class HardwareInterface : public hardware_interface::RobotHW
156157
bool shouldResetControllers();
157158

158159
protected:
160+
161+
/*!
162+
* \brief Loads URDF model from robot_description parameter
163+
*
164+
* Requires robot_description paramter to be set on the parameter server
165+
*/
166+
void loadURDF(ros::NodeHandle& nh, std::string param_name);
159167
/*!
160168
* \brief Transforms force-torque measurements reported from the robot from base to tool frame.
161169
*
@@ -223,6 +231,9 @@ class HardwareInterface : public hardware_interface::RobotHW
223231
ur_controllers::ScaledVelocityJointInterface svj_interface_;
224232
hardware_interface::ForceTorqueSensorInterface fts_interface_;
225233

234+
235+
urdf::Model* urdf_model_;
236+
226237
vector6d_t joint_position_command_;
227238
vector6d_t joint_velocity_command_;
228239
vector6d_t joint_positions_;

ur_robot_driver/src/ros/hardware_interface.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ bool HardwareInterface::init(ros::NodeHandle& root_nh, ros::NodeHandle& robot_hw
7272
std::string output_recipe_filename;
7373
std::string input_recipe_filename;
7474

75+
// Load URDF file from parameter server
76+
loadURDF(robot_hw_nh, "robot_description");
77+
7578
// The robot's IP address.
7679
if (!robot_hw_nh.getParam("robot_ip", robot_ip_))
7780
{
@@ -956,6 +959,37 @@ bool HardwareInterface::checkControllerClaims(const std::set<std::string>& claim
956959
}
957960
return false;
958961
}
962+
963+
void HardwareInterface::loadURDF(ros::NodeHandle& nh, std::string param_name)
964+
{
965+
std::string urdf_string;
966+
urdf_model_ = new urdf::Model();
967+
968+
// search and wait for robot_description on param server
969+
while (urdf_string.empty() && ros::ok())
970+
{
971+
std::string search_param_name;
972+
if (nh.searchParam(param_name, search_param_name))
973+
{
974+
ROS_INFO_STREAM("Waiting for model URDF on the ROS param server at location: " << nh.getNamespace()
975+
<< search_param_name);
976+
nh.getParam(search_param_name, urdf_string);
977+
}
978+
else
979+
{
980+
ROS_INFO_STREAM("Waiting for model URDF on the ROS param server at location: " << nh.getNamespace()
981+
<< param_name);
982+
nh.getParam(param_name, urdf_string);
983+
}
984+
985+
usleep(100000);
986+
}
987+
988+
if (!urdf_model_->initString(urdf_string))
989+
ROS_ERROR_STREAM("Unable to load URDF model");
990+
else
991+
ROS_DEBUG_STREAM("Received URDF from param server");
992+
}
959993
} // namespace ur_driver
960994

961995
PLUGINLIB_EXPORT_CLASS(ur_driver::HardwareInterface, hardware_interface::RobotHW)

0 commit comments

Comments
 (0)