-
Notifications
You must be signed in to change notification settings - Fork 0
/
surfaceProximity.cpp
88 lines (65 loc) · 2.66 KB
/
surfaceProximity.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//
// Created by chaitanya11 on 16.06.23.
//
#include <iostream>
#include <Eigen/Dense>
#include <vector>
#include <utility>
#include <algorithm>
#include <iterator>
#include <AndreiUtils/utilsJson.h>
#include <AndreiUtils/utilsJsonEigen.hpp>
#include <AndreiUtils/classes/DualQuaternion.hpp>
using json = nlohmann::json;
using namespace AndreiUtils;
using namespace std;
using namespace Eigen;
// set here the index number of surface (starts from 0)-
int const surface_index = 0;
// set here the acceptable distance from surface in z direction in meters -
double const z_dist = 0.10;
int main() {
cout << "Hello World!" << endl;
vector<json> data = readJsonFile("../data/demonstration_2023-06-21-18-53-52_129873292.json").get<vector<json>>();
cout << "Json data size = " << data.size() << endl;
vector<json> surface = readJsonFile("../data/surfaceData_2023-06-22-14-45-37_257316435.json").get<vector<json>>();
Eigen::Matrix3d A;
Posed q;
// extracting the axes of the surface -
// Taking data of surface number 0 -
vector<double> x_axis = surface[20].at("surfacesData")[surface_index].at("xAxis");
vector<double> y_axis = surface[20].at("surfacesData")[surface_index].at("yAxis");
vector<double> z_axis = surface[20].at("surfacesData")[surface_index].at("zAxis");
vector<double> x_range = surface[20].at("surfacesData")[surface_index].at("xRange");
vector<double> y_range = surface[20].at("surfacesData")[surface_index].at("yRange");
for (int i = 0; i < data.size() - 1; ++i) {
//if (!data[i].contains("objects")) {
// continue;
//}
//auto &objects = data[i].at("objects");
//if (!objects.contains("MilkCartonLidlInstance1")) {
// continue;
//}
try {
auto &milkCarton = data[i].at("objects").at("MilkCartonLidlInstance1");
q = milkCarton.at("geometryPose").get<Posed>();
auto t = q.getTranslation();
A.col(0) = Vector3d(x_axis.data());
A.col(1) = Vector3d(y_axis.data());
A.col(2) = Vector3d(z_axis.data());
// check!
Eigen::Vector3d newCoordinates = A * Eigen::Vector3d(t.x(), t.y(), t.z());
if (newCoordinates(0) > x_range[0] && newCoordinates(0) < x_range[1] &&
newCoordinates(1) > y_range[0] && newCoordinates(1) < y_range[1] &&
newCoordinates(2) < z_dist) {
cout << "Object is in surface limits" << endl;
}
else
cout << "Outside bounds!" << endl;
}
catch (nlohmann::detail::out_of_range &e ) {
continue;
}
}
return 0;
}