error_simulation.cpp
Go to the documentation of this file.
1 
18 #include "error_simulation.h"
19 #include <random>
20 #include <iostream>
21 #include <ros/console.h>
22 #include <Eigen/Dense>
23 
24 
25 namespace fake_object_recognition {
26 
28 
29 ErrorSimulation::ErrorSimulation(bool use_pose_invalidation, bool use_position_noise, bool use_orientation_noise) :
30  use_pose_invalidation_(use_pose_invalidation),
31  use_position_noise_(use_position_noise),
32  use_orientation_noise_(use_orientation_noise),
42 
43 double ErrorSimulation::genUniformNumber(double interval_start, double interval_end) {
44  std::random_device rd;
45  std::mt19937 gen(rd());
46  std::uniform_real_distribution<double> dis(interval_start, interval_end);
47  return dis(gen);
48 }
49 
50 double ErrorSimulation::genNormalDistNumber(double mean, double std_deviation) {
51  std::random_device rd;
52  std::mt19937 gen(rd());
53  std::normal_distribution<double> dis(mean, std_deviation);
54  return dis(gen);
55 }
56 
59  return genUniformNumber(0.0, 1.0) >= prob_pose_inval_;
60  }
61  return true;
62 }
63 
64 geometry_msgs::Pose ErrorSimulation::addNoiseToPosition(const geometry_msgs::Pose &pose) {
65  if (use_position_noise_) {
66  geometry_msgs::Pose result(pose);
70  return result;
71  }
72  return pose;
73 }
74 
75 geometry_msgs::Pose ErrorSimulation::addNoiseToOrientation(const geometry_msgs::Pose &pose) {
77  geometry_msgs::Pose result(pose);
78  Eigen::Quaternion<double> orientation(pose.orientation.w, pose.orientation.x, pose.orientation.y, pose.orientation.z);
79  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)));
80  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)));
81  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)));
82 
83  orientation = quat_x * quat_y * quat_z * orientation;
84  result.orientation.w = orientation.w();
85  result.orientation.x = orientation.x();
86  result.orientation.y = orientation.y();
87  result.orientation.z = orientation.z();
88  return result;
89  }
90  return pose;
91 }
92 
93 
94 void ErrorSimulation::setProbPoseInval(double prob_pose_inval) {
95  prob_pose_inval_ = prob_pose_inval;
96 }
97 void ErrorSimulation::setPoseNoiseDistMean(double pos_noise_dist_mean) {
98  pos_noise_dist_mean_ = pos_noise_dist_mean;
99 }
100 
101 void ErrorSimulation::setPoseNoiseDistDev(double pos_noise_dist_dev) {
102  pos_noise_dist_dev_ = pos_noise_dist_dev;
103 }
104 
105 void ErrorSimulation::setOrXNoiseDistMean(double or_x_noise_dist_mean) {
106  or_x_noise_dist_mean_ = or_x_noise_dist_mean;
107 }
108 
109 void ErrorSimulation::setOrXNoiseDistDev(double or_x_noise_dist_dev) {
110  or_x_noise_dist_dev_ = or_x_noise_dist_dev;
111 }
112 
113 void ErrorSimulation::setOrYNoiseDistMean(double or_y_noise_dist_mean) {
114  or_y_noise_dist_mean_ = or_y_noise_dist_mean;
115 }
116 
117 void ErrorSimulation::setOrYNoiseDistDev(double or_y_noise_dist_dev) {
118  or_y_noise_dist_dev_ = or_y_noise_dist_dev;
119 }
120 
121 void ErrorSimulation::setOrZNoiseDistMean(double or_z_noise_dist_mean) {
122  or_z_noise_dist_mean_ = or_z_noise_dist_mean;
123 }
124 
125 void ErrorSimulation::setOrZNoiseDistDev(double or_z_noise_dist_dev) {
126  or_z_noise_dist_dev_ = or_z_noise_dist_dev;
127 }
128 
129 }
double genUniformNumber(double interval_start, double interval_end)
Returns a value calculated on a uniform distribution.
void setOrZNoiseDistMean(double or_z_noise_dist_mean)
Sets the mean value of the normal distribution used by the orientation error generation (z-axis) ...
static const double DEFAULT_OR_Y_NOISE_DEV(0.02)
This class is used to simulate typical errors of an object recognition system.
double genNormalDistNumber(double mean, double std_deviation)
Returns a value calculated on a normal distribution.
static const double DEFAULT_OR_Z_NOISE_MEAN(0.0)
void setProbPoseInval(double prob_pose_inval)
Set the probability of the pose invalidation.
void setOrZNoiseDistDev(double or_z_noise_dist_dev)
Sets the standard deviation value of the normal distribution used by the orientation error generation...
ErrorSimulation()
The constructor of this class.
geometry_msgs::Pose addNoiseToOrientation(const geometry_msgs::Pose &pose)
Adds error values to the given pose (orientation only)
void setOrYNoiseDistDev(double or_y_noise_dist_dev)
Sets the standard deviation value of the normal distribution used by the orientation error generation...
void setOrXNoiseDistMean(double or_x_noise_dist_mean)
Sets the mean value of the normal distribution used by the orientation error generation (x-axis) ...
static const double DEFAULT_OR_X_NOISE_DEV(0.02)
static const double DEFAULT_OR_Y_NOISE_MEAN(0.0)
static const double DEFAULT_OR_Z_NOISE_DEV(0.02)
void setOrYNoiseDistMean(double or_y_noise_dist_mean)
Sets the mean value of the normal distribution used by the orientation error generation (y-axis) ...
bool poseInvalidation()
Invalidates a pose by the probability member of this class.
static const double DEFAULT_POS_NOISE_DEV(0.005)
void setPoseNoiseDistMean(double pos_noise_dist_mean)
Sets the mean value of the normal distribution used by the position error generation.
static const double DEFAULT_OR_X_NOISE_MEAN(0.0)
geometry_msgs::Pose addNoiseToPosition(const geometry_msgs::Pose &pose)
Adds error values to the given pose (position only)
void setPoseNoiseDistDev(double pos_noise_dist_dev)
Sets the standard deviation value of the normal distribution used by the position error generation...
static const double DEFAULT_PROB_POSE_INVAL(0.01)
static const double DEFAULT_POS_NOISE_MEAN(0.0)
void setOrXNoiseDistDev(double or_x_noise_dist_dev)
Sets the standard deviation value of the normal distribution used by the orientation error generation...


asr_fake_object_recognition
Author(s): Allgeyer Tobias, Aumann Florian, Borella Jocelyn, Meißner Pascal, Qattan Mohamad
autogenerated on Wed Feb 19 2020 03:58:59