32 #include <Eigen/Dense> 35 #include <boost/shared_ptr.hpp> 36 #include <boost/algorithm/string.hpp> 56 std::ifstream input(filename);
58 unsigned int lineNumber = 1;
59 std::vector<Eigen::Quaterniond> rotationVector;
60 std::vector<Eigen::Vector3d> translationVector;
61 while(std::getline( input, line ))
63 std::vector<std::string> strs;
64 boost::split(strs, line, boost::is_any_of(
";"));
67 std::vector<double> numericValues;
69 for (
unsigned int i = 0; i < strs.size(); i++)
73 std::string temp = strs.at(i);
74 boost::algorithm::trim(temp);
75 numericValues.push_back(boost::lexical_cast<double>(temp));
77 catch (boost::bad_lexical_cast
const&)
79 ROS_ERROR_STREAM(
"Line " << lineNumber <<
": " <<strs.at(i) <<
" is not a number.");
86 Eigen::Quaterniond rotation(numericValues.at(3),numericValues.at(0),numericValues.at(1),numericValues.at(2));
87 Eigen::Vector3d translation(numericValues.at(4),numericValues.at(5),numericValues.at(6));
88 rotationVector.push_back(rotation);
89 translationVector.push_back(translation);
94 ROS_ERROR_STREAM(
"Line " << lineNumber <<
": Expected 7 items, got " << strs.size());
98 if (rotationVector.size() > 0)
100 Eigen::Vector3d averageTranslation = translationVector.at(0);
101 Eigen::Quaterniond averageRotation = rotationVector.at(0);
103 for (
unsigned int i = 1; i < rotationVector.size(); i++)
105 Eigen::Quaterniond tempRotation = rotationVector.at(i);
106 Eigen::Vector3d tempTranslation = translationVector.at(i);
107 averageTranslation = averageTranslation + tempTranslation;
108 averageRotation = averageRotation.slerp((
double)i/(i+1.0), tempRotation);
110 averageTranslation = averageTranslation * 1.0/(double)rotationVector.size();
111 ROS_INFO_STREAM(
"Position X=" << averageTranslation(0) <<
" Y=" << averageTranslation(1) <<
" Z=" << averageTranslation(2));
112 ROS_INFO_STREAM(
"Rotation w=" << averageRotation.w() <<
" x=" << averageRotation.x() <<
" y=" << averageRotation.y() <<
" z=" << averageRotation.z());
119 bool success =
false;
130 bool success =
false;
131 unsigned int testCount = 3;
132 Eigen::Matrix4d m1_array[testCount];
133 double pan_array[testCount];
134 double tilt_array[testCount];
135 for (
unsigned int k = 0; k < testCount; k++)
137 Eigen::Matrix4d m1, m2;
139 tilt = rand() & 1000;
141 tilt_array[k] = tilt;
142 double roll = fmod((
double)rand(),2.0*M_PI);
143 double pitch = fmod((
double)rand(),2.0*M_PI);
144 double yaw = fmod((
double)rand(),2.0*M_PI);
145 ROS_INFO_STREAM(
"Roll: " << roll <<
" pitch: " << pitch <<
" yaw: " << yaw);
146 Eigen::Affine3d tr1 = Eigen::AngleAxisd(roll, Eigen::Vector3d::UnitZ()) * Eigen::AngleAxisd(pitch, Eigen::Vector3d::UnitX()) * Eigen::AngleAxisd(yaw, Eigen::Vector3d::UnitZ()) * Eigen::Translation3d(rand() % 1000, rand()% 1000, rand()% 1000);
147 roll = fmod((
double)rand(),2.0*M_PI);
148 pitch = fmod((
double)rand(),2.0*M_PI);
149 yaw = fmod((
double)rand(),2.0*M_PI);
150 ROS_INFO_STREAM(
"Roll: " << roll <<
" pitch: " << pitch <<
" yaw: " << yaw);
151 Eigen::Affine3d tr2 = Eigen::AngleAxisd(roll, Eigen::Vector3d::UnitZ()) * Eigen::AngleAxisd(pitch, Eigen::Vector3d::UnitX()) * Eigen::AngleAxisd(yaw, Eigen::Vector3d::UnitZ()) * Eigen::Translation3d(rand()% 1000, rand()% 1000, rand()% 1000);
158 std::vector<Transformation_Data> dataCollection = manager->
readFromFile();
159 if (dataCollection.size() >= testCount)
162 for (
unsigned int k = 0; k < testCount; k++)
167 tilt = tilt_array[k];
169 success &= (fabs(pan - data.
pan) < 0.00001);
170 if (success) {cout <<
"Pan correct" << endl;}
171 else {
ROS_ERROR_STREAM(
"Pan incorrect. Expected " << pan <<
", got " << data.
pan <<
" difference " << fabs(pan - data.
pan));
return success;}
172 success &= (fabs(tilt - data.
tilt) < 0.00001);
173 if (success) {cout <<
"Tilt correct" << endl;}
174 else {
ROS_ERROR_STREAM(
"Tilt incorrect. Expected " << tilt <<
", got " << data.
tilt <<
" difference " << fabs(tilt - data.
tilt));
return success;}
175 for (
unsigned int i = 0; i < 4; i++)
177 for (
unsigned int j = 0; j < 4; j++)
179 success &= (fabs(m1(i,j) - data.
PTU_Frame(i,j)) < 0.001);
180 if (!success) {
ROS_ERROR_STREAM(
"PTU frame incorrect. Expected " << m1(i,j) <<
", got " << data.
PTU_Frame(i,j) <<
" difference " << fabs(m1(i,j) - data.
PTU_Frame(i,j)));
return success;}
183 if (success) {cout <<
"PTU frame correct" << endl;}
188 ROS_ERROR_STREAM(
"Not enough dataNodes found. Expected " << testCount <<
", got " << dataCollection.size());
195 Eigen::Vector3d top, temp;
196 Eigen::Vector2d base1, base2, base3;
197 double angle12, angle23, angle31;
198 double side1, side2, side3, sideBase;
203 top[0] = (rand() % 1000 + 1) /100.0;
204 top[1] = (rand() % 1000 + 1) /100.0;
205 top[2] = (rand() % 1000 + 1) /500.0;
207 base1[0] = (rand() % 1000 + 1) /100.0;
208 base1[1] = (rand() % 1000 + 1) /100.0;
209 base2[0] = (rand() % 1000 + 1) /100.0;
210 base2[1] = (rand() % 1000 + 1) /100.0;
211 base3[0] = (rand() % 1000 + 1) /100.0;
213 base3[1] = (base1[0]*base3[0]-base2[0]*base3[0]-base1[0]*base2[0]+base2[0]*base2[0]-base1[1]*base2[1]+base2[1]*base2[1])/(base2[1]-base1[1]);
217 temp = Eigen::Vector3d(base1.x(), base1.y(), 0.0f);
218 side1 = (top - temp).norm();
219 temp = Eigen::Vector3d(base2.x(), base2.y(), 0.0f);
220 side2 = (top - temp).norm();
221 temp = Eigen::Vector3d(base3.x(), base3.y(), 0.0f);
222 side3 = (top - temp).norm();
223 sideBase = (base1 - base2).norm();
224 angle12 = acos((-sideBase*sideBase + side1*side1 + side2*side2)/(2*side1*side2));
226 sideBase = (base2 - base3).norm();
227 angle23 = acos((-sideBase*sideBase + side3*side3 + side2*side2)/(2*side3*side2));
229 sideBase = (base3 - base1).norm();
230 angle31 = acos((-sideBase*sideBase + side1*side1 + side3*side3)/(2*side1*side3));
232 cout <<
"Testing vectors [" << base1.x() <<
", " << base1.y() <<
"] ";
233 cout <<
"[" << base2.x() <<
", " << base2.y() <<
"] ";
234 cout <<
"[" << base3.x() <<
", " << base3.y() <<
"]" << endl;
235 cout <<
"with top-point [" << top.x() <<
", " << top.y() <<
", " << top.z() <<
"]" << endl;
236 cout <<
"Distances " << side1 <<
", " << side2 <<
", " << side3 <<
"" << endl;
237 cout <<
"Angles " << angle12 <<
", " << angle23 <<
", " << angle31 <<
"" << endl;
241 calibrationObject->top_angle_ab = angle12;
242 calibrationObject->top_angle_bc = angle23;
243 calibrationObject->top_angle_ca = angle31;
244 calibrationObject->side_a = (base1 - base2).norm();
245 calibrationObject->side_b = (base2 - base3).norm();
246 calibrationObject->side_c = (base1 - base3).norm();
250 solver.
solve(base1, base2, base3);
251 cout <<
"Results:" << endl;
253 if (solver.
solutions_a.size() == 0) {cout <<
"No solutions found." << endl;}
254 for (
unsigned int i = 0; i < solver.
solutions_a.size(); i++)
269 cout <<
"Distance test successful" << endl;
271 for (
unsigned int i = 0; i < solver.
solutions.size(); i++)
273 if (abs(solver.
solutions[i].x() - top.x()) <= 0.0001
f && abs(solver.
solutions[i].y() - top.y()) <= 0.0001
f && abs(solver.
solutions[i].z() - top.z()) <= 0.0001
f)
285 if (success) {cout <<
"Top-point test successful!" << endl;}
293 int sizeOfString = string_.size();
295 bool isNumeric =
true;
297 while(iteration < sizeOfString)
299 if(!isdigit(string_[iteration]))
312 bool testFound =
false;
313 if (args.substr(0,9) ==
"resection")
315 string numerArg = args.substr(9);
316 numerArg.erase(std::remove(numerArg.begin(), numerArg.end(),
' '), numerArg.end());
318 if (
is_numeric(numerArg) && numerArg.size() > 0) {
319 unsigned int numbers = atoi(numerArg.c_str());
320 unsigned int success = 0;
321 for (
unsigned int i = 0; i < numbers; i++)
325 time_end = clock() + 20 * CLOCKS_PER_SEC/1000;
326 while (clock() < time_end)
331 cout << success <<
"/" << numbers <<
" were successful." << endl;
345 else if (args.substr(0,13) ==
"serialization")
347 string numerArg = args.substr(13);
348 numerArg.erase(std::remove(numerArg.begin(), numerArg.end(),
' '), numerArg.end());
350 if (numerArg.size() > 0) {
351 std::string writer = numerArg.c_str();
372 else if (args.substr(0,15) ==
"markerdetection")
377 else if (args.substr(0,12) ==
"averageframe")
379 string filename = args.substr(13);
380 filename.erase(std::remove(filename.begin(), filename.end(),
' '), filename.end());
386 cout <<
"Testcase '" << args <<
"'not declared!" << endl;
392 int main(
int argc,
char *argv[])
397 ros::init(x, arg,
"calibrationTool_tests");
400 nh.
getParam(
"test_workspace", myWorkspace);
403 std::cout <<
"Please choose a test to run: " << std::endl;
405 std::getline(std::cin, inp);
407 while (args_ !=
"exit")
411 std::cout <<
"Available tests are: " << std::endl;
412 std::cout <<
" resection <count>" << std::endl;
413 std::cout <<
" serialization XML|DATA" << std::endl;
414 std::cout <<
" markerdetection" << std::endl;
415 std::cout <<
" averageframe <filename>" << std::endl;
417 std::cout <<
"Please choose a test to run: " << std::endl;
418 std::getline(std::cin, inp);
bool start_test(string args)
std::vector< Eigen::Vector3d, Eigen::aligned_allocator< Eigen::Vector3d > > solutions
unsigned int solve(const Eigen::Vector2d &base_A, const Eigen::Vector2d &base_B, const Eigen::Vector2d &base_C)
ROSCPP_DECL void init(int &argc, char **argv, const std::string &name, uint32_t options=0)
ROSCPP_DECL const std::string & getName()
bool test_serialisation(Abstract_TransformationFile_Manager *manager)
std::vector< double > solutions_a
std::vector< double > solutions_b
int main(int argc, char *argv[])
#define ROS_INFO_STREAM(args)
bool test_averageframe(string filename)
bool test_resectionsolver()
bool getParam(const std::string &key, std::string &s) const
bool is_numeric(string string_)
#define ROS_ERROR_STREAM(args)
bool test_markerDetection()
std::vector< double > solutions_c