1 #include "header/coordInterfaceCoord.h" 3 CoordInterfaceCoord::CoordInterfaceCoord(ros::NodeHandle nh, std::string robotNameA,
4 std::string robotNameB){
6 this->robotNameA = robotNameA;
7 this->robotNameB = robotNameB;
9 std::cout <<
"[COORDINATOR][COORD_INTERFACE] Start" << std::endl;
13 std::string topicReadyA =
"/uwsim/" + robotNameA+
"_MissionManager" +
"/ready";
14 readyRobASub = nh.subscribe(topicReadyA, 1, &CoordInterfaceCoord::readyRobASubCallback,
this);
15 std::string topicReadyB =
"/uwsim/" + robotNameB+
"_MissionManager" +
"/ready";
16 readyRobBSub = nh.subscribe(topicReadyB, 1, &CoordInterfaceCoord::readyRobBSubCallback,
this);
19 std::string topicCoordFromMMA =
"/uwsim/" + robotNameA +
"_MissionManager/toCoord";
20 subCoordFromMMA = nh.subscribe(topicCoordFromMMA, 1, &CoordInterfaceCoord::subCoordFromMMACallBack,
this);
21 std::string topicCoordFromMMB =
"/uwsim/" + robotNameB +
"_MissionManager/toCoord";
22 subCoordFromMMB = nh.subscribe(topicCoordFromMMB, 1, &CoordInterfaceCoord::subCoordFromMMBCallBack,
this);
29 std::string topicStart =
"/uwsim/Coord/StartStopBoth";
30 startBothPub = nh.advertise<std_msgs::Bool>(topicStart, 1);
32 std::string topicCoopVel =
"/uwsim/Coord/CoopVel";
33 coopVelPub = nh.advertise<geometry_msgs::TwistStamped>(topicCoopVel, 1);
37 subForceTorque = nh.subscribe(
"/uwsim/g500_A/forceSensorPeg", 1, &CoordInterfaceCoord::subForceTorqueCallback,
this);
38 vectorForce.resize(3, 0.0);
39 vectorTorque.resize(3, 0.0);
40 std::string updateGoalTopic =
"/uwsim/Coord/updatedGoal";
42 pubUpdateGoal = nh.advertise<peg_msgs::transformMat>(updateGoalTopic, 1);
46 bool CoordInterfaceCoord::getReadyBothRob(){
47 return (CoordInterfaceCoord::getReadyRobA()
48 && CoordInterfaceCoord::getReadyRobB());
51 bool CoordInterfaceCoord::getReadyRobA(){
52 return this->readyRobA;
54 bool CoordInterfaceCoord::getReadyRobB(){
55 return this->readyRobB;
74 Eigen::Matrix<double, VEHICLE_DOF, 1> *nonCoopCartVelA,
75 Eigen::Matrix<double, VEHICLE_DOF, 1> *nonCoopCartVelB,
76 Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF> *admisVelToolA,
77 Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF> *admisVelToolB){
85 return1 = CoordInterfaceCoord::getNonCoopCartVel(nonCoopCartVelA, robotNameA);
89 return2 = CoordInterfaceCoord::getNonCoopCartVel(nonCoopCartVelB, robotNameB);
93 return3 = CoordInterfaceCoord::getJJsharp(admisVelToolA, robotNameA);
96 return4 = CoordInterfaceCoord::getJJsharp(admisVelToolB, robotNameB);
99 if (return1 == -1 || return2 ==-1 || return3 ==-1 || return4 ==-1){
102 if (return1 == -2 || return2 ==-2 || return3 ==-2 || return4 ==-2){
106 int counter = return1+return2+return3+return4;
113 readJJsharpA =
false;
114 readJJsharpB =
false;
121 void CoordInterfaceCoord::publishStartBoth(
bool start){
123 std_msgs::Bool start_msg;
124 start_msg.data = start;
125 startBothPub.publish(start_msg);
129 void CoordInterfaceCoord::publishCoopVel(Eigen::Matrix<double, VEHICLE_DOF, 1> coopVel){
131 geometry_msgs::TwistStamped msg;
132 msg.twist.linear.x = coopVel(0);
133 msg.twist.linear.y = coopVel(1);
134 msg.twist.linear.z = coopVel(2);
135 msg.twist.angular.x = coopVel(3);
136 msg.twist.angular.y = coopVel(4);
137 msg.twist.angular.z = coopVel(5);
139 coopVelPub.publish(msg);
153 int CoordInterfaceCoord::getNonCoopCartVel(
154 Eigen::Matrix<double, VEHICLE_DOF, 1> *nonCoopCartVel_eigen,
155 std::string robotName){
158 std::vector<double> *tempXdot;
160 if (robotName.compare(robotNameA) == 0){
161 vectSize = tempXdotA.size();
162 tempXdot = &tempXdotA;
165 }
else if (robotName.compare(robotNameB) == 0){
166 vectSize = tempXdotB.size();
167 tempXdot = &tempXdotB;
180 if (vectSize != VEHICLE_DOF){
181 std::cout <<
"[COORDINATOR][COORD_INTERFACE] ERROR:" 182 <<
"something wrong with dimension of xDot_tool received from " 183 << robotName << std::endl;
187 for (
int i=0; i<vectSize; i++){
188 (*nonCoopCartVel_eigen)(i,0) = tempXdot->at(i);
206 int CoordInterfaceCoord::getJJsharp(
207 Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF> *admisVelTool_eigen,
208 std::string robotName){
212 std::vector<double> *tempJJsharp;
214 if (robotName.compare(robotNameA) == 0){
215 nSize = tempJJsharpA.size();
216 tempJJsharp = &tempJJsharpA;
217 read = &readJJsharpA;
218 }
else if (robotName.compare(robotNameB) == 0){
219 nSize = tempJJsharpB.size();
220 tempJJsharp = &tempJJsharpB;
221 read = &readJJsharpB;
234 if (nSize != VEHICLE_DOF*VEHICLE_DOF){
243 for (
int i=0; i<VEHICLE_DOF; i++){
244 for (
int j=0; j<VEHICLE_DOF; j++){
245 posRow = i*VEHICLE_DOF;
246 (*admisVelTool_eigen)(i,j) = tempJJsharp->at(posRow + j);
250 tempJJsharp->clear();
256 void CoordInterfaceCoord::readyRobASubCallback(
const std_msgs::Bool::ConstPtr& start){
257 readyRobA = start->data;
259 void CoordInterfaceCoord::readyRobBSubCallback(
const std_msgs::Bool::ConstPtr& start){
260 readyRobB = start->data;
272 void CoordInterfaceCoord::subCoordFromMMACallBack(
const peg_msgs::toCoord::ConstPtr& msg){
276 tempXdotA.at(0) = msg->xDot.twist.linear.x;
277 tempXdotA.at(1) = msg->xDot.twist.linear.y;
278 tempXdotA.at(2) = msg->xDot.twist.linear.z;
279 tempXdotA.at(3) = msg->xDot.twist.angular.x;
280 tempXdotA.at(4) = msg->xDot.twist.angular.y;
281 tempXdotA.at(5) = msg->xDot.twist.angular.z;
285 tempJJsharpA.resize(msg->JJsharp.layout.dim[0].stride);
286 tempJJsharpA = msg->JJsharp.data;
298 void CoordInterfaceCoord::subCoordFromMMBCallBack(
const peg_msgs::toCoord::ConstPtr& msg){
302 tempXdotB.at(0) = msg->xDot.twist.linear.x;
303 tempXdotB.at(1) = msg->xDot.twist.linear.y;
304 tempXdotB.at(2) = msg->xDot.twist.linear.z;
305 tempXdotB.at(3) = msg->xDot.twist.angular.x;
306 tempXdotB.at(4) = msg->xDot.twist.angular.y;
307 tempXdotB.at(5) = msg->xDot.twist.angular.z;
311 tempJJsharpB.resize(msg->JJsharp.layout.dim[0].stride);
312 tempJJsharpB = msg->JJsharp.data;
316 int CoordInterfaceCoord::getForceTorque(Eigen::Vector3d *force, Eigen::Vector3d *torque){
318 *force = CONV::vector_std2Eigen(vectorForce);
319 *torque = CONV::vector_std2Eigen(vectorTorque);
324 void CoordInterfaceCoord::subForceTorqueCallback(
const geometry_msgs::WrenchStamped& msg){
326 vectorForce.at(0) = msg.wrench.force.x;
327 vectorForce.at(1) = msg.wrench.force.y;
328 vectorForce.at(2) = msg.wrench.force.z;
330 vectorTorque.at(0) = msg.wrench.torque.x;
331 vectorTorque.at(1) = msg.wrench.torque.y;
332 vectorTorque.at(2) = msg.wrench.torque.z;
336 void CoordInterfaceCoord::publishUpdatedGoal(Eigen::Matrix4d wTgoal){
345 peg_msgs::transformMat transfMsg;
346 transfMsg.linPosition.vector.x = wTgoal(0,3);
347 transfMsg.linPosition.vector.y = wTgoal(1,3);
348 transfMsg.linPosition.vector.z = wTgoal(2,3);
351 transfMsg.rotation.resize(9);
352 transfMsg.rotation.at(0).data = wTgoal(0,0);
353 transfMsg.rotation.at(1).data = wTgoal(1,0);
354 transfMsg.rotation.at(2).data = wTgoal(2,0);
355 transfMsg.rotation.at(3).data = wTgoal(0,1);
356 transfMsg.rotation.at(4).data = wTgoal(1,1);
357 transfMsg.rotation.at(5).data = wTgoal(2,1);
358 transfMsg.rotation.at(6).data = wTgoal(0,2);
359 transfMsg.rotation.at(7).data = wTgoal(1,2);
360 transfMsg.rotation.at(8).data = wTgoal(2,2);
362 pubUpdateGoal.publish(transfMsg);
int getMatricesFromRobs(Eigen::Matrix< double, VEHICLE_DOF, 1 > *nonCoopCartVelA, Eigen::Matrix< double, VEHICLE_DOF, 1 > *nonCoopCartVelB, Eigen::Matrix< double, VEHICLE_DOF, VEHICLE_DOF > *admisVelToolA, Eigen::Matrix< double, VEHICLE_DOF, VEHICLE_DOF > *admisVelToolB)
CoordInterfaceCoord::getMatricesFromRobs get all matrices needed to algorithm The function call each ...