20 #include <boost/algorithm/string/replace.hpp> 26 const std::string& robot_namespace,
28 gazebo::physics::ModelPtr parent_model,
30 std::vector<transmission_interface::TransmissionInfo> transmissions)
44 n_dof_ = transmissions.size();
64 unsigned int index = 0;
65 for(
unsigned int j=0; j < transmissions.size(); j++)
68 if(transmissions[j].joints_.size() == 0)
71 <<
" has no associated joints.");
74 else if(transmissions[j].joints_.size() > 1)
77 <<
" has more than one joint. Currently the default robot hardware simulation " 78 <<
" interface only supports one.");
82 std::vector<std::string> joint_interfaces = transmissions[j].joints_[0].hardware_interfaces_;
83 if (joint_interfaces.empty() &&
84 !(transmissions[j].actuators_.empty()) &&
85 !(transmissions[j].actuators_[0].hardware_interfaces_.empty()))
88 joint_interfaces = transmissions[j].actuators_[0].hardware_interfaces_;
89 ROS_WARN_STREAM_NAMED(
"hwi_switch_robot_hw_sim",
"The <hardware_interface> element of tranmission " <<
90 transmissions[j].name_ <<
" should be nested inside the <joint> element, not <actuator>. " <<
91 "The transmission will be properly loaded, but please update " <<
92 "your robot model to remain compatible with future versions of the plugin.");
94 if (joint_interfaces.empty())
97 " of transmission " << transmissions[j].name_ <<
" does not specify any hardware interface. " <<
98 "Not adding it to the robot hardware simulation.");
101 else if (joint_interfaces.size() > 1)
104 " of transmission " << transmissions[j].name_ <<
" specifies multiple hardware interfaces. " <<
105 "This feature is now available.");
112 ROS_DEBUG_STREAM_NAMED(
"hwi_switch_robot_hw_sim",
"Found enabled joint '"<<transmissions[j].joints_[0].name_<<
"'; j "<<j<<
"; index: "<<index);
116 ROS_DEBUG_STREAM_NAMED(
"hwi_switch_robot_hw_sim",
"Joint '"<<transmissions[j].joints_[0].name_<<
"' is not enabled; j "<<j<<
"; index: "<<index);
123 ROS_DEBUG_STREAM_NAMED(
"hwi_switch_robot_hw_sim",
"JointFiltering is disabled. Use joint '"<<transmissions[j].joints_[0].name_<<
"'; j "<<j<<
"; index: "<<index);
127 joint_names_[index] = transmissions[j].joints_[0].name_;
144 for(
unsigned int i=0; i<joint_interfaces.size(); i++)
148 <<
"' of type '" << joint_interfaces[i] <<
"'");
152 if(hardware_interface ==
"EffortJointInterface" || hardware_interface ==
"PositionJointInterface" || hardware_interface ==
"VelocityJointInterface") {
153 ROS_WARN_STREAM(
"Deprecated syntax, please prepend 'hardware_interface/' to '" << hardware_interface <<
"' within the <hardwareInterface> tag in joint '" <<
joint_names_[index] <<
"'.");
154 hardware_interface =
"hardware_interface/"+joint_interfaces[i];
158 std::string hw_interface_type = boost::algorithm::replace_all_copy(hardware_interface,
"/",
"::");
161 ROS_DEBUG_STREAM_NAMED(
"hwi_switch_robot_hw_sim",
"HW-Interface " << hw_interface_type <<
" already registered. Adding joint " <<
joint_names_[index] <<
" to list.");
162 std::map< std::string, std::set<std::string> >::iterator it;
169 std::set<std::string> supporting_joints;
174 if(hw_interface_type ==
"hardware_interface::EffortJointInterface")
186 joint_limit_nh, urdf_model,
190 else if(hw_interface_type ==
"hardware_interface::PositionJointInterface")
202 joint_limit_nh, urdf_model,
206 else if(hw_interface_type ==
"hardware_interface::VelocityJointInterface")
218 joint_limit_nh, urdf_model,
225 << hardware_interface );
230 gazebo::physics::JointPtr joint = parent_model->GetJoint(
joint_names_[index]);
234 <<
"\" which is not in the gazebo model.");
241 #if GAZEBO_MAJOR_VERSION >= 8 242 gazebo::physics::PhysicsEnginePtr physics = gazebo::physics::get_world()->Physics();
244 gazebo::physics::PhysicsEnginePtr physics = gazebo::physics::get_world()->GetPhysicsEngine();
259 #if GAZEBO_MAJOR_VERSION > 2 288 std::vector<std::string> joints;
289 if(!nh.
getParam(filter_joints_param, joints))
295 for(std::vector<std::string>::iterator it = joints.begin() ; it != joints.end(); ++it)
304 bool HWISwitchRobotHWSim::canSwitch(
const std::list<hardware_interface::ControllerInfo> &start_list,
const std::list<hardware_interface::ControllerInfo> &stop_list)
const 309 for (std::list<hardware_interface::ControllerInfo>::const_iterator list_it = start_list.begin(); list_it != start_list.end(); ++list_it)
311 for (std::vector<hardware_interface::InterfaceResources>::const_iterator res_it = list_it->claimed_resources.begin(); res_it != list_it->claimed_resources.end(); ++res_it)
313 for(std::set<std::string>::iterator set_it = res_it->resources.begin(); set_it != res_it->resources.end(); ++set_it)
317 ROS_ERROR_STREAM_NAMED(
"hwi_switch_robot_hw_sim",
"Cannot switch because resource \'" << *set_it <<
"\' does not provide HW-Interface \'" << res_it->hardware_interface <<
"\'");
326 void HWISwitchRobotHWSim::doSwitch(
const std::list<hardware_interface::ControllerInfo> &start_list,
const std::list<hardware_interface::ControllerInfo> &stop_list)
329 for (std::list<hardware_interface::ControllerInfo>::const_iterator list_it = start_list.begin(); list_it != start_list.end(); ++list_it)
331 for (std::vector<hardware_interface::InterfaceResources>::const_iterator res_it = list_it->claimed_resources.begin(); res_it != list_it->claimed_resources.end(); ++res_it)
337 if(res_it->resources.find(
joint_names_[i]) != res_it->resources.end())
void registerInterface(T *iface)
std::vector< double > joint_upper_limits_
virtual bool enableJointFiltering(ros::NodeHandle nh, std::string filter_joints_param)
#define ROS_DEBUG_STREAM_NAMED(name, args)
#define ROS_ERROR_STREAM_NAMED(name, args)
joint_limits_interface::PositionJointSoftLimitsInterface pj_limits_interface_
hardware_interface::PositionJointInterface pj_interface_
joint_limits_interface::PositionJointSaturationInterface pj_sat_interface_
std::vector< double > joint_position_command_
std::vector< double > joint_lower_limits_
std::string physics_type_
std::vector< double > joint_position_
std::map< std::string, ControlMethod > map_hwinterface_to_controlmethod_
hardware_interface::VelocityJointInterface vj_interface_
bool enable_joint_filtering_
virtual bool canSwitch(const std::list< hardware_interface::ControllerInfo > &start_list, const std::list< hardware_interface::ControllerInfo > &stop_list) const
virtual bool initSim(const std::string &robot_namespace, ros::NodeHandle model_nh, gazebo::physics::ModelPtr parent_model, const urdf::Model *const urdf_model, std::vector< transmission_interface::TransmissionInfo > transmissions)
virtual void stateValid(const bool active)
hardware_interface::JointStateInterface js_interface_
hardware_interface::EffortJointInterface ej_interface_
std::set< std::string > enabled_joints_
std::vector< double > joint_velocity_
std::vector< std::string > joint_names_
virtual void doSwitch(const std::list< hardware_interface::ControllerInfo > &start_list, const std::list< hardware_interface::ControllerInfo > &stop_list)
std::vector< gazebo::physics::JointPtr > sim_joints_
std::vector< ControlMethod > joint_control_methods_
#define ROS_FATAL_STREAM_NAMED(name, args)
std::vector< int > joint_types_
std::vector< double > joint_effort_
void registerJointLimits(const std::string &joint_name, const hardware_interface::JointHandle &joint_handle, const ControlMethod ctrl_method, const ros::NodeHandle &joint_limit_nh, const urdf::Model *const urdf_model, int *const joint_type, double *const lower_limit, double *const upper_limit, double *const effort_limit)
std::vector< double > joint_effort_command_
#define ROS_WARN_STREAM(args)
void registerHandle(const JointStateHandle &handle)
JointStateHandle getHandle(const std::string &name)
#define ROS_INFO_STREAM(args)
bool getParam(const std::string &key, std::string &s) const
PLUGINLIB_EXPORT_CLASS(transmission_interface::BiDirectionalEffortJointInterfaceProvider, transmission_interface::RequisiteProvider)
std::vector< double > joint_velocity_command_
std::vector< double > joint_effort_limits_
#define ROS_WARN_STREAM_NAMED(name, args)
std::map< std::string, std::set< std::string > > map_hwinterface_to_joints_