data_functions.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2015 Fetch Robotics Inc.
00003  * Copyright (C) 2014 Unbounded Robotics Inc.
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *     http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 // Author: Michael Ferguson
00019 
00020 #ifndef ROBOT_CALIBRATION_CERES_DATA_FUNCTIONS_H
00021 #define ROBOT_CALIBRATION_CERES_DATA_FUNCTIONS_H
00022 
00023 #include <robot_calibration_msgs/CalibrationData.h>
00024 
00025 namespace robot_calibration
00026 {
00027 
00029 geometry_msgs::PointStamped
00030 computeAverage(std::vector<geometry_msgs::PointStamped> points)
00031 {
00032   geometry_msgs::PointStamped p;
00033   p.header = points[0].header;
00034 
00035   for (size_t i = 0; i < points.size(); ++i)
00036   {
00037     p.point.x += points[i].point.x;
00038     p.point.y += points[i].point.y;
00039     p.point.z += points[i].point.z;
00040   }
00041 
00042   p.point.x = p.point.x / points.size();
00043   p.point.y = p.point.y / points.size();
00044   p.point.z = p.point.z / points.size();
00045 
00046   return p;
00047 }
00048 
00050 double computeAverage(std::vector<double> values)
00051 {
00052   double x = 0.0;
00053   for (size_t i = 0; i < values.size(); ++i)
00054     x += values[i];
00055   return (x/values.size()); 
00056 }
00057 
00062 geometry_msgs::PointStamped
00063 computeDifference(geometry_msgs::PointStamped& p1,
00064                   geometry_msgs::PointStamped& p2)
00065 {
00066   geometry_msgs::PointStamped p;
00067   p.header = p1.header;
00068 
00069   p.point.x = fabs(p1.point.x - p2.point.x);
00070   p.point.y = fabs(p1.point.y - p2.point.y);
00071   p.point.z = fabs(p1.point.z - p2.point.z);
00072 
00073   return p;
00074 }
00075 
00080 double getDistance(geometry_msgs::PointStamped& p1,
00081                    geometry_msgs::PointStamped& p2)
00082 {
00083   double x = p1.point.x - p2.point.x;
00084   double y = p1.point.y - p2.point.y;
00085   double z = p1.point.z - p2.point.z;
00086   return sqrt(x*x + y*y + z*z);
00087 }
00088 
00090 std::vector<double> getErrors(ChainModel * chain1,
00091                               ChainModel * chain2,
00092                               CalibrationOffsetParser * offsets,
00093                               robot_calibration_msgs::CalibrationData& data)
00094 {
00095   std::vector<double> error;
00096   std::vector<geometry_msgs::PointStamped> proj1 = chain1->project(data, *offsets);
00097   std::vector<geometry_msgs::PointStamped> proj2 = chain2->project(data, *offsets);
00098 
00099   for (size_t i = 0; i < proj1.size(); ++i)
00100   {
00101     error.push_back(getDistance(proj1[i], proj2[i]));
00102   }
00103 
00104   return error;
00105 }
00106 
00112 std::vector<geometry_msgs::PointStamped>
00113 getErrorPoints(ChainModel * chain1,
00114                ChainModel * chain2,
00115                CalibrationOffsetParser * offsets,
00116                robot_calibration_msgs::CalibrationData& data)
00117 {
00118   std::vector<geometry_msgs::PointStamped> error;
00119   std::vector<geometry_msgs::PointStamped> proj1 = chain1->project(data, *offsets);
00120   std::vector<geometry_msgs::PointStamped> proj2 = chain2->project(data, *offsets);
00121 
00122   for (size_t i = 0; i < proj1.size(); ++i)
00123   {
00124     error.push_back(computeDifference(proj1[i], proj2[i]));
00125   }
00126 
00127   return error;
00128 }
00129 
00130 void printSimpleDistanceError(ChainModel * chain1,
00131                               ChainModel * chain2,
00132                               CalibrationOffsetParser * before,
00133                               CalibrationOffsetParser * after,
00134                               robot_calibration_msgs::CalibrationData& data)
00135 {
00136   std::cout << "  Distance Error Before: " << computeAverage(getErrors(chain1, chain2, before, data)) <<
00137                  ", After: " << computeAverage(getErrors(chain1, chain2, after, data)) << std::endl;
00138 }
00139 
00140 void printComparePointsInternal(ChainModel * chain1,
00141                                 ChainModel * chain2,
00142                                 CalibrationOffsetParser * offsets,
00143                                 robot_calibration_msgs::CalibrationData& data)
00144 {
00145   std::vector<geometry_msgs::PointStamped> proj1 = chain1->project(data, *offsets);
00146   std::vector<geometry_msgs::PointStamped> proj2 = chain2->project(data, *offsets);
00147 
00148   std::cout << "  x:";
00149   for (size_t x = 0; x < proj1.size(); ++x)
00150     std::cout << "  " << std::setw(10) << std::fixed << proj1[x].point.x;
00151   std::cout << "  |  ";
00152   for (size_t x = 0; x < proj2.size(); ++x)
00153     std::cout << "  " << std::setw(10) << std::fixed << proj2[x].point.x;
00154   std::cout << std::endl;
00155 
00156   std::cout << "  y:";
00157   for (size_t y = 0; y < proj1.size(); ++y)
00158     std::cout << "  " << std::setw(10) << std::fixed << proj1[y].point.y;
00159   std::cout << "  |  ";
00160   for (size_t y = 0; y < proj2.size(); ++y)
00161     std::cout << "  " << std::setw(10) << std::fixed << proj2[y].point.y;
00162   std::cout << std::endl;
00163 
00164   std::cout << "  z:";
00165   for (size_t z = 0; z < proj1.size(); ++z)
00166     std::cout << "  " << std::setw(10) << std::fixed << proj1[z].point.z;
00167   std::cout << "  |  ";
00168   for (size_t z = 0; z < proj2.size(); ++z)
00169     std::cout << "  " << std::setw(10) << std::fixed << proj2[z].point.z;
00170   std::cout << std::endl;
00171 }
00172 
00173 void printComparePoints(ChainModel * chain1,
00174                         ChainModel * chain2,
00175                         CalibrationOffsetParser * before,
00176                         CalibrationOffsetParser * after,
00177                         robot_calibration_msgs::CalibrationData& data)
00178 {
00179   std::cout << "  Points Before:" << std::endl;
00180   printComparePointsInternal(chain1, chain2, before, data);
00181   std::cout << std::endl;
00182   std::cout << "  Points After:" << std::endl;
00183   printComparePointsInternal(chain1, chain2, after, data);
00184   std::cout << std::endl;
00185 
00186   // error by dimension
00187   geometry_msgs::PointStamped err_before = computeAverage(getErrorPoints(chain1, chain2, before, data));
00188   geometry_msgs::PointStamped err_after = computeAverage(getErrorPoints(chain1, chain2, after, data));
00189 
00190   std::cout << "  Error:     Before       After" << std::endl;
00191   std::cout << "  x:     " << std::setw(10) << std::fixed << err_before.point.x <<
00192                "  " << std::setw(10) << std::fixed << err_after.point.x << std::endl;
00193   std::cout << "  y:     " << std::setw(10) << std::fixed << err_before.point.y <<
00194                "  " << std::setw(10) << std::fixed << err_after.point.y << std::endl;
00195   std::cout << "  z:     " << std::setw(10) << std::fixed << err_before.point.z <<
00196                "  " << std::setw(10) << std::fixed << err_after.point.z << std::endl;
00197   std::cout << std::endl; 
00198 }
00199 
00200 }  // namespace robot_calibration
00201 
00202 #endif  // ROBOT_CALIBRATION_CERES_DATA_FUNCTIONS_H


robot_calibration
Author(s): Michael Ferguson
autogenerated on Sat May 20 2017 02:35:31