6 double clamp(
const double val,
const double min_val,
const double max_val)
8 return std::min(std::max(val, min_val), max_val);
18 const std::string& robot_namespace,
20 gazebo::physics::ModelPtr parent_model,
22 std::vector<transmission_interface::TransmissionInfo> transmissions)
29 n_dof_ = transmissions.size();
45 for(
unsigned int j=0; j <
n_dof_; j++)
48 if(transmissions[j].joints_.size() == 0)
51 <<
" has no associated joints.");
54 else if(transmissions[j].joints_.size() > 1)
57 <<
" has more than one joint. Currently the default robot hardware simulation " 58 <<
" interface only supports one.");
62 std::vector<std::string> joint_interfaces = transmissions[j].joints_[0].hardware_interfaces_;
63 if (joint_interfaces.empty() &&
64 !(transmissions[j].actuators_.empty()) &&
65 !(transmissions[j].actuators_[0].hardware_interfaces_.empty()))
68 joint_interfaces = transmissions[j].actuators_[0].hardware_interfaces_;
70 transmissions[j].name_ <<
" should be nested inside the <joint> element, not <actuator>. " <<
71 "The transmission will be properly loaded, but please update " <<
72 "your robot model to remain compatible with future versions of the plugin.");
74 if (joint_interfaces.empty())
77 " of transmission " << transmissions[j].name_ <<
" does not specify any hardware interface. " <<
78 "Not adding it to the robot hardware simulation.");
81 else if (joint_interfaces.size() > 1)
84 " of transmission " << transmissions[j].name_ <<
" specifies multiple hardware interfaces. " <<
85 "Currently the default robot hardware simulation interface only supports one. Using the first entry!");
102 <<
"' of type '" << hardware_interface <<
"'");
111 if(hardware_interface ==
"EffortJointInterface" || hardware_interface ==
"hardware_interface/EffortJointInterface")
119 else if(hardware_interface ==
"PositionJointInterface" || hardware_interface ==
"hardware_interface/PositionJointInterface")
127 else if(hardware_interface ==
"VelocityJointInterface" || hardware_interface ==
"hardware_interface/VelocityJointInterface")
135 else if(hardware_interface ==
"PosVelJointInterface" || hardware_interface ==
"hardware_interface/PosVelJointInterface")
146 << hardware_interface );
153 gazebo::physics::JointPtr joint = parent_model->GetJoint(
joint_names_[j]);
157 <<
"\" which is not in the gazebo model.");
163 joint_limit_nh, urdf_model,
169 joint_limit_nh, urdf_model,
180 const ros::NodeHandle nh(model_nh, robot_namespace +
"/gazebo_ros_control/pid_gains/" +
203 #if GAZEBO_MAJOR_VERSION > 2 229 for(
unsigned int j=0; j <
n_dof_; j++)
270 for(
unsigned int j=0; j <
n_dof_; j++)
278 #if GAZEBO_MAJOR_VERSION >= 4 295 #if GAZEBO_MAJOR_VERSION >= 4 307 case urdf::Joint::REVOLUTE:
314 case urdf::Joint::CONTINUOUS:
323 const double effort = clamp(
pid_controllers_[j].computeCommand(error, period),
324 -effort_limit, effort_limit);
340 const double effort = clamp(
pid_controllers_[j].computeCommand(error, period),
341 -effort_limit, effort_limit);
362 int *
const joint_type,
double *
const lower_limit,
363 double *
const upper_limit,
double *
const effort_limit)
365 *joint_type = urdf::Joint::UNKNOWN;
366 *lower_limit = -std::numeric_limits<double>::max();
367 *upper_limit = std::numeric_limits<double>::max();
368 *effort_limit = std::numeric_limits<double>::max();
371 bool has_limits =
false;
373 bool has_soft_limits =
false;
375 if (urdf_model != NULL)
378 if (urdf_joint != NULL)
380 *joint_type = urdf_joint->type;
385 has_soft_limits =
true;
395 if (*joint_type == urdf::Joint::UNKNOWN)
401 *joint_type = urdf::Joint::REVOLUTE;
406 *joint_type = urdf::Joint::CONTINUOUS;
408 *joint_type = urdf::Joint::PRISMATIC;
427 limits_handle(joint_handle, limits, soft_limits);
434 limits_handle(joint_handle, limits, soft_limits);
441 limits_handle(joint_handle, limits, soft_limits);
454 sat_handle(joint_handle, limits);
461 sat_handle(joint_handle, limits);
468 sat_handle(joint_handle, limits);
482 int *
const joint_type,
double *
const lower_limit,
483 double *
const upper_limit,
double *
const effort_limit)
485 *joint_type = urdf::Joint::UNKNOWN;
486 *lower_limit = -std::numeric_limits<double>::max();
487 *upper_limit = std::numeric_limits<double>::max();
488 *effort_limit = std::numeric_limits<double>::max();
491 bool has_limits =
false;
493 bool has_soft_limits =
false;
495 if (urdf_model != NULL)
498 if (urdf_joint != NULL)
500 *joint_type = urdf_joint->type;
505 has_soft_limits =
true;
515 if (*joint_type == urdf::Joint::UNKNOWN)
521 *joint_type = urdf::Joint::REVOLUTE;
526 *joint_type = urdf::Joint::CONTINUOUS;
528 *joint_type = urdf::Joint::PRISMATIC;
void registerInterface(T *iface)
hardware_interface::PosVelJointInterface pvj_interface_
hardware_interface::PositionJointInterface pj_interface_
#define ROS_DEBUG_STREAM_NAMED(name, args)
joint_limits_interface::VelocityJointSaturationInterface vj_sat_interface_
virtual void readSim(ros::Time time, ros::Duration period)
std::vector< double > joint_lower_limits_
joint_limits_interface::PositionJointSoftLimitsInterface pj_limits_interface_
std::vector< double > joint_upper_limits_
virtual bool init(ros::NodeHandle &root_nh, ros::NodeHandle &robot_hw_nh)
std::vector< ControlMethod > joint_control_methods_
joint_limits_interface::EffortJointSoftLimitsInterface ej_limits_interface_
std::vector< double > joint_effort_
joint_limits_interface::PositionJointSaturationInterface pj_sat_interface_
void enforceLimits(const ros::Duration &period)
std::vector< double > joint_effort_command_
std::vector< double > joint_velocity_
hardware_interface::JointStateInterface js_interface_
std::vector< int > joint_types_
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)
bool getSoftJointLimits(urdf::JointConstSharedPtr urdf_joint, SoftJointLimits &soft_limits)
#define ROS_FATAL_STREAM_NAMED(name, args)
virtual void eStopActive(const bool active)
std::vector< double > joint_position_command_
virtual void writeSim(ros::Time time, ros::Duration period)
std::vector< double > joint_position_
hardware_interface::VelocityJointInterface vj_interface_
hardware_interface::EffortJointInterface ej_interface_
joint_limits_interface::EffortJointSaturationInterface ej_sat_interface_
std::vector< gazebo::physics::JointPtr > sim_joints_
std::vector< double > joint_effort_limits_
std::vector< double > last_joint_position_command_
void registerHandle(const JointStateHandle &handle)
std::vector< double > joint_velocity_command_
def shortest_angular_distance_with_limits(from_angle, to_angle, left_limit, right_limit)
JointStateHandle getHandle(const std::string &name)
std::vector< control_toolbox::Pid > pid_controllers_
bool getJointLimits(urdf::JointConstSharedPtr urdf_joint, JointLimits &limits)
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)
joint_limits_interface::VelocityJointSoftLimitsInterface vj_limits_interface_
std::vector< std::string > joint_names_
PLUGINLIB_EXPORT_CLASS(transmission_interface::BiDirectionalEffortJointInterfaceProvider, transmission_interface::RequisiteProvider)
#define ROS_ERROR_STREAM(args)
def shortest_angular_distance(from_angle, to_angle)
#define ROS_WARN_STREAM_NAMED(name, args)