Skip to content

Commit b1e1fc1

Browse files
committed
data logging outside of module control
1 parent 0bd6357 commit b1e1fc1

File tree

10 files changed

+483
-165
lines changed

10 files changed

+483
-165
lines changed

Diff for: dual_arm_control/include/dual_arm_control_iam/DualArmControlSim.hpp

+70-3
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,6 @@ struct StateMachine {
9898
Eigen::Vector3f deltaPos;
9999
float trackingFactor;
100100
bool adaptationActive;
101-
102-
bool startlogging;
103101
};
104102

105103
struct SphericalPosition {
@@ -130,6 +128,72 @@ struct tossingTaskVariables {
130128
Eigen::Vector4f restOrientation;
131129
};
132130

131+
struct DataToSave {
132+
// Robot
133+
Eigen::Vector3f robotX[NB_ROBOTS];
134+
Eigen::Vector4f robotQ[NB_ROBOTS];
135+
Vector6f robotVelDesEE[NB_ROBOTS];
136+
Vector6f robotVelEE[NB_ROBOTS];
137+
Eigen::Vector3f robotVDes[NB_ROBOTS];
138+
Eigen::Vector3f robotOmegaDes[NB_ROBOTS];
139+
Vector6f robotFilteredWrench[NB_ROBOTS];
140+
Vector7f robotJointsPositions[NB_ROBOTS];
141+
Vector7f robotJointsVelocities[NB_ROBOTS];
142+
Vector7f robotJointsAccelerations[NB_ROBOTS];
143+
Vector7f robotJointsTorques[NB_ROBOTS];
144+
145+
// Object
146+
Eigen::Matrix4f objectWHGpSpecific[NB_ROBOTS];
147+
Eigen::Matrix4f objectWHDo;
148+
Eigen::Vector3f objectXo;
149+
Eigen::Vector4f objectQo;
150+
Eigen::Vector3f objectVo;
151+
Eigen::Vector3f objectWo;
152+
Vector6f objVelDes;
153+
154+
// Target
155+
Eigen::Vector3f targetXt;
156+
Eigen::Vector4f targetQt;
157+
Eigen::Vector3f targetVt;
158+
Eigen::Vector3f targetXdLanding;
159+
Eigen::Vector3f targetXIntercept;
160+
Eigen::Vector3f targetXtStateToGo;
161+
162+
// Tossing
163+
tossingTaskVariables tossVar;
164+
165+
// Task
166+
Eigen::Vector3f taskXPlacing;
167+
float desiredVelImp;
168+
float betaVelMod;
169+
Eigen::Vector2f dualPathLenAvgSpeed;
170+
171+
// Cooperative control
172+
Vector6f cooperativeCtrlForceApplied[NB_ROBOTS];
173+
174+
// Free motion control
175+
float freeMotionCtrlActivationProximity;
176+
float freeMotionCtrlActivationNormal;
177+
float freeMotionCtrlActivationTangent;
178+
float freeMotionCtrlActivationRelease;
179+
float freeMotionCtrlActivationRetract;
180+
181+
// DS throwing
182+
float dsThrowingActivationProximity;
183+
float dsThrowingActivationNormal;
184+
float dsThrowingActivationTangent;
185+
float dsThrowingActivationToss;
186+
187+
// State machine
188+
bool goHome;
189+
bool goToAttractors;
190+
bool releaseAndretract;
191+
bool isThrowing;
192+
bool isPlacing;
193+
bool isContact;
194+
float desVtoss;
195+
};
196+
133197
class DualArmControlSim {
134198

135199
private:
@@ -372,4 +436,7 @@ class DualArmControlSim {
372436
void keyboardReferenceObjectControl();
373437
StateMachine getStateMachine();
374438
void updateStateMachine(StateMachine stateMachine);
375-
};
439+
440+
// ---- Get data for log
441+
DataToSave getDataToSave();
442+
};

Diff for: dual_arm_control/include/dual_arm_control_iam/tools/PdfGMR.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
#include "eigen3/Eigen/Core"
2929

30-
// #include "dual_arm_control_iam/DataLogging.hpp"
30+
#include "dual_arm_control_iam/tools/Utils.hpp"
3131

3232
using namespace std;
3333
class PdfGMR {
@@ -43,7 +43,7 @@ class PdfGMR {
4343
~PdfGMR(){};
4444

4545
bool init(std::string fileGMM[]) {
46-
// datalog_.loadGMMParam(fileGMM, priorGMMToss_, meanGMMToss_, covMxGMMToss_);
46+
Utils<double>::loadGMMParam(fileGMM, priorGMMToss_, meanGMMToss_, covMxGMMToss_);
4747
return true;
4848
}
4949

Diff for: dual_arm_control/include/dual_arm_control_iam/tools/Utils.hpp

+59
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include "Eigen/Eigen"
2929
#include <float.h>
3030
#include <fstream>
31+
#include <iostream>
3132

3233
template<typename T = float>
3334
class Utils {
@@ -798,6 +799,64 @@ class Utils {
798799
static Eigen::Matrix<T, 3, 1> getAbs3D(Eigen::Matrix<T, 4, 4> H[2]) {
799800
return 0.5 * (H[0].block(0, 3, 3, 1) + H[1].block(0, 3, 3, 1));
800801
}
802+
803+
// Function to load data from file
804+
static bool loadDataFromFile(std::string fileName, Eigen::VectorXf& dataAllVal) {
805+
// Eigen::Matrix<T, Eigen::Dynamic, 1> &data_all_val
806+
std::ifstream inFile;
807+
inFile.open(fileName);
808+
if (!inFile) {
809+
std::cout << "Unable to open file \n" << std::endl;
810+
exit(1);// terminate with error
811+
}
812+
813+
std::vector<float> dataVal;
814+
float x;
815+
while (inFile >> x) { dataVal.push_back(x); }
816+
817+
int sizeDataVal = dataVal.size();
818+
dataAllVal.resize(sizeDataVal);
819+
for (int i = 0; i < sizeDataVal; i++) dataAllVal(i) = dataVal[i];
820+
821+
return true;
822+
}
823+
824+
static bool
825+
loadGMMParam(std::string fileName[], Eigen::VectorXf& priors, Eigen::MatrixXf& means, Eigen::MatrixXf& covars) {
826+
827+
std::string priorsFileName = fileName[0];
828+
std::string meansFileName = fileName[1];
829+
std::string covarFileName = fileName[2];
830+
Eigen::VectorXf priorsAllVal;
831+
Eigen::VectorXf meansAllVal;
832+
Eigen::VectorXf covarsAllVal;
833+
834+
Utils<double>::loadDataFromFile(priorsFileName, priorsAllVal);
835+
Utils<double>::loadDataFromFile(meansFileName, meansAllVal);
836+
Utils<double>::loadDataFromFile(covarFileName, covarsAllVal);
837+
838+
// Priors
839+
priors = priorsAllVal;
840+
841+
int nbStates = priorsAllVal.rows();
842+
int dataDim = int(meansAllVal.rows() / nbStates);
843+
844+
// Means
845+
Eigen::Map<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>> meansMx(meansAllVal.data(),
846+
dataDim,
847+
nbStates);
848+
means = meansMx;
849+
850+
int rowCov = dataDim * nbStates;
851+
852+
// Covariance
853+
Eigen::Map<Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>> covarMx(covarsAllVal.data(),
854+
rowCov,
855+
dataDim);
856+
covars = covarMx;
857+
858+
return true;
859+
}
801860
};
802861

803862
template class Utils<float>;

Diff for: dual_arm_control/src/DataLogging.cpp

-145
This file was deleted.

0 commit comments

Comments
 (0)