38 #include <std_msgs/Float64.h> 48 SrhJointVariablePidPositionController::SrhJointVariablePidPositionController()
49 : position_deadband_(0.015)
66 std::string robot_state_name;
67 node_.
param<std::string>(
"robot_state_name", robot_state_name,
"unique_robot_hw");
71 robot_ = robot->getHandle(robot_state_name).getState();
75 ROS_ERROR_STREAM(
"Could not find robot state: " << robot_state_name <<
" Not loading the controller. " <<
110 ROS_ERROR(
"SrhJointVariablePidPositionController could not find the first joint relevant to \"%s\"\n",
116 ROS_ERROR(
"SrhJointVariablePidPositionController could not find the second joint relevant to \"%s\"\n",
122 ROS_ERROR(
"Joint %s not calibrated for SrhJointVariablePidPositionController",
joint_name_.c_str());
135 ROS_ERROR(
"SrhJointVariablePidPositionController could not find joint named \"%s\"\n",
joint_name_.c_str());
140 ROS_ERROR(
"Joint %s not calibrated for SrhJointVariablePidPositionController",
joint_name_.c_str());
173 sr_robot_msgs::SetPidGains::Response &resp)
175 ROS_INFO_STREAM(
"Setting new PID parameters. P:" << req.p <<
" / I:" << req.i <<
176 " / D:" << req.d <<
" / IClamp:" << req.i_clamp <<
", max force: " <<
177 req.max_force <<
", friction deadband: " << req.friction_deadband <<
178 " pos deadband: " << req.deadband);
232 double set_point_velocity = diff_set_point *
frequency_;
234 double error_velocity = diff_error *
frequency_;
236 double exp_error = exp(fabs(error));
237 double exp_log_error_velocity = exp(log10(error_velocity));
239 double p =
p_init_ * (exp_error + exp_log_error_velocity + set_point_velocity);
240 double i =
i_init_ * (exp_error + exp_log_error_velocity + set_point_velocity);
241 double d =
d_init_ * (exp_error + exp_log_error_velocity + set_point_velocity);
282 double error_position = 0.0;
283 double commanded_effort = 0.0;
299 error_position = 0.0;
308 commanded_effort = max(commanded_effort, -(
max_force_demand * max_force_factor_));
317 static_cast<int>(commanded_effort),
324 static_cast<int>(commanded_effort),
void get_min_max(urdf::Model model, std::string joint_name)
virtual const char * what() const
ros_ethercat_model::JointState * joint_state_
void setCommandCB(const std_msgs::Float64ConstPtr &msg)
set the position target from a topic
double position_deadband_
the position deadband value used in the hysteresis_deadband
void read_parameters()
read all the controller settings from the parameter server
virtual bool resetGains(std_srvs::Empty::Request &req, std_srvs::Empty::Response &resp)
double smoothing_factor_p_
boost::scoped_ptr< realtime_tools::RealtimePublisher< control_msgs::JointControllerState > > controller_state_publisher_
virtual void updatePid(double, double)
ServiceServer advertiseService(const std::string &service, bool(T::*srv_func)(MReq &, MRes &), T *obj)
double smoothing_factor_i_
ros_ethercat_model::JointState * joint_state_2
double p_init_
initial PID parameters
boost::scoped_ptr< sr_friction_compensation::SrFrictionCompensator > friction_compensator
double clamp_command(double cmd, double min_cmd, double max_cmd)
ros_ethercat_model::RobotState * robot_
bool setGains(sr_robot_msgs::SetPidGains::Request &req, sr_robot_msgs::SetPidGains::Response &resp)
boost::scoped_ptr< PlainPid > pid_controller_position_
Internal PID controller for the position loop.
virtual void getGains(double &p, double &i, double &d, double &i_max, double &i_min)
int friction_deadband
the deadband for the friction compensation algorithm
bool param(const std::string ¶m_name, T ¶m_val, const T &default_val) const
virtual void starting(const ros::Time &time)
const std::string & getNamespace() const
double smoothing_velocity_min_
bool init(ros_ethercat_model::RobotStateInterface *robot, ros::NodeHandle &n)
double smoothing_velocity_max_
bool is_in_deadband(T demand, T error, T deadband, double deadband_multiplicator=5.0, unsigned int nb_errors_for_avg=50)
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
double max_force_demand
clamps the force demand to this value
void get_joints_states_1_2()
#define ROS_INFO_STREAM(args)
virtual void update(const ros::Time &time, const ros::Duration &period)
Issues commands to the joint. Should be called at regular intervals.
bool getParam(const std::string &key, std::string &s) const
ros::ServiceServer serve_set_gains_
#define ROS_ERROR_STREAM(args)
sr_deadband::HysteresisDeadband< double > hysteresis_deadband
We're using an hysteresis deadband.
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
void setParam(const std::string &key, const XmlRpc::XmlRpcValue &v) const
double smoothing_factor_d_
void after_init()
call this function at the end of the init function in the inheriting classes.
ros::ServiceServer serve_reset_gains_