00001
00012 #ifndef HARDWARE_SENSOR_INERTIAL_ADHOC_SIMULATOR_HPP_
00013 #define HARDWARE_SENSOR_INERTIAL_ADHOC_SIMULATOR_HPP_
00014
00015 #include "jafarConfig.h"
00016
00017 #include "jmath/jblas.hpp"
00018 #include "jmath/indirectArray.hpp"
00019
00020 #include "rtslam/hardwareEstimatorAbstract.hpp"
00021
00022
00023 namespace jafar {
00024 namespace rtslam {
00025 namespace hardware {
00026
00027 class HardwareSensorInertialAdhocSimulator: public HardwareSensorProprioAbstract
00028 {
00029 private:
00030 double dt;
00031 boost::shared_ptr<simu::AdhocSimulator> simulator;
00032 size_t robId;
00033
00034 private:
00035 struct estimator_params_t
00036 {
00037 double gravity;
00038 jblas::vec gyr_bias;
00039 jblas::vec gyr_gain;
00040 MultiDimNormalDistribution *gyr_noise;
00041 jblas::vec acc_bias;
00042 jblas::vec acc_gain;
00043 MultiDimNormalDistribution *acc_noise;
00044 double timestamps_correction;
00045
00046 estimator_params_t(): gravity(9.81),
00047 gyr_bias(3), gyr_gain(3), gyr_noise(NULL),
00048 acc_bias(3), acc_gain(3), acc_noise(NULL),
00049 timestamps_correction(0.0) {}
00050 ~estimator_params_t() { delete gyr_noise; delete acc_noise; }
00051 } params;
00052
00053 public:
00060 HardwareSensorInertialAdhocSimulator(kernel::VariableCondition<int> *condition, double freq, int bufferSize_,
00061 boost::shared_ptr<simu::AdhocSimulator> simulator, size_t robId):
00062 HardwareSensorProprioAbstract(condition, mOnline, bufferSize_, ctVar),
00063 dt(1./freq), simulator(simulator), robId(robId) {}
00064
00065 void setSyncConfig(double timestamps_correction = 0.0)
00066 {
00067 params.timestamps_correction = timestamps_correction;
00068 }
00069
00070 void setErrors(double gravity = 9.81,
00071 double gyr_bias = 0.0, double gyr_bias_noisestd = 0.0,
00072 double gyr_gain = 1.0, double gyr_gain_noisestd = 0.0,
00073 double gyr_noisestd = 0.0,
00074 double acc_bias = 0.0, double acc_bias_noisestd = 0.0,
00075 double acc_gain = 1.0, double acc_gain_noisestd = 0.0,
00076 double acc_noisestd = 0.0)
00077 {
00078 jblas::scalar_vec x, P;
00079 params.gravity = gravity;
00080
00081 x = jblas::scalar_vec(3, gyr_bias); P = jblas::scalar_vec(3, gyr_bias_noisestd*gyr_bias_noisestd);
00082 params.gyr_bias = MultiDimNormalDistribution(x, P, rtslam::rand()).get();
00083 x = jblas::scalar_vec(3, gyr_gain); P = jblas::scalar_vec(3, gyr_gain_noisestd*gyr_gain_noisestd);
00084 params.gyr_gain = MultiDimNormalDistribution(x, P, rtslam::rand()).get();
00085 x = jblas::scalar_vec(3, 0.0); P = jblas::scalar_vec(3, gyr_noisestd*gyr_noisestd);
00086 params.gyr_noise = new MultiDimNormalDistribution(x, P, rtslam::rand());
00087
00088 x = jblas::scalar_vec(3, acc_bias); P = jblas::scalar_vec(3, acc_bias_noisestd*acc_bias_noisestd);
00089 params.acc_bias = MultiDimNormalDistribution(x, P, rtslam::rand()).get();
00090 x = jblas::scalar_vec(3, acc_gain); P = jblas::scalar_vec(3, acc_gain_noisestd*acc_gain_noisestd);
00091 params.acc_gain = MultiDimNormalDistribution(x, P, rtslam::rand()).get();
00092 x = jblas::scalar_vec(3, 0.0); P = jblas::scalar_vec(3, acc_noisestd*acc_noisestd);
00093 params.acc_noise = new MultiDimNormalDistribution(x, P, rtslam::rand());
00094 }
00095 #if 0
00096 jblas::mat_indirect acquireReadings(double t1, double t2)
00097 {
00098 size_t n1 = (int)(t1/dt);
00099 size_t n2 = (int)(t2/dt +1-1e-4);
00100 size_t i = 0;
00101 for(size_t n = n1; n <= n2; ++n,++i)
00102 {
00103 double t = n*dt;
00104
00105 jblas::vec tmp = simulator->getRobotInertial(robId, t);
00106 ublas::subrange(tmp, 0, 3) = ublas::element_prod(ublas::subrange(tmp, 0, 3), params.acc_gain) +
00107 params.acc_bias + params.acc_noise->get();
00108 ublas::subrange(tmp, 3, 6) = ublas::element_prod(ublas::subrange(tmp, 3, 6), params.gyr_gain) +
00109 params.gyr_bias + params.gyr_noise->get();
00110
00111 buffer(i).data(0) = t + params.timestamps_correction;
00112 buffer(i).data(1) = tmp(0);
00113 buffer(i).data(2) = tmp(1);
00114 buffer(i).data(3) = tmp(2);
00115 buffer(i).data(4) = tmp(3);
00116 buffer(i).data(5) = tmp(4);
00117 buffer(i).data(6) = tmp(5);
00118 buffer(i).data(7) = 0.;
00119 buffer(i).data(8) = 0.;
00120 buffer(i).data(9) = 0.;
00121 }
00122 return ublas::project(buffer,
00123 jmath::ublasExtra::ia_set(ublas::range(0,i)),
00124 jmath::ublasExtra::ia_set(ublas::range(0,buffer.size2())));
00125 }
00126 #endif
00127 void releaseReadings() { }
00128 jblas::ind_array instantValues() { return jmath::ublasExtra::ia_set(1,10); }
00129 jblas::ind_array incrementValues() { return jmath::ublasExtra::ia_set(1,1); }
00130 };
00131
00132 }}}
00133
00134 #endif
00135