ROSEndEffector
ROS End-Effector package: provides a ROS-based set of standard interfaces to command robotics end-effectors in an agnostic fashion.
XBot2Hal.cpp
Go to the documentation of this file.
2 
3 
4 ROSEE::XBot2Hal::XBot2Hal( ros::NodeHandle* nh ) : EEHal ( nh ) {
5 
6  //little HACK to be sure xbot is ready and gazebo is unpaused (this service is on after xbot2-core
7  // is on AND gazebo is unpaused
8  ROS_INFO_STREAM("[XBot2Hal constructor]: wait for xbot2core and gazebo to be ready...");
9  ros::service::waitForService("/xbotcore/ros_ctrl/switch", -1);
10  ROS_INFO_STREAM("[XBot2Hal constructor]: xbot2core and gazebo ready!");
11 
12  //We call the xbot service to command the hand through ros
13 // std_srvs::SetBool serviceMsg;
14 // serviceMsg.request.data = true;
15 // ros::ServiceClient client = nh->serviceClient<std_srvs::SetBool>("/xbotcore/ros_ctrl/switch");
16 //
17 // if (client.call(serviceMsg) ) {
18 //
19 //
20 //
21 // if (!serviceMsg.response.success){
22 // ROS_ERROR_STREAM("[XBot2Hal constructor]: Failed to call /xbotcore/ros_ctrl/switch with error message: " << serviceMsg.response.message << ". Aborting");
23 // exit(-1);
24 // }
25 // ROS_INFO_STREAM("[XBot2Hal constructor]: Succesfully called /xbotcore/ros_ctrl/switch");
26 //
27 // } else {
28 // ROS_ERROR_STREAM("[XBot2Hal constructor]: Failed to call /xbotcore/ros_ctrl/switch. Aborting");
29 // exit(-1);
30 // }
31 
32 
33  std::string path_to_config_file = XBot::Utils::getXBotConfig();
34 
35  _robot = XBot::RobotInterface::getRobot(path_to_config_file);
36 
37  _mr_msg.name.resize(_robot->getJointNum());
38  _mr_msg.position.resize(_robot->getJointNum());
39  _js_msg.name.resize(_robot->getJointNum());
40  _js_msg.position.resize(_robot->getJointNum());
41  _js_msg.velocity.resize(_robot->getJointNum());
42  _js_msg.effort.resize(_robot->getJointNum());
43 
44 }
45 
46 
48  if (! _robot->sense()){
49  return false;
50  }
51  _robot->getJointPosition(_jointPositionActualMap);
52  if (_js_msg.name.size() != _jointPositionActualMap.size() ||
53  _js_msg.position.size() != _jointPositionActualMap.size()) {
54 
55  ROS_ERROR_STREAM("[XBot2Hal::" << __func__ << "] size of _js_msg is different from the size" <<
56  " or what received from the robot (_jointPositionActualMap)");
57  return false;
58  }
59 
60  int i = 0;
61  for (auto it : _jointPositionActualMap ) {
62 
63  //TODO it is better to fill the names only once in the costructor?
64  _js_msg.name.at(i) = it.first;
65  _js_msg.position.at(i) = it.second;
66  i++;
67  }
68 
69  return true;
70 }
71 
73 
74  //NOTE if robot does not move, check if "rosservice call /xbotcore/ros_ctrl/switch 1"
75  for (int i=0; i<_mr_msg.position.size(); i++) {
76 
77  _jointPositionReferenceMap[_mr_msg.name.at(i)] = _mr_msg.position.at(i);
78  }
79 
80  if (! _robot->setPositionReference(_jointPositionReferenceMap)) {
81  return false;
82  }
83 
84  return _robot->move();
85 }
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
XBot2Hal(ros::NodeHandle *nh)
Definition: XBot2Hal.cpp:4
XBot::JointNameMap _jointPositionActualMap
Definition: XBot2Hal.h:37
XBot::RobotInterface::Ptr _robot
Definition: XBot2Hal.h:36
Class representing an end-effector.
Definition: EEHal.h:54
XBot::JointNameMap _jointPositionReferenceMap
Definition: XBot2Hal.h:38
virtual bool sense() override
Definition: XBot2Hal.cpp:47
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 move() override
Definition: XBot2Hal.cpp:72