1 #include "header/robotInterface.h" 9 robotInterface::robotInterface(std::string robotName, std::string topicRoot,
int argc,
char **argv)
12 ROS_INFO(
"[ROS_INTERFACE] Start");
13 ros::init(argc, argv,
"robotInterface");
16 this->robotName = robotName;
17 this->topicRoot = topicRoot;
19 pubTwist = nh.advertise<geometry_msgs::TwistStamped>((topicRoot +
"twist_command_A"),1);
20 pubJoint = nh.advertise<sensor_msgs::JointState>((topicRoot +
"joint_command_A"),1);
22 subJointState = nh.subscribe(topicRoot+
"joint_state_A", 1, &robotInterface::subJointStateCallback,
this);
26 int robotInterface::init(){
33 std::string topic =
"/" + robotName;
34 tfListener_wTv.waitForTransform(
"world", topic, ros::Time(0), ros::Duration(3.0));
38 while (jState_priv.size()==0){
46 int robotInterface::getwTv(Eigen::Matrix4d* wTv_eigen){
52 tf::StampedTransform wTv_tf;
54 std::string topic =
"/" + robotName;
56 tfListener_wTv.lookupTransform(
"world", topic, ros::Time(0), wTv_tf);
58 }
catch (tf::TransformException &ex) {
59 ROS_ERROR(
"%s",ex.what());
60 ros::Duration(1.0).sleep();
63 *wTv_eigen = CONV::transfMatrix_tf2eigen(wTv_tf);
68 int robotInterface::getvTee(Eigen::Matrix4d* vTee_eigen){
73 tf::StampedTransform vTee_tf;
75 std::string topic1 =
"/" + robotName;
76 std::string topic2 =
"/" + robotName +
"/part4_base";
78 tfListener_wTv.lookupTransform(topic1, topic2, ros::Time(0), vTee_tf);
80 }
catch (tf::TransformException &ex) {
81 ROS_ERROR(
"%s",ex.what());
82 ros::Duration(1.0).sleep();
85 *vTee_eigen = CONV::transfMatrix_tf2eigen(vTee_tf);
91 int robotInterface::getvTjoints(std::vector<Eigen::Matrix4d> *vTjoints) {
96 std::vector<tf::StampedTransform> vTJoints_tf(ARM_DOF);
98 std::string topic1 =
"/" + robotName;
100 for(
int i=0; i<ARM_DOF; i++){
101 std::ostringstream s;
103 const std::string si(s.str());
104 std::string topic2 = topic1+
"/part" + si;
108 tfListener_wTv.lookupTransform(topic1, topic2, ros::Time(0), vTJoints_tf[i]);
112 }
catch (tf::TransformException &ex) {
113 ROS_ERROR(
"%s",ex.what());
114 ros::Duration(1.0).sleep();
117 for(
int i=0; i<ARM_DOF; i++){
118 vTjoints->push_back(CONV::transfMatrix_tf2eigen(vTJoints_tf[i]));
125 void robotInterface::subJointStateCallback(
const sensor_msgs::JointState& js)
127 jState_priv = js.position;
136 int robotInterface::getJointState(std::vector<double> *jState){
142 *jState = jState_priv;
147 int robotInterface::sendyDot(std::vector<double> yDot){
152 sensor_msgs::JointState js;
153 js.name.push_back(std::string(
"Slew"));
154 js.velocity.push_back(yDot.at(0));
155 js.name.push_back(std::string(
"Shoulder"));
156 js.velocity.push_back(yDot.at(1));
157 js.name.push_back(std::string(
"Elbow"));
158 js.velocity.push_back(yDot.at(2));
159 js.name.push_back(std::string(
"JawRotate"));
160 js.velocity.push_back(yDot.at(3));
161 geometry_msgs::TwistStamped twist;
162 twist.twist.linear.x=yDot.at(4);
163 twist.twist.linear.y=yDot.at(5);
164 twist.twist.linear.z=yDot.at(6);
165 twist.twist.angular.x=yDot.at(7);
166 twist.twist.angular.y=yDot.at(8);
167 twist.twist.angular.z=yDot.at(9);
169 pubJoint.publish(js);
170 pubTwist.publish(twist);
175 void robotInterface::spinOnce(){