ROSEndEffector
ROS End-Effector package: provides a ROS-based set of standard interfaces to command robotics end-effectors in an agnostic fashion.
EEHal.h
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 #ifndef __ROSEE_EE_HAL__
19 #define __ROSEE_EE_HAL__
20 
21 
22 #include <ros/ros.h>
23 #include <sensor_msgs/JointState.h>
24 
25 #include <string>
26 #include <vector>
27 #include <memory>
28 #include <unordered_map>
29 #include <fstream>
30 
31 #include <Eigen/Dense>
32 #include <yaml-cpp/yaml.h>
33 #include <end_effector/Utils.h>
35 
36 #include <end_effector/UtilsYAML.h>
37 
38 #include <rosee_msg/HandInfo.h>
39 #include <rosee_msg/MotorPhalangePressure.h>
40 
41 //Macro to be used in each concrete HAL that will define the create_object functions
42 #define HAL_CREATE_OBJECT(className) \
43  extern "C" ::ROSEE::EEHal* create_object_##className ( ros::NodeHandle* nh) { \
44  return new className(nh); \
45  } \
46 
47 namespace ROSEE {
48 
49 
54  class EEHal {
55 
56  public:
57 
58  typedef std::shared_ptr<EEHal> Ptr;
59  typedef std::shared_ptr<const EEHal> ConstPtr;
60 
61  EEHal ( ros::NodeHandle* nh );
62  virtual ~EEHal() {};
63 
64  virtual bool sense() = 0;
65 
66  virtual bool move() = 0;
67 
68  virtual bool publish_joint_state();
69 
70  virtual bool checkCommandPub();
71 
72  //virtual bool setMotorPositionReference(std::string motor, double pos) = 0;
73  //virtual bool getJointPosition(std::string joint, std::vector<double> &pos ) = 0;
74 
75  //Matrices needed by Grasp Planner ROSEE
76  virtual bool getFingersNames(std::vector<std::string> &fingers_names);
77  virtual bool getMotorsNames(std::vector<std::string> &motors_names);
78 
79  virtual bool getMotorStiffness(Eigen::VectorXd &motors_stiffness);
80  virtual bool getTipsFrictions(Eigen::VectorXd &tips_friction);
81  virtual bool getMotorTorqueLimits(Eigen::VectorXd &motors_torque_limits);
82  virtual bool getTipJointToTipFrameX(Eigen::VectorXd &tip_joint_to_tip_frame_x);
83  virtual bool getTipJointToTipFrameY(Eigen::VectorXd &tip_joint_to_tip_frame_y);
84 
85  // These are dependent on hand configuration, hence can not be simply parsed by conf file so
86  // each derived HAL must implement them with some logic if they want to use the planne
87  virtual bool getTipsJacobiansNormal(std::unordered_map<std::string, Eigen::MatrixXd>& tips_jacobian_normal) {return false;}
88  virtual bool getTipsJacobiansFriction(std::unordered_map<std::string, Eigen::MatrixXd>& tips_jacobian_friction) {return false;}
89  virtual bool getTransmissionMatrix(Eigen::MatrixXd &transmission_matrix) {return false;}
90  virtual bool getTransmissionSquareMatrices(std::unordered_map<std::string, Eigen::MatrixXd>& transmission_square_matrices) {return false;}
91  virtual bool getTransmissionAugmentedMatrices(std::unordered_map<std::string, Eigen::MatrixXd>& transmission_augmented_matrices) {return false;}
92  virtual bool getTipsForcesNormal(Eigen::VectorXd& tips_forces_normal) {return false;}
93  virtual bool getTipsForcesFriction(Eigen::VectorXd& tips_forces_friction) {return false;}
94 
95  virtual bool parseHandInfo();
96 
97  virtual bool isHandInfoPresent();
98 
103  virtual bool init_hand_info_response() ;
104 
110  virtual bool setHandInfoCallback();
111 
113  bool publish_pressure();
114 
115  Eigen::VectorXd getMotorReference() const;
116  Eigen::VectorXd getJointPosition() const;
117  Eigen::VectorXd getJointEffort() const;
118  Eigen::MatrixXd getPressure() const;
119 
120 
121  protected:
122 
123  ros::NodeHandle* _nh;
124 
129  sensor_msgs::JointState _mr_msg;
130  ros::Subscriber _motor_reference_sub;
131 
136  sensor_msgs::JointState _js_msg;
137  ros::Publisher _joint_state_pub;
138 
139  //Heri specific message
140  bool initPressureSensing();
141  rosee_msg::MotorPhalangePressure _pressure_msg;
142  ros::Publisher _pressure_pub;
143 
144 
145  /**** Hand info matrices***/
146  std::vector <std::string> fingers_names, motors_names;
149 
150  ros::ServiceServer _hand_info_server;
151  rosee_msg::HandInfo::Response _hand_info_response;
153 
154 
155  private:
156 
158 
160  rosee_msg::HandInfo::Request& request,
161  rosee_msg::HandInfo::Response& response);
162 
163 
164  void motor_reference_clbk(const sensor_msgs::JointState::ConstPtr& msg);
165  };
166 }
167 
168 #endif // __ROSEE_EE_HAL__
bool publish_pressure()
Definition: EEHal.cpp:265
ros::Publisher _joint_state_pub
Definition: EEHal.h:137
Eigen::VectorXd motors_stiffness
Definition: EEHal.h:147
std::shared_ptr< EEHal > Ptr
Definition: EEHal.h:58
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 move()=0
virtual bool getTransmissionAugmentedMatrices(std::unordered_map< std::string, Eigen::MatrixXd > &transmission_augmented_matrices)
Definition: EEHal.h:91
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
virtual bool sense()=0
virtual bool publish_joint_state()
Definition: EEHal.cpp:60
virtual bool getTransmissionMatrix(Eigen::MatrixXd &transmission_matrix)
Definition: EEHal.h:89
virtual bool getFingersNames(std::vector< std::string > &fingers_names)
Definition: EEHal.cpp:69
virtual bool getTransmissionSquareMatrices(std::unordered_map< std::string, Eigen::MatrixXd > &transmission_square_matrices)
Definition: EEHal.h:90
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
std::shared_ptr< const EEHal > ConstPtr
Definition: EEHal.h:59
virtual bool getTipsForcesNormal(Eigen::VectorXd &tips_forces_normal)
Definition: EEHal.h:92
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
Class representing an end-effector.
Definition: EEHal.h:54
virtual bool getTipsJacobiansFriction(std::unordered_map< std::string, Eigen::MatrixXd > &tips_jacobian_friction)
Definition: EEHal.h:88
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
virtual bool getTipsForcesFriction(Eigen::VectorXd &tips_forces_friction)
Definition: EEHal.h:93
virtual ~EEHal()
Definition: EEHal.h:62
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
Eigen::VectorXd tip_joint_to_tip_frame_x
Definition: EEHal.h:147
virtual bool getTipsJacobiansNormal(std::unordered_map< std::string, Eigen::MatrixXd > &tips_jacobian_normal)
Definition: EEHal.h:87
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