2 #include <VirtualRobot/MathTools.h>
10 Eigen::VectorXf
getEigenVec(nlohmann::json& userConfig, nlohmann::json& defaultConfig,
const std::string& entryName,
int size,
int value)
12 if (userConfig.find(entryName) != userConfig.end())
14 auto vec = userConfig[entryName].get<std::vector<float>>();
17 return Eigen::Map<Eigen::VectorXf>(vec.data(), vec.size());
21 return Eigen::VectorXf::Ones(size) *
value;
23 ARMARX_IMPORTANT <<
"user defined parameter " << entryName <<
" have size 0, fall back to default";
26 auto vec = defaultConfig[entryName].get<std::vector<float>>();
27 return Eigen::Map<Eigen::VectorXf>(vec.data(), vec.size());
30 void getEigenMatrix(nlohmann::json &userConfig,
const std::string &entryName, Eigen::MatrixXf& mat)
32 if (userConfig.find(entryName) != userConfig.end())
34 auto vec = userConfig[entryName].get<std::vector<std::vector<float>>>();
35 int rows = vec.size();
36 int cols = vec[0].size();
40 mat.resize(rows, cols);
41 for (
int i = 0; i < rows; i++)
43 for (
int j = 0; j < cols; j++)
56 Eigen::VectorXf
getEigenVecWithDefault(nlohmann::json& userConfig, Eigen::VectorXf defaultValue,
const std::string& entryName)
58 if (userConfig.find(entryName) != userConfig.end())
60 auto vec = userConfig[entryName].get<std::vector<float>>();
61 if (vec.size() == (unsigned)defaultValue.size())
63 return Eigen::Map<Eigen::VectorXf>(vec.data(), vec.size());
65 ARMARX_WARNING <<
"size of the user defined parameter " << entryName <<
" doesn't correspond to default size, use default value instead";
72 Eigen::Matrix4d currentPosed = currentPose.cast<
double>();
73 Eigen::Vector3d currentPosid = currentPosed.block<3,1>(0,3);
74 posiError = (currentPosid - targetPosition).
norm();
77 oriError = targetQuaternion.angularDistance(currentOrientation);
80 oriError = 2 *
M_PI - oriError;
86 Eigen::Vector3f rpy = VirtualRobot::MathTools::eigen4f2rpy(pose);
87 datafields[name +
"_x"] =
new Variant(pose(0, 3));
88 datafields[name +
"_y"] =
new Variant(pose(1, 3));
89 datafields[name +
"_z"] =
new Variant(pose(2, 3));
90 datafields[name +
"_rx"] =
new Variant(rpy(0));
91 datafields[name +
"_ry"] =
new Variant(rpy(1));
92 datafields[name +
"_rz"] =
new Variant(rpy(2));
97 for (
int i = 0; i < vec.size(); i++)
107 {
"qw", fp.orientation->qw},
108 {
"qx", fp.orientation->qx},
109 {
"qy", fp.orientation->qy},
110 {
"qz", fp.orientation->qz},
111 {
"x", fp.position->x},
112 {
"y", fp.position->y},
113 {
"z", fp.position->z}
119 j.at(
"qw").get_to(fp.orientation->qw);
120 j.at(
"qx").get_to(fp.orientation->qx);
121 j.at(
"qy").get_to(fp.orientation->qy);
122 j.at(
"qz").get_to(fp.orientation->qz);
123 j.at(
"x").get_to(fp.position->x);
124 j.at(
"y").get_to(fp.position->y);
125 j.at(
"z").get_to(fp.position->z);
136 void to_json(nlohmann::json &j,
const PoseBasePtr &fp)
140 to_json(j, PosePtr::dynamicCast(fp));
144 void from_json(
const nlohmann::json &j, PoseBasePtr &fp)
165 Eigen::Matrix4f mat = VirtualRobot::MathTools::quat2eigen4f(
static_cast<float>(dvec[4]),
166 static_cast<float>(dvec[5]),
167 static_cast<float>(dvec[6]),
168 static_cast<float>(dvec[3]));
169 mat(0, 3) =
static_cast<float>(dvec[0]);
170 mat(1, 3) =
static_cast<float>(dvec[1]);
171 mat(2, 3) =
static_cast<float>(dvec[2]);
184 std::vector<double> result;
187 for (
size_t i = 0; i < 3; ++i)
189 result.at(i) =
static_cast<double>(mat(i, 3));
194 result.at(3) =
static_cast<double>(quat.w);
195 result.at(4) =
static_cast<double>(quat.x);
196 result.at(5) =
static_cast<double>(quat.y);
197 result.at(6) =
static_cast<double>(quat.z);
210 std::vector<float> result;
213 for (
size_t i = 0; i < 3; ++i)
215 result.at(i) = mat(i, 3);
220 result.at(3) = quat.w;
221 result.at(4) = quat.x;
222 result.at(5) = quat.y;
223 result.at(6) = quat.z;
231 for (
const double& d: dvec)
240 return Eigen::Map<Eigen::VectorXf>(vec.data(), vec.size());