srh_syntouch_controllers.cpp
Go to the documentation of this file.
1 
26 #include "../example/srh_syntouch_controllers.hpp"
27 #include "angles/angles.h"
29 #include <string>
30 #include <sstream>
31 #include <math.h>
33 #include <std_msgs/Float64.h>
34 
36 
37 namespace controller
38 {
39 
40  SrhSyntouchController::SrhSyntouchController()
41  : SrController()
42  {
43  }
44 
46  {
48  }
49 
50  bool SrhSyntouchController::init(ros_ethercat_model::RobotStateInterface *robot, ros::NodeHandle &n)
51  {
52  ROS_ASSERT(robot);
53 
54  std::string robot_state_name;
55  node_.param<std::string>("robot_state_name", robot_state_name, "unique_robot_hw");
56 
57  try
58  {
59  robot_ = robot->getHandle(robot_state_name).getState();
60  }
62  {
63  ROS_ERROR_STREAM("Could not find robot state: " << robot_state_name << " Not loading the controller. " <<
64  e.what());
65  return false;
66  }
67 
68  node_ = n;
69 
70  if (!node_.getParam("joint", joint_name_))
71  {
72  ROS_ERROR("No joint given (namespace: %s)", node_.getNamespace().c_str());
73  return false;
74  }
75 
76  ROS_DEBUG(" --------- ");
77  ROS_DEBUG_STREAM("Init: " << joint_name_);
78 
79  joint_state_ = robot_->getJointState(joint_name_);
80  if (!joint_state_)
81  {
82  ROS_ERROR("SrhMixedPositionVelocityController could not find joint named \"%s\"\n",
83  joint_name_.c_str());
84  return false;
85  }
86  if (!joint_state_->calibrated_)
87  {
88  ROS_ERROR("Joint %s not calibrated for SrhSyntouchController", joint_name_.c_str());
89  return false;
90  }
91 
92  // init the pointer to the biotacs data, updated at 1kHz
93  actuator_ = static_cast<sr_actuator::SrMotorActuator *>(robot_->getActuator(joint_name_));
94 
95  after_init();
96  return true;
97  }
98 
99 
101  {
102  command_ = joint_state_->position_;
103 
104  ROS_WARN_STREAM("Reseting PID for joint " << joint_state_->joint_->name);
105  }
106 
107  void SrhSyntouchController::update(const ros::Time &time, const ros::Duration &period)
108  {
109  if (!joint_state_->calibrated_)
110  {
111  return;
112  }
113 
115  ROS_ASSERT(joint_state_->joint_);
116 
117  if (initialized_)
118  {
119  command_ = joint_state_->commanded_position_;
120  }
121  else
122  {
123  initialized_ = true;
124  command_ = joint_state_->position_;
125  }
126 
128  // POSITION
129 
130  // Compute position error:
131  double error_position = command_ - joint_state_->position_;
132 
134  // TACTILES
135 
136  // you have access here to the whole data coming from the 5 tactiles at full speed.
137  double my_first_finger_tactile_pac = actuator_->motor_state_.tactiles_->at(0).biotac.get_pac().back();
138  if (loop_count_ % 10 == 0)
139  {
140  ROS_ERROR_STREAM("PAC, tactile " << my_first_finger_tactile_pac);
141  }
142 
144  // EFFORT
145 
146  // Compute the commanded effort to send to the motor
147  double commanded_effort = 0.0;
148  // @todo compute the force demand by combining the information you
149  // want. You can have a look at the mixed controller to see a
150  // working implementation of a controller using different pid loops.
151 
152  joint_state_->commanded_effort_ = commanded_effort;
153 
154  if (loop_count_ % 10 == 0)
155  {
157  {
158  controller_state_publisher_->msg_.header.stamp = time;
159  controller_state_publisher_->msg_.set_point = command_;
160 
161  controller_state_publisher_->msg_.process_value = joint_state_->position_;
162  controller_state_publisher_->msg_.process_value_dot = joint_state_->velocity_;
163 
164  controller_state_publisher_->msg_.error = error_position;
165  controller_state_publisher_->msg_.time_step = period.toSec();
166 
167  controller_state_publisher_->msg_.command = commanded_effort;
168  controller_state_publisher_->msg_.measured_effort = joint_state_->effort_;
169 
170  controller_state_publisher_->unlockAndPublish();
171  }
172  }
173  loop_count_++;
174  }
175 } // namespace controller
176 
177 /* For the emacs weenies in the crowd.
178 Local Variables:
179  c-basic-offset: 2
180 End:
181 */
182 
183 
ros_ethercat_model::JointState * joint_state_
boost::scoped_ptr< realtime_tools::RealtimePublisher< sr_robot_msgs::JointControllerState > > controller_state_publisher_
virtual void update(const ros::Time &time, const ros::Duration &period)
Issues commands to the joint. Should be called at regular intervals.
ros::Subscriber sub_command_
ros_ethercat_model::RobotState * robot_
sr_actuator::SrMotorActuator * actuator_
bool init(ros_ethercat_model::RobotStateInterface *robot, ros::NodeHandle &n)
virtual void starting(const ros::Time &time)
bool param(const std::string &param_name, T &param_val, const T &default_val) const
const std::string & getNamespace() const
#define ROS_WARN_STREAM(args)
#define ROS_DEBUG_STREAM(args)
std::vector< tactiles::AllTactileData > * tactiles_
bool getParam(const std::string &key, std::string &s) const
#define ROS_ERROR_STREAM(args)
#define ROS_ASSERT(cond)
#define PLUGINLIB_EXPORT_CLASS(class_type, base_class_type)
#define ROS_ERROR(...)
SrMotorActuatorState motor_state_
void after_init()
call this function at the end of the init function in the inheriting classes.
#define ROS_DEBUG(...)


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