30 if (!sdf->HasElement(
"robotNamespace"))
36 namespace_ = sdf->GetElement(
"robotNamespace")->GetValue()->GetAsString();
38 if (!sdf->HasElement(
"bodyName"))
45 link_name_ = sdf->GetElement(
"bodyName")->GetValue()->GetAsString();
57 if (sdf->HasElement(
"frameId"))
59 frame_id_ = sdf->GetElement(
"frameId")->GetValue()->GetAsString();
61 if (sdf->HasElement(
"topicName"))
63 nmea_topic_ = sdf->GetElement(
"topicName")->GetValue()->GetAsString();
65 if (sdf->HasElement(
"publishRate"))
67 sdf->GetElement(
"publishRate")->GetValue()->Get(
publish_rate_);
69 if (sdf->HasElement(
"referenceLatitude"))
73 if (sdf->HasElement(
"referenceLongitude"))
77 if (sdf->HasElement(
"referenceHeading"))
84 if (sdf->HasElement(
"referenceAltitude"))
88 if (sdf->HasElement(
"positionGaussiaNoise"))
92 if (sdf->HasElement(
"orientationGaussiaNoise"))
96 if (sdf->HasElement(
"velocityGaussiaNoise"))
107 geometry_msgs::Vector3 vec;
147 ret = std::to_string(value);
155 for(
int i=1; i<sentence.size(); i++)
160 uint8_t rest = checksum%16;
161 uint8_t quotient = (checksum-rest)/16;
174 nmea_msgs::Sentence sentence;
176 sentence.header.stamp = stamp;
177 sentence.sentence =
"$GPGGA," +
getUnixTime(stamp) +
",";
179 std::string north_or_south;
182 north_or_south =
"N";
186 north_or_south =
"S";
188 sentence.sentence = sentence.sentence +
convertToDmm(lat) +
"," + north_or_south +
",";
190 std::string east_or_west;
199 sentence.sentence = sentence.sentence +
convertToDmm(lon) +
"," + east_or_west +
",1,08,1.0,";
200 sentence.sentence = sentence.sentence + std::to_string(
current_geo_pose_.position.altitude) +
",M,";
201 sentence.sentence = sentence.sentence + std::to_string(
current_geo_pose_.position.altitude) +
",M,,0000";
202 sentence.sentence = sentence.sentence +
getCheckSum(sentence.sentence);
208 nmea_msgs::Sentence sentence;
210 sentence.header.stamp = stamp;
211 sentence.sentence =
"$GPRMC," +
getUnixTime(stamp) +
",A,";
213 std::string north_or_south;
216 north_or_south =
"N";
220 north_or_south =
"S";
222 sentence.sentence = sentence.sentence +
convertToDmm(lat) +
"," + north_or_south +
",";
224 std::string east_or_west;
233 sentence.sentence = sentence.sentence +
convertToDmm(lon) +
"," + east_or_west +
",";
235 sentence.sentence = sentence.sentence + std::to_string(vel) +
",";
239 angle = angle + 360.0;
241 angle = (double)(
int)((angle*pow(10.0, 2)) + 0.9 ) * pow(10.0, -1);
242 sentence.sentence = sentence.sentence + std::to_string(angle) +
",";
243 sentence.sentence = sentence.sentence +
getUnixDay(stamp) +
",,,";
244 sentence.sentence = sentence.sentence +
"A";
245 sentence.sentence = sentence.sentence +
getCheckSum(sentence.sentence);
251 nmea_msgs::Sentence sentence;
253 sentence.header.stamp = stamp;
254 sentence.sentence =
"$GPVTG,";
258 angle = angle + 360.0;
260 angle = (double)(
int)((angle*pow(10.0, 2)) + 0.9 ) * pow(10.0, -1);
261 sentence.sentence = sentence.sentence + std::to_string(angle) +
",T,,M,";
263 sentence.sentence = sentence.sentence + std::to_string(vel_knot) +
",N,";
265 sentence.sentence = sentence.sentence + std::to_string(vel_kmph) +
",K,";
266 sentence.sentence = sentence.sentence +
",A";
267 sentence.sentence = sentence.sentence +
getCheckSum(sentence.sentence);
273 nmea_msgs::Sentence sentence;
275 sentence.header.stamp = stamp;
276 sentence.sentence =
"$GPHDT,";
278 double angle = -1*vec.z/M_PI*180;
281 angle = angle + 360.0;
283 sentence.sentence = sentence.sentence + std::to_string(angle) +
",T";
284 sentence.sentence = sentence.sentence +
getCheckSum(sentence.sentence);
291 time_t t = stamp.
sec;
293 utc_time = gmtime(&t);
294 int day = utc_time->tm_mday;
295 int month = utc_time->tm_mon;
296 int year = 1900 + utc_time->tm_year;
297 std::string year_str = std::to_string(year);
298 ret = std::to_string(day) + std::to_string(month) + year_str[2] + year_str[3];
305 time_t t = stamp.
sec;
307 utc_time = gmtime(&t);
308 int hour = utc_time->tm_hour;
309 int min = utc_time->tm_min;
310 int sec = utc_time->tm_sec;
311 uint32_t nsec = stamp.
nsec;
312 int csec = round((
double)nsec/std::pow(10,7));
313 std::string hour_str;
316 hour_str =
"0" + std::to_string(hour);
320 hour_str = std::to_string(hour);
325 min_str =
"0" + std::to_string(min);
329 min_str = std::to_string(min);
334 sec_str =
"0" + std::to_string(sec);
338 sec_str = std::to_string(sec);
340 ret = hour_str + min_str + sec_str +
"." + std::to_string(csec);
346 #if (GAZEBO_MAJOR_VERSION >= 8) 347 common::Time sim_time =
world_ptr_->SimTime();
349 common::Time sim_time =
world_ptr_->GetSimTime();
361 #if (GAZEBO_MAJOR_VERSION >= 8) 362 ignition::math::Pose3d pose =
link_ptr_->WorldPose();
363 ignition::math::Vector3d linear_velocity =
link_ptr_->WorldLinearVel();
368 gazebo::math::Pose pose =
link_ptr_->GetWorldPose();
369 gazebo::math::Vector3 linear_velocity =
link_ptr_->GetWorldLinearVel();
380 stamp.
sec = sim_time.sec;
381 stamp.
nsec = sim_time.nsec;
383 geometry_msgs::Quaternion current_utm_quat;
384 #if (GAZEBO_MAJOR_VERSION >= 8) 385 current_utm_quat.x = pose.Rot().X();
386 current_utm_quat.y = pose.Rot().Y();
387 current_utm_quat.z = pose.Rot().Z();
388 current_utm_quat.w = pose.Rot().W();
389 geometry_msgs::Vector3 current_utm_orientation
395 double r = std::sqrt(diff_x*diff_x + diff_y*diff_y);
401 current_utm_quat.x = pose.rot.x;
402 current_utm_quat.y = pose.rot.y;
403 current_utm_quat.z = pose.rot.z;
404 current_utm_quat.w = pose.rot.w;
410 double r = std::sqrt(diff_x*diff_x + diff_y*diff_y);
432 value = std::fabs(value);
433 int deg = std::floor(value);
434 std::stringstream ss;
435 ss << std::setprecision(7) << (value-(double)deg)*60.0;
436 ret = std::to_string(deg) + ss.str();
virtual void Update()
Update the sensor state and publish nmea sentence.
geometry_msgs::Quaternion convertEulerAngleToQuaternion(geometry_msgs::Vector3 euler)
nmea_msgs::Sentence getGPVTG(ros::Time stamp)
generate GPVTG sentence
constexpr double reference_altitude
initial altitude of the robot
double orientation_gaussian_noise_
std::string getUnixTime(ros::Time stamp)
Get Unix time from the timestmap.
std::string getHexString(uint8_t value)
void publish(const boost::shared_ptr< M > &message) const
std::string getUnixDay(ros::Time stamp)
Get Unix day from the timestamp.
virtual void Load(physics::ModelPtr model, sdf::ElementPtr sdf)
Load parameters for the nmea gps plugin.
geodesy::UTMPose initial_utm_pose_
double reference_longitude_
double reference_altitude_
geographic_msgs::GeoPose current_geo_pose_
physics::ModelPtr model_ptr_
double reference_latitude_
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
virtual void Reset()
Reset the nmea gps plugin.
std::string convertToDmm(double value)
Convert DDD -> DMM format.
constexpr double position_gaussiaa_noise
gaussian noise of the posision
double velocity_gaussian_noise_
constexpr double publish_rate
publish rate of the each sentence
static geographic_msgs::GeoPoint toMsg(double lat, double lon)
constexpr double reference_longitude
initial longitude of the robot
const std::string nmea_topic
topic name of the nmea_sentence topic
std::string getCheckSum(std::string sentence)
geometry_msgs::Twist current_twist_
boost::optional< gazebo::math::Pose > initial_gazebo_pose_
constexpr double reference_heading
nitial heading of the robot
boost::optional< common::Time > last_publish_timestamp_
nmea_msgs::Sentence getGPRMC(ros::Time stamp)
generate GPRMC sentence
std::unique_ptr< GpsSensorModel > sensor_model_ptr_
Publisher advertise(const std::string &topic, uint32_t queue_size, bool latch=false)
geometry_msgs::Vector3 convertQuaternionToEulerAngle(geometry_msgs::Quaternion quat)
physics::WorldPtr world_ptr_
double reference_heading_
ros::NodeHandle node_handle_
definition for the NmeaGpsPlugin class
event::ConnectionPtr update_connection_
Class for the GPS sensor model.
double position_gaussiaa_noise_
geographic_msgs::GeoPose initial_pose_
constexpr double orientation_gaussian_noise
gaussian noise of the orientation
physics::LinkPtr link_ptr_
nmea_msgs::Sentence getGPHDT(ros::Time stamp)
Class of the NMEA gps plugin.
nmea_msgs::Sentence getGPGGA(ros::Time stamp)
generate GPGGA sentence
constexpr double velocity_gaussian_noise
gaussian noise of the velocity
constexpr double reference_latitude
initial longitude of the robot