19 #include <gazebo/sensors/ImuSensor.hh> 20 #include <gazebo/physics/World.hh> 21 #include <ignition/math/Rand.hh> 27 accelerometer_data = ignition::math::Vector3d(0, 0, 0);
28 gyroscope_data = ignition::math::Vector3d(0, 0, 0);
29 orientation = ignition::math::Quaterniond(1,0,0,0);
36 sensor=
dynamic_cast<gazebo::sensors::ImuSensor*
>(sensor_.get());
40 ROS_FATAL(
"Error: Sensor pointer is NULL!");
44 if (
sdf->HasElement(
"initialOrientationAsReference"))
46 bool initial_orientation_as_reference =
sdf->Get<
bool>(
"initialOrientationAsReference");
47 ROS_INFO_STREAM(
"<initialOrientationAsReference> set to: "<< initial_orientation_as_reference);
48 if (!initial_orientation_as_reference) {
50 sensor->SetWorldToReferenceOrientation(ignition::math::Quaterniond::Identity);
64 ROS_FATAL(
"ROS has not been initialized!");
79 common::Time current_time =
sensor->LastUpdateTime();
106 imu_msg.orientation_covariance[0] = gn2;
107 imu_msg.orientation_covariance[4] = gn2;
108 imu_msg.orientation_covariance[8] = gn2;
109 imu_msg.angular_velocity_covariance[0] = gn2;
110 imu_msg.angular_velocity_covariance[4] = gn2;
111 imu_msg.angular_velocity_covariance[8] = gn2;
112 imu_msg.linear_acceleration_covariance[0] = gn2;
113 imu_msg.linear_acceleration_covariance[4] = gn2;
114 imu_msg.linear_acceleration_covariance[8] = gn2;
118 imu_msg.header.stamp.sec = current_time.sec;
119 imu_msg.header.stamp.nsec = current_time.nsec;
133 double U1 = ignition::math::Rand::DblUniform();
134 double U2 = ignition::math::Rand::DblUniform();
137 double Z0 = sqrt(-2.0 * ::log(U1)) * cos(2.0*M_PI * U2);
140 Z0 = sigma * Z0 + mu;
149 if (
sdf->HasElement(
"robotNamespace"))
156 std::string scoped_name =
sensor->ParentName();
157 std::size_t it = scoped_name.find(
"::");
164 if (
sdf->HasElement(
"topicName"))
176 if (
sdf->HasElement(
"frameName"))
183 ROS_FATAL(
"missing <frameName>, cannot proceed");
188 if (
sdf->HasElement(
"updateRateHZ"))
200 if (
sdf->HasElement(
"gaussianNoise"))
212 if (
sdf->HasElement(
"xyzOffset"))
214 offset.Pos() =
sdf->Get<ignition::math::Vector3d>(
"xyzOffset");
219 offset.Pos() = ignition::math::Vector3d(0, 0, 0);
224 if (
sdf->HasElement(
"rpyOffset"))
226 offset.Rot() = ignition::math::Quaterniond(
sdf->Get<ignition::math::Vector3d>(
"rpyOffset"));
231 offset.Rot() = ignition::math::Quaterniond::Identity;
double update_rate
Sensor update rate.
sdf::ElementPtr sdf
Pointer to the sdf config file.
std::string robot_namespace
The data is published on the topic named: /robot_namespace/topic_name.
ROSCPP_DECL bool isInitialized()
double GuassianKernel(double mu, double sigma)
Gaussian noise generator.
ros::Publisher imu_data_publisher
Ros Publisher for imu data.
Gazebo Ros imu sensor plugin.
double gaussian_noise
Gaussian noise.
ignition::math::Vector3d accelerometer_data
Linear acceleration data from the sensor.
ignition::math::Vector3d gyroscope_data
Angular velocity data from the sensor.
ros::NodeHandle * node
Ros NodeHandle pointer.
void publish(const boost::shared_ptr< M > &message) const
sensors::ImuSensor * sensor
Pointer to the sensor.
virtual void Load(sensors::SensorPtr sensor_, sdf::ElementPtr sdf_)
Load the sensor.
ignition::math::Quaterniond orientation
Orientation data from the sensor.
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
virtual void UpdateChild(const gazebo::common::UpdateInfo &)
Update the sensor.
#define ROS_WARN_STREAM(args)
virtual ~GazeboRosImuSensor()
Destructor.
bool LoadParameters()
Load the parameters from the sdf file.
common::Time last_time
last time on which the data was published.
sensor_msgs::Imu imu_msg
Ros IMU message.
#define ROS_INFO_STREAM(args)
gazebo::event::ConnectionPtr connection
Pointer to the update event connection.
std::string topic_name
The data is published on the topic named: /robot_namespace/topic_name.
uint32_t getNumSubscribers() const
ROSCPP_DECL void spinOnce()
ignition::math::Pose3d offset
Offset parameter, position part is unused.
std::string body_name
Name of the link of the IMU.