1 #include "header/coordinator.h" 4 int main(
int argc,
char **argv){
7 std::cout <<
"[COORDINATOR] Please insert the two robots name" 11 std::string robotName1 = argv[1];
12 std::string robotName2 = argv[2];
14 if (LOG && (argc > 3)){
18 bool readyRob1 =
false;
19 bool readyRob2 =
false;
21 ros::init (argc, argv,
"Coordinator");
22 std::cout <<
"[COORDINATOR] Start" << std::endl;
27 double goalLinearVectTool[] = {-0.27, -1.102, 9.000};
29 Eigen::Matrix4d wTgoalTool_eigen = Eigen::Matrix4d::Identity();
32 wTgoalTool_eigen.topLeftCorner<3,3>() << 0, -1, 0,
39 wTgoalTool_eigen(0, 3) = goalLinearVectTool[0];
40 wTgoalTool_eigen(1, 3) = goalLinearVectTool[1];
41 wTgoalTool_eigen(2, 3) = goalLinearVectTool[2];
45 std::string topicStart =
"/uwsim/Coord/StartStopBoth";
46 ros::Publisher startBothPub = nh.advertise<std_msgs::Bool>(topicStart, 1);
48 std::string topicCoopVel =
"/uwsim/Coord/CoopVel";
49 ros::Publisher coopVelPub = nh.advertise<geometry_msgs::TwistStamped>(topicCoopVel, 1);
59 std::string toolName =
"pipe";
60 std::string toolName2 =
"pipe2";
62 worldInterface.waitReady(toolName);
63 worldInterface.waitReady(toolName2);
68 Eigen::Matrix<double, VEHICLE_DOF, 1> nonCoopCartVelA_eigen;
69 Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF> admisVelToolA_eigen;
70 Eigen::Matrix<double, VEHICLE_DOF, 1> nonCoopCartVelB_eigen;
71 Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF> admisVelToolB_eigen;
72 Eigen::Matrix<double, VEHICLE_DOF, 1> refTool;
73 Eigen::Matrix<double, VEHICLE_DOF, 1> coopVelToolFeasible;
79 if (pathLog.size() > 0){
80 logger =
Logger(
"Coordinator", pathLog);
81 logger.createDirectoryForNode();
85 boost::asio::io_service io;
90 while(!(readyRob1 && readyRob2)){
91 boost::asio::deadline_timer loopRater(io, boost::posix_time::milliseconds(ms));
92 startBothPub.publish(start);
94 readyRob1 = coordInterfaceA.getReadyRob();
95 readyRob2 = coordInterfaceB.getReadyRob();
100 std::cout <<
"[COORDINATOR] Now both robot are ready" << std::endl;
104 while(readyRob1 && readyRob2){
105 boost::asio::deadline_timer loopRater(io, boost::posix_time::milliseconds(ms));
106 startBothPub.publish(start);
108 bool arrived[4] = {
false,
false,
false,
false};
110 while (arrived[0] ==
false || arrived[1] ==
false || arrived[2] ==
false || arrived[3] ==
false){
111 if (arrived[0] ==
false){
112 arrived[0] = (coordInterfaceA.getNonCoopCartVel(&nonCoopCartVelA_eigen) == 0) ?
true :
false;
114 if (arrived[1] ==
false){
115 arrived[1] = (coordInterfaceA.getJJsharp(&admisVelToolA_eigen) == 0) ?
true :
false;
117 if (arrived[2] ==
false){
118 arrived[2] = (coordInterfaceB.getNonCoopCartVel(&nonCoopCartVelB_eigen) == 0) ?
true :
false;
120 if (arrived[3] ==
false){
121 arrived[3] = (coordInterfaceB.getJJsharp(&admisVelToolB_eigen) == 0) ?
true :
false;
124 boost::asio::deadline_timer loopRater(io, boost::posix_time::milliseconds(1));
135 worldInterface.getwT(&wTt, toolName);
136 refTool = calculateRefTool(wTgoalTool_eigen, wTt);
137 coopVelToolFeasible = execCoordAlgo(nonCoopCartVelA_eigen, admisVelToolA_eigen,
138 nonCoopCartVelB_eigen, admisVelToolB_eigen,
141 std::cout <<
"Calculated coop vel:\n" << coopVelToolFeasible <<
"\n\n";
143 publishCoopVel(coopVelPub, coopVelToolFeasible);
147 if (pathLog.size() != 0){
148 Eigen::Matrix4d wTt2;
149 worldInterface.getwT(&wTt2, toolName2);
157 std::cout <<
"[COORDINATOR] Now one robot is not ready anymore" << std::endl;
163 Eigen::Matrix<double, VEHICLE_DOF, 1> execCoordAlgo(
164 Eigen::Matrix<double, VEHICLE_DOF, 1> nonCoopCartVelA_eigen,
165 Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF> admisVelToolA_eigen,
166 Eigen::Matrix<double, VEHICLE_DOF, 1> nonCoopCartVelB_eigen,
167 Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF> admisVelToolB_eigen,
168 Eigen::Matrix<double, VEHICLE_DOF, 1> refTool,
174 double muA = muZero + ((refTool-nonCoopCartVelA_eigen).norm());
175 double muB = muZero + ((refTool-nonCoopCartVelB_eigen).norm());
179 Eigen::Matrix<double, VEHICLE_DOF, 1> coopVelTool;
180 coopVelTool = (1 / (muA + muB)) *
181 ( (muA * nonCoopCartVelA_eigen) + (muB * nonCoopCartVelB_eigen) );
184 Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF> constraintMat;
185 constraintMat = (admisVelToolA_eigen - admisVelToolB_eigen);
188 Eigen::Matrix<double, VEHICLE_DOF, 1> coopVelToolFeasible;
189 Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF> eye =
190 Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF>::Identity();
192 coopVelToolFeasible = ( eye - (FRM::pseudoInverse(constraintMat) * constraintMat) )
196 logger->logNumbers(muA,
"weightA");
197 logger->logNumbers(muB,
"weightB");
198 logger->logNumbers(coopVelTool,
"notFeasibleCoopVel");
199 logger->logNumbers(nonCoopCartVelA_eigen,
"nonCoopVelg500_A");
200 logger->logNumbers(nonCoopCartVelB_eigen,
"nonCoopVelg500_B");
201 logger->logNumbers(coopVelToolFeasible,
"coopVel");
202 logger->logNumbers(refTool,
"idealTool");
205 return coopVelToolFeasible;
209 Eigen::Matrix<double, VEHICLE_DOF, 1> calculateRefTool(Eigen::Matrix4d wTgoaltool_eigen,
210 Eigen::Matrix4d wTtool_eigen){
212 CMAT::TransfMatrix wTgoaltool_cmat = CONV::matrix_eigen2cmat(wTgoaltool_eigen);
213 CMAT::TransfMatrix wTtool_cmat = CONV::matrix_eigen2cmat(wTtool_eigen);
216 CMAT::Vect6 errorSwapped = CMAT::CartError(wTgoaltool_cmat, wTtool_cmat);
220 Eigen::Matrix<double, VEHICLE_DOF, 1> reference;
221 reference(0) = errorSwapped(4);
222 reference(1) = errorSwapped(5);
223 reference(2) = errorSwapped(6);
224 reference(3) = errorSwapped(1);
225 reference(4) = errorSwapped(2);
226 reference(5) = errorSwapped(3);
230 reference.topRows(3) = FRM::saturateVectorEigen(reference.topRows(3), 0.3);
231 reference.bottomRows(3) = FRM::saturateVectorEigen(reference.bottomRows(3), 0.1);
238 void publishCoopVel(ros::Publisher coopVelPub, Eigen::Matrix<double, VEHICLE_DOF, 1> coopVel){
240 geometry_msgs::TwistStamped msg;
241 msg.twist.linear.x = coopVel(0);
242 msg.twist.linear.y = coopVel(1);
243 msg.twist.linear.z = coopVel(2);
244 msg.twist.angular.x = coopVel(3);
245 msg.twist.angular.y = coopVel(4);
246 msg.twist.angular.z = coopVel(5);
248 coopVelPub.publish(msg);
The CoordInterfaceCoord class.
The WorldInterface class to get position from world to anything else.
void logCartError(Eigen::Matrix4d goal, Eigen::Matrix4d base, std::string fileName)
Logger::logCartError log cartesian error for two frames The result is the error that brings in2 towar...