sr_controller.cpp
Go to the documentation of this file.
1 
27 #include "angles/angles.h"
29 #include <sstream>
30 #include <math.h>
31 #include <string>
33 
34 #include <std_msgs/Float64.h>
35 
36 namespace controller
37 {
38  using std::string;
39 
41  : joint_state_(NULL),
42  joint_state_2(NULL),
43  has_j2(false),
44  command_(0),
45  min_(0.0),
46  max_(sr_math_utils::pi),
47  vel_min_(-1 * sr_math_utils::pi),
48  vel_max_(sr_math_utils::pi),
49  eff_min_(-1023.),
50  eff_max_(1023.),
51  loop_count_(0),
52  initialized_(false),
53  robot_(NULL),
54  n_tilde_("~"),
55  max_force_demand(1023.),
56  friction_deadband(5),
57  max_force_factor_(1.0)
58  {
59  }
60 
62  {
64  }
65 
67  {
68  // joint_name_ has unknown length
69  // it is assumed that last char is the joint number
70  if (joint_name_[joint_name_.size() - 1] == '0')
71  {
72  return true;
73  }
74  return false;
75  }
76 
78  {
79  string j1 = joint_name_, j2 = joint_name_;
80  j1[j1.size() - 1] = '1';
81  j2[j2.size() - 1] = '2';
82 
83  ROS_DEBUG_STREAM("Joint 0: " << j1 << " " << j2);
84 
85  joint_state_ = robot_->getJointState(j1);
86  joint_state_2 = robot_->getJointState(j2);
87  }
88 
90  {
91  sub_command_ = node_.subscribe<std_msgs::Float64>("command", 1, &SrController::setCommandCB, this);
92  sub_max_force_factor_ = node_.subscribe<std_msgs::Float64>("max_force_factor", 1, &SrController::maxForceFactorCB,
93  this);
94  }
95 
97  {
98  return joint_state_->joint_->name;
99  }
100 
101  void SrController::get_min_max(urdf::Model model, std::string joint_name)
102  {
103  if (joint_name_[joint_name.size() - 1] == '0')
104  {
105  joint_name[joint_name.size() - 1] = '1';
106  std::string j1 = joint_name;
107  joint_name[joint_name.size() - 1] = '2';
108  std::string j2 = joint_name;
109 
110  boost::shared_ptr<const urdf::Joint> joint1 = model.getJoint(j1);
111  boost::shared_ptr<const urdf::Joint> joint2 = model.getJoint(j2);
112 
113  min_ = joint1->limits->lower + joint2->limits->lower;
114  max_ = joint1->limits->upper + joint2->limits->upper;
115  vel_max_ = joint1->limits->velocity + joint2->limits->velocity;
116  vel_min_ = -1 * vel_max_;
117  eff_max_ = joint1->limits->effort + joint2->limits->effort;
118  eff_min_ = -1 * eff_max_;
119  }
120  else
121  {
122  boost::shared_ptr<const urdf::Joint> joint = model.getJoint(joint_name);
123 
124  min_ = joint->limits->lower;
125  max_ = joint->limits->upper;
126  vel_max_ = joint->limits->velocity;
127  vel_min_ = -1 * vel_max_;
128  eff_max_ = joint->limits->effort;
129  eff_min_ = -1 * eff_max_;
130  }
131  }
132 
133  double SrController::clamp_command(double cmd, double min_cmd, double max_cmd)
134  {
135  if (cmd < min_cmd)
136  {
137  return min_cmd;
138  }
139  if (cmd > max_cmd)
140  {
141  return max_cmd;
142  }
143  return cmd;
144  }
145 
146  double SrController::clamp_command(double cmd)
147  {
148  return clamp_command(cmd, min_, max_);
149  }
150 
151  void SrController::maxForceFactorCB(const std_msgs::Float64ConstPtr &msg)
152  {
153  if ((msg->data >= 0.0) && (msg->data <= 1.0))
154  {
155  max_force_factor_ = msg->data;
156  }
157  else
158  {
159  ROS_ERROR("Max force factor must be between 0.0 and 1.0. Discarding received value: %f", msg->data);
160  }
161  }
162 } // namespace controller
163 
164 /* For the emacs weenies in the crowd.
165 Local Variables:
166  c-basic-offset: 2
167 End:
168 */
void get_min_max(urdf::Model model, std::string joint_name)
ros_ethercat_model::JointState * joint_state_
ros::Subscriber sub_max_force_factor_
double eff_min_
Min and max range of the effort, used to clamp the command.
Subscriber subscribe(const std::string &topic, uint32_t queue_size, void(T::*fp)(M), T *obj, const TransportHints &transport_hints=TransportHints())
A generic controller for the Shadow Robot EtherCAT hand&#39;s joints.
ros_ethercat_model::JointState * joint_state_2
void maxForceFactorCB(const std_msgs::Float64ConstPtr &msg)
double clamp_command(double cmd, double min_cmd, double max_cmd)
ros::Subscriber sub_command_
ros_ethercat_model::RobotState * robot_
double min_
Min and max range of the joint, used to clamp the command.
double vel_min_
Min and max range of the velocity, used to clamp the command.
#define ROS_DEBUG_STREAM(args)
virtual void setCommandCB(const std_msgs::Float64ConstPtr &msg)
set the command from a topic
#define ROS_ERROR(...)
void after_init()
call this function at the end of the init function in the inheriting classes.


sr_mechanism_controllers
Author(s): Ugo Cupcic
autogenerated on Tue Oct 13 2020 03:55:58