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 robotNameA = argv[1];
12 std::string robotNameB = argv[2];
14 if (LOG && (argc > 3)){
18 bool readyBothRob =
false;
20 ros::init (argc, argv,
"Coordinator");
21 std::cout <<
"[COORDINATOR] Start" << std::endl;
26 double goalLinearVectTool[] = {-0.27, -1.102, 9.000};
28 Eigen::Matrix4d wTgoalTool_eigen = Eigen::Matrix4d::Identity();
31 wTgoalTool_eigen.topLeftCorner<3,3>() << 0, 1, 0,
38 wTgoalTool_eigen(0, 3) = goalLinearVectTool[0];
39 wTgoalTool_eigen(1, 3) = goalLinearVectTool[1];
40 wTgoalTool_eigen(2, 3) = goalLinearVectTool[2];
48 std::string toolName =
"pipe";
49 std::string toolName2 =
"pipe2";
51 worldInterface.waitReady(toolName);
52 worldInterface.waitReady(toolName2);
56 Eigen::Matrix<double, VEHICLE_DOF, 1> nonCoopCartVelA_eigen;
57 Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF> admisVelToolA_eigen;
58 Eigen::Matrix<double, VEHICLE_DOF, 1> nonCoopCartVelB_eigen;
59 Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF> admisVelToolB_eigen;
60 Eigen::Matrix<double, VEHICLE_DOF, 1> refTool;
61 Eigen::Matrix<double, VEHICLE_DOF, 1> coopVelToolFeasible;
67 if (pathLog.size() > 0){
68 logger =
Logger(
"Coordinator", pathLog);
69 logger.createDirectoryForNode();
73 boost::asio::io_service io;
77 while(!(readyBothRob)){
78 boost::asio::deadline_timer loopRater(io, boost::posix_time::milliseconds(ms));
79 coordInterface.publishStartBoth(
false);
81 readyBothRob = coordInterface.getReadyBothRob();
86 std::cout <<
"[COORDINATOR] Now both robot are ready" << std::endl;
89 boost::asio::deadline_timer loopRater(io, boost::posix_time::milliseconds(ms));
90 coordInterface.publishStartBoth(
true);
95 returned = coordInterface.getMatricesFromRobs(&nonCoopCartVelA_eigen, &nonCoopCartVelB_eigen, &admisVelToolA_eigen, &admisVelToolB_eigen);
97 std::cout <<
"[COORDINATOR] ERROR in the dimension of mesage arrived from robots" << std::endl;
101 std::cout <<
"[COORDINATOR] ERROR in the name of robots" << std::endl;
105 boost::asio::deadline_timer loopRater(io, boost::posix_time::milliseconds(1));
116 worldInterface.getwT(&wTt, toolName);
117 refTool = calculateRefTool(wTgoalTool_eigen, wTt);
118 coopVelToolFeasible = execCoordAlgo(nonCoopCartVelA_eigen, admisVelToolA_eigen,
119 nonCoopCartVelB_eigen, admisVelToolB_eigen,
122 std::cout <<
"Calculated coop vel:\n" << coopVelToolFeasible <<
"\n\n";
124 coordInterface.publishCoopVel(coopVelToolFeasible);
128 if (pathLog.size() != 0){
129 Eigen::Matrix4d wTt2;
130 worldInterface.getwT(&wTt2, toolName2);
134 readyBothRob = coordInterface.getReadyBothRob();
139 std::cout <<
"[COORDINATOR] Now one robot is not ready anymore" << std::endl;
145 Eigen::Matrix<double, VEHICLE_DOF, 1> execCoordAlgo(
146 Eigen::Matrix<double, VEHICLE_DOF, 1> nonCoopCartVelA_eigen,
147 Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF> admisVelToolA_eigen,
148 Eigen::Matrix<double, VEHICLE_DOF, 1> nonCoopCartVelB_eigen,
149 Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF> admisVelToolB_eigen,
150 Eigen::Matrix<double, VEHICLE_DOF, 1> refTool,
156 double muA = muZero + ((refTool-nonCoopCartVelA_eigen).norm());
157 double muB = muZero + ((refTool-nonCoopCartVelB_eigen).norm());
161 Eigen::Matrix<double, VEHICLE_DOF, 1> coopVelTool;
162 coopVelTool = (1 / (muA + muB)) *
163 ( (muA * nonCoopCartVelA_eigen) + (muB * nonCoopCartVelB_eigen) );
166 Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF> constraintMat;
167 constraintMat = (admisVelToolA_eigen - admisVelToolB_eigen);
170 Eigen::Matrix<double, VEHICLE_DOF, 1> coopVelToolFeasible;
171 Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF> eye =
172 Eigen::Matrix<double, VEHICLE_DOF, VEHICLE_DOF>::Identity();
174 coopVelToolFeasible = ( eye - (FRM::pseudoInverse(constraintMat) * constraintMat) )
178 logger->logNumbers(muA,
"weightA");
179 logger->logNumbers(muB,
"weightB");
180 logger->logNumbers(coopVelTool,
"notFeasibleCoopVel");
181 logger->logNumbers(nonCoopCartVelA_eigen,
"nonCoopVelg500_A");
182 logger->logNumbers(nonCoopCartVelB_eigen,
"nonCoopVelg500_B");
183 logger->logNumbers(coopVelToolFeasible,
"coopVel");
184 logger->logNumbers(refTool,
"idealTool");
187 return coopVelToolFeasible;
191 Eigen::Matrix<double, VEHICLE_DOF, 1> calculateRefTool(Eigen::Matrix4d wTgoaltool_eigen,
192 Eigen::Matrix4d wTtool_eigen){
194 CMAT::TransfMatrix wTgoaltool_cmat = CONV::matrix_eigen2cmat(wTgoaltool_eigen);
195 CMAT::TransfMatrix wTtool_cmat = CONV::matrix_eigen2cmat(wTtool_eigen);
198 CMAT::Vect6 errorSwapped = CMAT::CartError(wTgoaltool_cmat, wTtool_cmat);
202 Eigen::Matrix<double, VEHICLE_DOF, 1> reference;
203 reference(0) = errorSwapped(4);
204 reference(1) = errorSwapped(5);
205 reference(2) = errorSwapped(6);
206 reference(3) = errorSwapped(1);
207 reference(4) = errorSwapped(2);
208 reference(5) = errorSwapped(3);
212 reference.topRows(3) = FRM::saturateVectorEigen(reference.topRows(3), 0.3);
213 reference.bottomRows(3) = FRM::saturateVectorEigen(reference.bottomRows(3), 0.1);
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...