Cheetah Software  1.0
ImuSimulator< T > Class Template Reference

#include <ImuSimulator.h>

+ Inheritance diagram for ImuSimulator< T >:
+ Collaboration diagram for ImuSimulator< T >:

Public Member Functions

 ImuSimulator (SimulatorControlParameters &simSettings, u64 seed=0)
 
void updateVectornav (const FBModelState< T > &robotState, const FBModelStateDerivative< T > &robotStateD, VectorNavData *data)
 
void computeAcceleration (const FBModelState< T > &robotState, const FBModelStateDerivative< T > &robotStateD, Vec3< float > &acc, std::uniform_real_distribution< float > &dist, const RotMat< float > &R_body)
 
void updateCheaterState (const FBModelState< T > &robotState, const FBModelStateDerivative< T > &robotStateD, CheaterState< T > &state)
 

Private Attributes

SimulatorControlParameters_simSettings
 
std::mt19937 _mt
 
std::uniform_real_distribution< float > _vectornavGyroDistribution
 
std::uniform_real_distribution< float > _vectornavAccelerometerDistribution
 
std::uniform_real_distribution< float > _vectornavQuatDistribution
 
bool _vectorNavOrientationNoise = false
 

Detailed Description

template<typename T>
class ImuSimulator< T >

Definition at line 16 of file ImuSimulator.h.

Constructor & Destructor Documentation

template<typename T>
ImuSimulator< T >::ImuSimulator ( SimulatorControlParameters simSettings,
u64  seed = 0 
)
inlineexplicit

Definition at line 18 of file ImuSimulator.h.

19  : _simSettings(simSettings),
20  _mt(seed),
21  _vectornavGyroDistribution(-simSettings.vectornav_imu_gyro_noise,
22  simSettings.vectornav_imu_gyro_noise),
24  -simSettings.vectornav_imu_accelerometer_noise,
25  simSettings.vectornav_imu_accelerometer_noise),
26  _vectornavQuatDistribution(-simSettings.vectornav_imu_quat_noise,
27  simSettings.vectornav_imu_quat_noise) {
28  if (simSettings.vectornav_imu_quat_noise != 0) {
30  }
31  }
std::uniform_real_distribution< float > _vectornavQuatDistribution
Definition: ImuSimulator.h:53
SimulatorControlParameters & _simSettings
Definition: ImuSimulator.h:49
bool _vectorNavOrientationNoise
Definition: ImuSimulator.h:54
std::uniform_real_distribution< float > _vectornavGyroDistribution
Definition: ImuSimulator.h:51
std::uniform_real_distribution< float > _vectornavAccelerometerDistribution
Definition: ImuSimulator.h:52
std::mt19937 _mt
Definition: ImuSimulator.h:50

Member Function Documentation

template<typename T>
void ImuSimulator< T >::computeAcceleration ( const FBModelState< T > &  robotState,
const FBModelStateDerivative< T > &  robotStateD,
Vec3< float > &  acc,
std::uniform_real_distribution< float > &  dist,
const RotMat< float > &  R_body 
)

Definition at line 10 of file ImuSimulator.cpp.

References FBModelState< T >::bodyVelocity, FBModelStateDerivative< T >::dBodyVelocity, fillEigenWithRandom(), and spatial::spatialToLinearAcceleration().

13  {
14  // accelerometer noise
15  fillEigenWithRandom(acc, _mt, dist);
16 
17  // gravity (should be positive when robot is upright)
18  acc += (R_body * Vec3<float>(0, 0, 9.81));
19 
20  // acceleration
22  robotState.bodyVelocity)
23  .template cast<float>();
24 }
SVec< T > bodyVelocity
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
auto spatialToLinearAcceleration(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T2 > &v)
Definition: spatial.h:289
std::mt19937 _mt
Definition: ImuSimulator.h:50
void fillEigenWithRandom(Eigen::MatrixBase< T > &v, std::mt19937 &gen, std::uniform_real_distribution< typename T::Scalar > &dist)
Definition: utilities.h:75

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T>
void ImuSimulator< T >::updateCheaterState ( const FBModelState< T > &  robotState,
const FBModelStateDerivative< T > &  robotStateD,
CheaterState< T > &  state 
)

Definition at line 74 of file ImuSimulator.cpp.

References CheaterState< T >::acceleration, FBModelState< T >::bodyOrientation, FBModelState< T >::bodyPosition, FBModelState< T >::bodyVelocity, FBModelStateDerivative< T >::dBodyVelocity, CheaterState< T >::omegaBody, CheaterState< T >::orientation, CheaterState< T >::position, ori::quaternionToRotationMatrix(), spatial::spatialToLinearAcceleration(), and CheaterState< T >::vBody.

76  {
78  state.acceleration = (R_body * Vec3<T>(0, 0, 9.81)) +
80  robotStateD.dBodyVelocity, robotState.bodyVelocity);
81  state.orientation = robotState.bodyOrientation;
82  state.position = robotState.bodyPosition;
83  state.omegaBody = robotState.bodyVelocity.template head<3>();
84  state.vBody = robotState.bodyVelocity.template tail<3>();
85 }
Vec3< T > bodyPosition
SVec< T > bodyVelocity
Vec3< T > vBody
Definition: IMUTypes.h:25
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
auto spatialToLinearAcceleration(const Eigen::MatrixBase< T > &a, const Eigen::MatrixBase< T2 > &v)
Definition: spatial.h:289
Vec3< T > omegaBody
Definition: IMUTypes.h:24
Quat< T > orientation
Definition: IMUTypes.h:22
Vec3< T > acceleration
Definition: IMUTypes.h:26
Vec3< T > position
Definition: IMUTypes.h:23
Mat3< typename T::Scalar > quaternionToRotationMatrix(const Eigen::MatrixBase< T > &q)
typename Eigen::Matrix< T, 3, 3 > RotMat
Definition: cppTypes.h:18
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Quat< T > bodyOrientation

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

