error_simulation.cpp
Go to the documentation of this file.
00001 
00018 #include "error_simulation.h"
00019 #include <random>
00020 #include <iostream>
00021 #include <ros/console.h>
00022 #include <Eigen/Dense>
00023 
00024 
00025 namespace fake_object_recognition {
00026 
00027 ErrorSimulation::ErrorSimulation() : ErrorSimulation(false, false, false) { }
00028 
00029 ErrorSimulation::ErrorSimulation(bool use_pose_invalidation, bool use_position_noise, bool use_orientation_noise) :
00030     use_pose_invalidation_(use_pose_invalidation),
00031     use_position_noise_(use_position_noise),
00032     use_orientation_noise_(use_orientation_noise),
00033     prob_pose_inval_(DEFAULT_PROB_POSE_INVAL),
00034     pos_noise_dist_mean_(DEFAULT_POS_NOISE_MEAN),
00035     pos_noise_dist_dev_(DEFAULT_POS_NOISE_DEV),
00036     or_x_noise_dist_mean_(DEFAULT_OR_X_NOISE_MEAN),
00037     or_x_noise_dist_dev_(DEFAULT_OR_X_NOISE_DEV),
00038     or_y_noise_dist_mean_(DEFAULT_OR_Y_NOISE_MEAN),
00039     or_y_noise_dist_dev_(DEFAULT_OR_Y_NOISE_DEV),
00040     or_z_noise_dist_mean_(DEFAULT_OR_Z_NOISE_MEAN),
00041     or_z_noise_dist_dev_(DEFAULT_OR_Z_NOISE_DEV) { }
00042 
00043 double ErrorSimulation::genUniformNumber(double interval_start, double interval_end) {
00044     std::random_device rd;
00045     std::mt19937 gen(rd());
00046     std::uniform_real_distribution<double> dis(interval_start, interval_end);
00047     return dis(gen);
00048 }
00049 
00050 double ErrorSimulation::genNormalDistNumber(double mean, double std_deviation) {
00051     std::random_device rd;
00052     std::mt19937 gen(rd());
00053     std::normal_distribution<double> dis(mean, std_deviation);
00054     return dis(gen);
00055 }
00056 
00057 bool ErrorSimulation::poseInvalidation() {
00058     if (use_pose_invalidation_) {
00059         return genUniformNumber(0.0, 1.0) >= prob_pose_inval_;
00060     }
00061     return true;
00062 }
00063 
00064 geometry_msgs::Pose ErrorSimulation::addNoiseToPosition(const geometry_msgs::Pose &pose) {
00065     if (use_position_noise_) {
00066         geometry_msgs::Pose result(pose);
00067         result.position.x += genNormalDistNumber(pos_noise_dist_mean_, pos_noise_dist_dev_);
00068         result.position.y += genNormalDistNumber(pos_noise_dist_mean_, pos_noise_dist_dev_);
00069         result.position.z += genNormalDistNumber(pos_noise_dist_mean_, pos_noise_dist_dev_);
00070         return result;
00071     }
00072     return pose;
00073 }
00074 
00075 geometry_msgs::Pose ErrorSimulation::addNoiseToOrientation(const geometry_msgs::Pose &pose) {
00076     if (use_orientation_noise_) {
00077         geometry_msgs::Pose result(pose);
00078         Eigen::Quaternion<double> orientation(pose.orientation.w, pose.orientation.x, pose.orientation.y, pose.orientation.z);
00079         Eigen::Quaternion<double> quat_x(Eigen::AngleAxis<double>(genNormalDistNumber(or_x_noise_dist_mean_, or_x_noise_dist_dev_), Eigen::Vector3d(1.0, 0.0, 0.0)));
00080         Eigen::Quaternion<double> quat_y(Eigen::AngleAxis<double>(genNormalDistNumber(or_y_noise_dist_mean_, or_y_noise_dist_dev_), Eigen::Vector3d(0.0, 1.0, 0.0)));
00081         Eigen::Quaternion<double> quat_z(Eigen::AngleAxis<double>(genNormalDistNumber(or_z_noise_dist_mean_, or_z_noise_dist_dev_), Eigen::Vector3d(0.0, 0.0, 1.0)));
00082 
00083         orientation = quat_x * quat_y * quat_z * orientation;
00084         result.orientation.w = orientation.w();
00085         result.orientation.x = orientation.x();
00086         result.orientation.y = orientation.y();
00087         result.orientation.z = orientation.z();
00088         return result;
00089     }
00090     return pose;
00091 }
00092 
00093 
00094 void ErrorSimulation::setProbPoseInval(double prob_pose_inval) {
00095     prob_pose_inval_ = prob_pose_inval;
00096 }
00097 void ErrorSimulation::setPoseNoiseDistMean(double pos_noise_dist_mean) {
00098     pos_noise_dist_mean_ = pos_noise_dist_mean;
00099 }
00100 
00101 void ErrorSimulation::setPoseNoiseDistDev(double pos_noise_dist_dev) {
00102     pos_noise_dist_dev_ = pos_noise_dist_dev;
00103 }
00104 
00105 void ErrorSimulation::setOrXNoiseDistMean(double or_x_noise_dist_mean) {
00106     or_x_noise_dist_mean_ = or_x_noise_dist_mean;
00107 }
00108 
00109 void ErrorSimulation::setOrXNoiseDistDev(double or_x_noise_dist_dev) {
00110     or_x_noise_dist_dev_ = or_x_noise_dist_dev;
00111 }
00112 
00113 void ErrorSimulation::setOrYNoiseDistMean(double or_y_noise_dist_mean) {
00114     or_y_noise_dist_mean_ = or_y_noise_dist_mean;
00115 }
00116 
00117 void ErrorSimulation::setOrYNoiseDistDev(double or_y_noise_dist_dev) {
00118     or_y_noise_dist_dev_ = or_y_noise_dist_dev;
00119 }
00120 
00121 void ErrorSimulation::setOrZNoiseDistMean(double or_z_noise_dist_mean) {
00122     or_z_noise_dist_mean_ = or_z_noise_dist_mean;
00123 }
00124 
00125 void ErrorSimulation::setOrZNoiseDistDev(double or_z_noise_dist_dev) {
00126     or_z_noise_dist_dev_ = or_z_noise_dist_dev;
00127 }
00128 
00129 }


asr_fake_object_recognition
Author(s): Allgeyer Tobias, Aumann Florian, Borella Jocelyn, Meißner Pascal, Qattan Mohamad
autogenerated on Sat Jun 8 2019 19:15:45