48 GetSDFParam<double>(_sdf,
"gyroscope_noise_density",
51 GetSDFParam<double>(_sdf,
"gyroscope_bias_random_walk",
54 GetSDFParam<double>(_sdf,
"gyroscope_bias_correlation_time",
58 "Gyroscope bias correlation time must be greater than zero");
59 GetSDFParam<double>(_sdf,
"gyroscope_turn_on_bias_sigma",
62 GetSDFParam<double>(_sdf,
"accelerometer_noise_density",
65 GetSDFParam<double>(_sdf,
"accelerometer_random_walk",
68 GetSDFParam<double>(_sdf,
"accelerometer_bias_correlation_time",
72 "Accelerometer bias correlation time must be greater than zero");
73 GetSDFParam<double>(_sdf,
"accelerometer_turn_on_bias_sigma",
76 GetSDFParam<double>(_sdf,
"orientation_noise",
98 this->
imuROSMessage.linear_acceleration_covariance[0] = accelVar;
99 this->
imuROSMessage.linear_acceleration_covariance[4] = accelVar;
100 this->
imuROSMessage.linear_acceleration_covariance[8] = accelVar;
106 this->
imuROSMessage.orientation_covariance[0] = orientationVar;
107 this->
imuROSMessage.orientation_covariance[4] = orientationVar;
108 this->
imuROSMessage.orientation_covariance[8] = orientationVar;
111 #if GAZEBO_MAJOR_VERSION >= 8 144 this->
gazeboNode->Advertise<sensor_msgs::msgs::Imu>(
162 #if GAZEBO_MAJOR_VERSION >= 8 163 common::Time curTime = this->
world->SimTime();
165 common::Time curTime = this->
world->GetSimTime();
170 ignition::math::Pose3d worldLinkPose;
171 ignition::math::Vector3d refLinVel;
172 ignition::math::Vector3d bodyAngVel;
173 ignition::math::Vector3d bodyLinAcc, worldLinAcc;
174 ignition::math::Vector3d refGravityWorld;
177 #if GAZEBO_MAJOR_VERSION >= 8 178 bodyAngVel = this->
link->RelativeAngularVel();
179 bodyLinAcc = this->
link->RelativeLinearAccel();
180 worldLinkPose = this->
link->WorldPose();
182 bodyAngVel = this->
link->GetRelativeAngularVel().Ign();
183 bodyLinAcc = this->
link->GetRelativeLinearAccel().Ign();
184 worldLinkPose = this->
link->GetWorldPose().Ign();
190 #if GAZEBO_MAJOR_VERSION >= 8 199 worldLinkPose.Pos() = worldLinkPose.Pos() - this->
referenceFrame.Pos();
200 worldLinkPose.Pos() = this->
referenceFrame.Rot().RotateVectorReverse(
201 worldLinkPose.Pos());
204 ignition::math::Vector3d gravityBody =
205 worldLinkPose.Rot().RotateVectorReverse(this->
gravityWorld);
209 bodyAngVel = this->
localNEDFrame.Rot().RotateVector(bodyAngVel);
210 bodyLinAcc = this->
localNEDFrame.Rot().RotateVector(bodyLinAcc);
211 gravityBody = this->
localNEDFrame.Rot().RotateVector(gravityBody);
244 sensor_msgs::msgs::Imu imuGazeboMessage;
246 for (
int i = 0; i < 9; i++)
251 imuGazeboMessage.add_angular_velocity_covariance(
253 this->imuParameters.gyroscopeNoiseDensity);
254 imuGazeboMessage.add_orientation_covariance(-1.0);
255 imuGazeboMessage.add_linear_acceleration_covariance(
257 this->imuParameters.accelerometerNoiseDensity);
262 imuGazeboMessage.add_angular_velocity_covariance(0.0);
263 imuGazeboMessage.add_orientation_covariance(-1.0);
264 imuGazeboMessage.add_linear_acceleration_covariance(0.0);
267 imuGazeboMessage.add_angular_velocity_covariance(
269 this->imuParameters.gyroscopeNoiseDensity);
270 imuGazeboMessage.add_orientation_covariance(-1.0);
271 imuGazeboMessage.add_linear_acceleration_covariance(
273 this->imuParameters.accelerometerNoiseDensity);
278 imuGazeboMessage.add_angular_velocity_covariance(0.0);
279 imuGazeboMessage.add_orientation_covariance(-1.0);
280 imuGazeboMessage.add_linear_acceleration_covariance(0.0);
283 imuGazeboMessage.add_angular_velocity_covariance(
285 this->imuParameters.gyroscopeNoiseDensity);
286 imuGazeboMessage.add_orientation_covariance(-1.0);
287 imuGazeboMessage.add_linear_acceleration_covariance(
289 this->imuParameters.accelerometerNoiseDensity);
294 gazebo::msgs::Quaternion * orientation =
new gazebo::msgs::Quaternion();
301 gazebo::msgs::Vector3d * linAcc =
new gazebo::msgs::Vector3d();
307 gazebo::msgs::Vector3d * angVel =
new gazebo::msgs::Vector3d();
312 imuGazeboMessage.set_allocated_orientation(orientation);
313 imuGazeboMessage.set_allocated_linear_acceleration(linAcc);
314 imuGazeboMessage.set_allocated_angular_velocity(angVel);
324 ignition::math::Vector3d& _angVel, ignition::math::Quaterniond& _orientation,
327 GZ_ASSERT(_dt > 0.0,
"Invalid time step");
336 double sigmaBGD = sqrt(- sigmaBG * sigmaBG * tauG / 2.0 *
337 (exp(-2.0 * _dt / tauG) - 1.0));
339 double phiGD = exp(-1.0 / tauG * _dt);
348 ignition::math::Vector3d(
353 ignition::math::Vector3d(
365 double sigmaBAD = sqrt(- sigmaBA * sigmaBA * tauA / 2.0 *
366 (exp(-2.0 * _dt / tauA) - 1.0));
368 double phiAD = exp(-1.0 / tauA * _dt);
378 ignition::math::Vector3d(
383 ignition::math::Vector3d(
393 ignition::math::Quaterniond error(1.0,
399 _orientation = _orientation * error;
physics::LinkPtr referenceLink
Reference link.
double GetGaussianNoise(double _amp)
Returns noise value for a function with zero mean from the default Gaussian noise model...
void publish(const boost::shared_ptr< M > &message) const
bool EnableMeasurement(const common::UpdateInfo &_info) const
Enables generation of simulated measurement if the timeout since the last update has been reached...
IMUROSPlugin()
Class constructor.
ignition::math::Pose3d referenceFrame
Pose of the reference frame wrt world frame.
physics::WorldPtr world
Pointer to the world.
IMUParameters imuParameters
IMU model parameters.
common::Time lastMeasurementTime
(Simulation) time when the last sensor measurement was generated.
double orientationNoise
Standard deviation of orientation noise per axis [rad].
double accelerometerNoiseDensity
Accelerometer noise density (two-sided spectrum) [m/s^2/sqrt(Hz)].
bool enableLocalNEDFrame
True if a the local NED frame needs to be broadcasted.
double gyroscopeBiasCorrelationTime
Gyroscope bias correlation time constant [s].
void SendLocalNEDTransform()
Returns true if the base_link_ned frame exists.
ignition::math::Vector3d gravityWorld
Gravity vector wrt. reference frame.
double noiseAmp
Noise amplitude.
void AddNoise(ignition::math::Vector3d &_linAcc, ignition::math::Vector3d &_angVel, ignition::math::Quaterniond &_orientation, double _dt)
Apply and add nosie model to ideal measurements.
double accelerometerTurnOnBiasSigma
Accelerometer turn on bias standard deviation [m/s^2].
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
Load plugin and its configuration from sdf,.
void UpdateReferenceFramePose()
Updates the pose of the reference frame wrt the world frame.
bool AddNoiseModel(std::string _name, double _sigma)
Add noise normal distribution to the list.
transport::NodePtr gazeboNode
Gazebo's node handle for transporting measurement messages.
double gyroscopeNoiseDensity
Gyroscope noise density (two-sided spectrum) [rad/s/sqrt(Hz)].
virtual ~IMUROSPlugin()
Class destructor.
virtual bool OnUpdate(const common::UpdateInfo &_info)
Update sensor measurement.
transport::PublisherPtr gazeboSensorOutputPub
Gazebo's publisher for transporting measurement messages.
ignition::math::Pose3d localNEDFrame
Pose of the local NED frame wrt link frame.
virtual void Load(physics::ModelPtr _model, sdf::ElementPtr _sdf)
Load the plugin.
ignition::math::Quaterniond measOrientation
(Simulation) time when the last sensor measurement was generated.
double gyroscopeTurnOnBiasSigma
Gyroscope turn on bias standard deviation [rad/s].
ignition::math::Vector3d gyroscopeBias
Current (drifting) gyroscope bias.
ignition::math::Vector3d measLinearAcc
Last measurement of linear acceleration..
physics::LinkPtr link
Pointer to the link.
double gyroscopeRandomWalk
Gyroscope bias random walk [rad/s/s/sqrt(Hz)].
ignition::math::Vector3d measAngularVel
Last measurement of angular velocity.
std::string sensorOutputTopic
Name of the sensor's output topic.
ros::Publisher rosSensorOutputPub
Gazebo's publisher for transporting measurement messages.
ignition::math::Vector3d gyroscopeTurnOnBias
Constant turn-on gyroscope bias.
boost::shared_ptr< ros::NodeHandle > rosNode
ROS node handle for communication with ROS.
GZ_REGISTER_MODEL_PLUGIN(GazeboRosP3D)
std::string robotNamespace
Robot namespace.
ignition::math::Vector3d accelerometerTurnOnBias
Constant turn-on accelerometer bias.
bool gazeboMsgEnabled
Flag set to true if the Gazebo sensors messages are supposed to be published as well (it can avoid un...
double accelerometerRandomWalk
Accelerometer bias random walk. [m/s^2/s/sqrt(Hz)].
void PublishState()
Publish the current state of the plugin.
ignition::math::Vector3d accelerometerBias
Current (drifting) accelerometer bias.
sensor_msgs::Imu imuROSMessage
ROS IMU message.
double accelerometerBiasCorrelationTime
Accelerometer bias correlation time constant [s].