template<typename T>
void ImuSimulator< T >::updateVectornav ( const FBModelState< T > &  robotState,
const FBModelStateDerivative< T > &  robotStateD,
VectorNavData data 
)

Definition at line 28 of file ImuSimulator.cpp.

References VectorNavData::accelerometer, FBModelState< T >::bodyOrientation, FBModelState< T >::bodyVelocity, f(), fillEigenWithRandom(), VectorNavData::gyro, ori::integrateQuat(), VectorNavData::quat, and ori::quaternionToRotationMatrix().

30  {
31  // body orientation
33  robotState.bodyOrientation.template cast<float>());
34 
35  Quat<float> ori_quat;
36  // printf("imu ori: %f, %f, %f, %f\n",
37  // robotState.bodyOrientation[0],
38  // robotState.bodyOrientation[1],
39  // robotState.bodyOrientation[2],
40  // robotState.bodyOrientation[3] );
41 
42  // acceleration
43  computeAcceleration(robotState, robotStateD, data->accelerometer,
45 
46  // gyro
48  data->gyro +=
49  robotState.bodyVelocity.template head<3>().template cast<float>();
50 
51  // quaternion
53  Vec3<float> omegaNoise;
55  Quat<float> floatQuat = robotState.bodyOrientation.template cast<float>();
56  // data->quat = integrateQuat(floatQuat, omegaNoise, 1.0f);
57  ori_quat = integrateQuat(floatQuat, omegaNoise, 1.0f);
58  // printf("imu noised ori: %f, %f, %f, %f\n",
59  // robotState.bodyOrientation[0],
60  // robotState.bodyOrientation[1],
61  // robotState.bodyOrientation[2],
62  // robotState.bodyOrientation[3] );
63  } else {
64  // data->quat = robotState.bodyOrientation.template cast<float>();
65  ori_quat = robotState.bodyOrientation.template cast<float>();
66  }
67  data->quat[3] = ori_quat[0];
68  data->quat[0] = ori_quat[1];
69  data->quat[1] = ori_quat[2];
70  data->quat[2] = ori_quat[3];
71 }
SVec< T > bodyVelocity
std::uniform_real_distribution< float > _vectornavQuatDistribution
Definition: ImuSimulator.h:53
bool _vectorNavOrientationNoise
Definition: ImuSimulator.h:54
typename Eigen::Matrix< T, 4, 1 > Quat
Definition: cppTypes.h:58
typename Eigen::Matrix< T, 3, 1 > Vec3
Definition: cppTypes.h:26
Vec3< float > accelerometer
Definition: IMUTypes.h:14
Quat< typename T::Scalar > integrateQuat(const Eigen::MatrixBase< T > &quat, const Eigen::MatrixBase< T2 > &omega, T3 dt)
std::uniform_real_distribution< float > _vectornavGyroDistribution
Definition: ImuSimulator.h:51
std::uniform_real_distribution< float > _vectornavAccelerometerDistribution
Definition: ImuSimulator.h:52
std::mt19937 _mt
Definition: ImuSimulator.h:50
Quat< float > quat
Definition: IMUTypes.h:16
void computeAcceleration(const FBModelState< T > &robotState, const FBModelStateDerivative< T > &robotStateD, Vec3< float > &acc, std::uniform_real_distribution< float > &dist, const RotMat< float > &R_body)
Mat3< typename T::Scalar > quaternionToRotationMatrix(const Eigen::MatrixBase< T > &q)
Vec3< float > gyro
Definition: IMUTypes.h:15
typename Eigen::Matrix< T, 3, 3 > RotMat
Definition: cppTypes.h:18
void fillEigenWithRandom(Eigen::MatrixBase< T > &v, std::mt19937 &gen, std::uniform_real_distribution< typename T::Scalar > &dist)
Definition: utilities.h:75
EIGEN_MAKE_ALIGNED_OPERATOR_NEW Quat< T > bodyOrientation
MX f(const MX &x, const MX &u)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Member Data Documentation

template<typename T>
std::mt19937 ImuSimulator< T >::_mt
private

Definition at line 50 of file ImuSimulator.h.

template<typename T>
SimulatorControlParameters& ImuSimulator< T >::_simSettings
private

Definition at line 49 of file ImuSimulator.h.

template<typename T>
std::uniform_real_distribution<float> ImuSimulator< T >::_vectornavAccelerometerDistribution
private

Definition at line 52 of file ImuSimulator.h.

template<typename T>
std::uniform_real_distribution<float> ImuSimulator< T >::_vectornavGyroDistribution
private

Definition at line 51 of file ImuSimulator.h.

template<typename T>
bool ImuSimulator< T >::_vectorNavOrientationNoise = false
private

Definition at line 54 of file ImuSimulator.h.

template<typename T>
std::uniform_real_distribution<float> ImuSimulator< T >::_vectornavQuatDistribution
private

Definition at line 53 of file ImuSimulator.h.


The documentation for this class was generated from the following files: