ROSEndEffector
ROS End-Effector package: provides a ROS-based set of standard interfaces to command robotics end-effectors in an agnostic fashion.
EEHal.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2019 IIT-HHCM
3  * Author: Luca Muratore
4  * email: luca.muratore@iit.it
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16 */
17 
18 #include <end_effector/HAL/EEHal.h>
19 
20 ROSEE::EEHal::EEHal(ros::NodeHandle* nh) {
21 
22  _nh = nh;
23 
24  //init sub to receive reference from UniversalROSEEEX
25  //TODO take topic name from roslaunch
26  std::string motor_reference_topic = "/ros_end_effector/motor_reference_pos";
27 
28  _motor_reference_sub = _nh->subscribe(motor_reference_topic, 10,
30 
31  std::string joint_state_topic = "/ros_end_effector/joint_states";
32 
33  _joint_state_pub = _nh->advertise<sensor_msgs::JointState>(joint_state_topic, 10);
34 
36 
37  if (_hand_info_present) {
38  _hand_info_service_name = "hand_info";
39  }
40 
41  _pressure_active = false; // if a derived class want to use this, it must call initPressureSensing()
42 
43 
44 
45 }
46 
48 
49  return (_motor_reference_sub.getNumPublishers() > 0 && _mr_msg.name.size() != 0);
50 }
51 
53 
54 void ROSEE::EEHal::motor_reference_clbk(const sensor_msgs::JointState::ConstPtr& msg) {
55 
56  _mr_msg = *msg;
57 
58 }
59 
61 
62  //NOTE _js_msg must be filled by the derived class
63  _joint_state_pub.publish(_js_msg);
64 
65  return true;
66 
67 }
68 
69 bool ROSEE::EEHal::getFingersNames(std::vector<std::string> &fingers_names){
70 
71  if (this->fingers_names.size() != 0) {
72 
73  fingers_names = this->fingers_names;
74  return true;
75 
76  } else {
77  return false;
78  }
79 
80 }
81 bool ROSEE::EEHal::getMotorsNames(std::vector<std::string> &motors_names){
82 
83  if (this->motors_names.size() != 0) {
84 
85  motors_names = this->motors_names;
86  return true;
87 
88  } else {
89  return false;
90  }
91 
92 }
93 
95 
96  if (this->motors_stiffness.size() != 0) {
97 
98  motors_stiffness = this->motors_stiffness;
99  return true;
100 
101  } else {
102  return false;
103  }
104 
105 }
106 
108 
109  if (this->tips_frictions.size() != 0) {
110 
111  tips_frictions = this->tips_frictions;
112  return true;
113 
114  } else {
115  return false;
116  }
117 
118 }
119 
121 
122  if (this->motors_torque_limits.size() != 0) {
123 
124  motors_torque_limits = this->motors_torque_limits;
125  return true;
126 
127  } else {
128  return false;
129  }
130 
131 }
132 
134 
135  if (this->tip_joint_to_tip_frame_x.size() != 0) {
136 
137  tip_joint_to_tip_frame_x = this->tip_joint_to_tip_frame_x;
138  return true;
139 
140  } else {
141  return false;
142  }
143 }
144 
146 
147  if (this->tip_joint_to_tip_frame_y.size() != 0) {
148 
149  tip_joint_to_tip_frame_y = this->tip_joint_to_tip_frame_y;
150  return true;
151 
152  } else {
153  return false;
154  }
155 }
156 
158 
159  std::string _rosee_config_path;
160  if (! _nh->getParam ( "/ros_ee_config_path", _rosee_config_path )) {
161  return false;
162  }
163 
164  std::ifstream ifile(_rosee_config_path);
165  if (! ifile) {
166  ROS_WARN_STREAM ("EEHALExecutor: config file " << _rosee_config_path << " not found");
167  return false;
168  }
169 
170  YAML::Node node = YAML::LoadFile(_rosee_config_path);
171 
172  if (! node["hand_info"]) {
173  ROS_WARN_STREAM ("EEHALExecutor: config file " << _rosee_config_path << " does not contain "
174  << "hand_info node. I will not parse hand information");
175 
176  return false;
177  }
178 
179  if(node["hand_info"]["fingers_names"]){
180 
181  fingers_names = node["hand_info"]["fingers_names"].as<std::vector<std::string>>();
182  }
183 
184  if(node["hand_info"]["motors_names"]){
185 
186  motors_names = node["hand_info"]["motors_names"].as<std::vector<std::string>>();
187  }
188 
189  if(node["hand_info"]["motors_stiffness"]){
190 
191  motors_stiffness = ROSEE::Utils::yamlVectorToEigen(node["hand_info"]["motors_stiffness"]);
192  }
193 
194  if(node["hand_info"]["tips_frictions"]){
195 
196  tips_frictions = ROSEE::Utils::yamlVectorToEigen(node["hand_info"]["tips_frictions"]);
197  }
198 
199  if(node["hand_info"]["motors_torque_limits"]){
200 
201  motors_torque_limits = ROSEE::Utils::yamlVectorToEigen(node["hand_info"]["motors_torque_limits"]);
202  }
203 
204  if(node["hand_info"]["tip_joint_to_tip_frame_x"]){
205 
206  tip_joint_to_tip_frame_x = ROSEE::Utils::yamlVectorToEigen(node["hand_info"]["tip_joint_to_tip_frame_x"]);
207  }
208 
209  if(node["hand_info"]["tip_joint_to_tip_frame_y"]){
210 
211  tip_joint_to_tip_frame_y = ROSEE::Utils::yamlVectorToEigen(node["hand_info"]["tip_joint_to_tip_frame_y"]);
212  }
213 
214  return true;
215 }
216 
218 
219  _hand_info_response.fingers_names = fingers_names;
220 
221  _hand_info_response.motors_names = motors_names;
222 
223  _hand_info_response.motors_stiffness =
225 
226  _hand_info_response.tips_frictions =
228 
229  _hand_info_response.motors_torque_limits =
231 
232  return true;
233 }
234 
236 
237  _hand_info_server = _nh->advertiseService(_hand_info_service_name,
239  return true;
240 }
241 
243  rosee_msg::HandInfo::Request& request,
244  rosee_msg::HandInfo::Response& response) {
245 
246  //generic hal does not read the request
247 
248  response = _hand_info_response;
249 
250  return true;
251 }
252 
254 {
255 
256  std::string topic_name = "/ros_end_effector/pressure_phalanges";
257 
258  _pressure_pub = _nh->advertise<rosee_msg::MotorPhalangePressure>(topic_name, 10);
259 
260  _pressure_active = true;
261 
262  return true;
263 }
264 
266 
267  //NOTE _pressure_msg must be filled by the derived class
268  _pressure_pub.publish(_pressure_msg);
269 
270  return true;
271 
272 }
273 
274 Eigen::VectorXd ROSEE::EEHal::getMotorReference() const {
275 
276  Eigen::VectorXd motorRef;
277  motorRef.resize(_mr_msg.name.size());
278  for (int i=0; i<_mr_msg.name.size(); i++ ) {
279 
280  motorRef(i) = _mr_msg.position.at(i);
281  }
282 
283  return motorRef;
284 }
285 
286 Eigen::VectorXd ROSEE::EEHal::getJointPosition() const {
287 
288  Eigen::VectorXd jointPos;
289  jointPos.resize(_js_msg.name.size());
290  for (int i=0; i<_js_msg.name.size(); i++ ) {
291 
292  jointPos(i) = _js_msg.position.at(i);
293  }
294 
295  return jointPos;
296 }
297 
298 Eigen::VectorXd ROSEE::EEHal::getJointEffort() const {
299 
300  Eigen::VectorXd jointEffort;
301  jointEffort.resize(_js_msg.name.size());
302  for (int i=0; i<_js_msg.name.size(); i++ ) {
303 
304  jointEffort(i) = _js_msg.effort.at(i);
305  }
306 
307  return jointEffort;
308 }
309 
310 Eigen::MatrixXd ROSEE::EEHal::getPressure() const {
311 
312  Eigen::MatrixXd pressure;
313  pressure.resize(4, _pressure_msg.pressure_finger1.size()); //message has 4 finger field
314  for (int i=0; i<_pressure_msg.pressure_finger1.size(); i++ ) {
315 
316  pressure(0, i) = _pressure_msg.pressure_finger1.at(i);
317  pressure(1, i) = _pressure_msg.pressure_finger2.at(i);
318  pressure(2, i) = _pressure_msg.pressure_finger3.at(i);
319  pressure(3, i) = _pressure_msg.pressure_thumb.at(i);
320  }
321 
322  return pressure;
323 
324 }
bool publish_pressure()
Definition: EEHal.cpp:265
Eigen::VectorXd motors_stiffness
Definition: EEHal.h:147
ros::Publisher _joint_state_pub
Definition: EEHal.h:137
Eigen::VectorXd getJointEffort() const
Definition: EEHal.cpp:298
virtual bool getMotorsNames(std::vector< std::string > &motors_names)
Definition: EEHal.cpp:81
sensor_msgs::JointState _mr_msg
The references that must be read in the move() to send to the real/simulated robot TODO put private a...
Definition: EEHal.h:129
Eigen::VectorXd tip_joint_to_tip_frame_y
Definition: EEHal.h:147
virtual bool checkCommandPub()
Definition: EEHal.cpp:47
bool initPressureSensing()
Definition: EEHal.cpp:253
Eigen::VectorXd tips_frictions
Definition: EEHal.h:147
bool _pressure_active
Definition: EEHal.h:112
std::vector< std::string > fingers_names
Definition: EEHal.h:146
EEHal(ros::NodeHandle *nh)
Definition: EEHal.cpp:20
static std::vector< float > eigenVectorToStdVector(Eigen::VectorXd eigenVector)
Definition: UtilsEigen.h:58
virtual bool publish_joint_state()
Definition: EEHal.cpp:60
virtual bool getFingersNames(std::vector< std::string > &fingers_names)
Definition: EEHal.cpp:69
void motor_reference_clbk(const sensor_msgs::JointState::ConstPtr &msg)
Definition: EEHal.cpp:54
ros::NodeHandle * _nh
Definition: EEHal.h:123
virtual bool getTipsFrictions(Eigen::VectorXd &tips_friction)
Definition: EEHal.cpp:107
virtual bool getTipJointToTipFrameX(Eigen::VectorXd &tip_joint_to_tip_frame_x)
Definition: EEHal.cpp:133
rosee_msg::MotorPhalangePressure _pressure_msg
Definition: EEHal.h:141
bool _hand_info_present
Definition: EEHal.h:157
std::vector< std::string > motors_names
Definition: EEHal.h:146
virtual bool getMotorTorqueLimits(Eigen::VectorXd &motors_torque_limits)
Definition: EEHal.cpp:120
ros::Publisher _pressure_pub
Definition: EEHal.h:142
ros::Subscriber _motor_reference_sub
Definition: EEHal.h:130
virtual bool getTipJointToTipFrameY(Eigen::VectorXd &tip_joint_to_tip_frame_y)
Definition: EEHal.cpp:145
Eigen::VectorXd getMotorReference() const
Definition: EEHal.cpp:274
std::string _hand_info_service_name
Definition: EEHal.h:152
Eigen::VectorXd motors_torque_limits
Definition: EEHal.h:147
rosee_msg::HandInfo::Response _hand_info_response
Definition: EEHal.h:151
virtual bool init_hand_info_response()
init the service message with info parsed from yaml file, ie info that will not change according to h...
Definition: EEHal.cpp:217
bool handInfoEEHalCallback(rosee_msg::HandInfo::Request &request, rosee_msg::HandInfo::Response &response)
Definition: EEHal.cpp:242
sensor_msgs::JointState _js_msg
The states that must be filled in the sense(), reading info from real/simulated robot TODO put privat...
Definition: EEHal.h:136
virtual bool isHandInfoPresent()
Definition: EEHal.cpp:52
virtual bool getMotorStiffness(Eigen::VectorXd &motors_stiffness)
Definition: EEHal.cpp:94
Eigen::MatrixXd getPressure() const
Definition: EEHal.cpp:310
static Eigen::VectorXd yamlVectorToEigen(const YAML::Node &vectorNode)
Definition: UtilsYAML.h:37
Eigen::VectorXd tip_joint_to_tip_frame_x
Definition: EEHal.h:147
virtual bool parseHandInfo()
Definition: EEHal.cpp:157
virtual bool setHandInfoCallback()
Here service is advertise and callback set: if derived class wants to use different callback...
Definition: EEHal.cpp:235
ros::ServiceServer _hand_info_server
Definition: EEHal.h:150
Eigen::VectorXd getJointPosition() const
Definition: EEHal.cpp:286