ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ROS gpsd client Subscriber node (fix)

asked 2018-03-20 14:48:19 -0500

Khan gravatar image

updated 2018-03-21 13:31:37 -0500

I want to write subscriber node for ROS GPSD client which is publishing GPS coordinates on topic "/fix". I don't know exactly what would be the right code and what changes I have to make in CMakeList.txt and package.xml. Below is the code

#include <ros/ros.h>
#include <sensor_msgs/NavSatStatus.h>  
#include <sensor_msgs/NavSatFix.h>
using namespace gps_common;
void callback(const sensor_msgs::NavSatFixConstPtr& fix) {
  if (fix->status.status == sensor_msgs::NavSatStatus::STATUS_NO_FIX) {
   ROS_INFO("No fix.");
   return;
 }

 if (fix->header.stamp == ros::Time(0)) {
   return;
}
printf("\n Latitude = %f and Logitude = %f ",fix->latitude, fix->logitude);  
}

int main (int argc, char **argv) {
 ros::init(argc, argv, "gps_collect");
 ros::NodeHandle node;
 ros::Subscriber fix_sub = node.subscribe("fix", 10, callback);
 ros::spin();
 return 0;
}
edit retag flag offensive close merge delete

Comments

Have you gone through the tutorials? These cover the basics (subscribing, publishing, etc.) pretty well. Are you getting any errors that you can post? I can't imagine that this code compiles with return statements in a void function.

jayess gravatar image jayess  ( 2018-03-20 16:46:48 -0500 )edit

Also, in one of your includes you're mixing " with <.

jayess gravatar image jayess  ( 2018-03-20 16:47:54 -0500 )edit

And just to make sure you've seen it: gpsd_client. There's nothing wrong with wanting to learn how to do something yourself btw.

gvdhoorn gravatar image gvdhoorn  ( 2018-03-21 02:05:06 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-03-26 11:06:31 -0500

Khan gravatar image

updated 2018-03-26 11:24:48 -0500

The code is fine and its working. Thanks

edit flag offensive delete link more

Comments

1

To whom are you addressing this comment? @jayess was right: before you edited the code in your question text, there was mixup with " instead of < in one of your #include statements.

gvdhoorn gravatar image gvdhoorn  ( 2018-03-26 11:12:09 -0500 )edit
1

If you've resolved your problem then please post the solution. If not, then please turn your answer into a comment.

gvdhoorn gravatar image gvdhoorn  ( 2018-03-26 11:12:35 -0500 )edit

If I am working on ROS and dont know to deal with syntax error then I would say I need to learn basic C/C++. Anyways I never had these brackets error, those were bcs of copy and paste. The problem here was I have to make few changes in CMakelist.txt and Package.xml file.

Khan gravatar image Khan  ( 2018-03-26 11:20:21 -0500 )edit

The above code is solution for capturing GPS Coordinates from fix(ros gpsgd client topic); Extra things you need is the right CMakelist.txt(add sensor_msgs) and Package.xml. Thanks and sorry for inconvenience

Khan gravatar image Khan  ( 2018-03-26 11:22:52 -0500 )edit

Question Tools

1 follower

Stats

Asked: 2018-03-20 14:48:19 -0500

Seen: 341 times

Last updated: Mar 26 '18