Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few build improvements and code cleanup changes #57

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

rgov
Copy link

@rgov rgov commented Apr 23, 2022

This pull request includes a few code cleanup changes. If you would prefer these as separate pull requests, please let me know.

  1. Uses CMake's built-in find_library to find libgps rather than relying on pkg-config, which is not populated by default on Debian.

  2. Upgrades package.xml to version 2 and promotes sensor_msgs and gps_common to runtime dependencies. Previously, these were only build time dependencies, which means that ros-noetic-gpsd-client will not auto-install ros-noetic-gps-common and hence the message definitions will not be available (rostopic echo /extended_fix will error, etc.)

  3. Changes process_data_navsat to not allocate a new NavSatFix object each time. The process_data_gps function did not have this problem.

  4. Provides a slightly hacky workaround to the fact that gps.h pollutes the global namespace with its macro definitions like STATUS_NO_FIX. This removes the need to hardcode the enum values for NavSatStatus::STATUS_NO_FIX etc.

  5. Removes the hardcoded default port number and instead uses DEFAULT_GPSD_PORT.

  6. Frees the allocated gpsmm instance when stop() is called, eliminating an extremely minor memory leak.

@rgov
Copy link
Author

rgov commented Apr 23, 2022

Perhaps should remove <build_depend>pkg-config</build_depend> now that it isn't truly needed.

@danthony06
Copy link
Collaborator

I haven't forgotten about this. I think 1, 2, and 5 make a lot of sense. I'm looking at refactoring the code significantly to help reduce the number of conditional compilation blocks we're using, and I think that might catch several of your other changes.

@rgov
Copy link
Author

rgov commented Jun 29, 2023

@danthony06 For what it's worth, this included the fix to #78 already, and did it in a way that doesn't add a lot more #ifdefs. Is there still any interest in getting this merged?

@danthony06
Copy link
Collaborator

Sorry, I saw this and your other PR. I'll try to get to it today or Monday.

Copy link
Collaborator

@danthony06 danthony06 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall, looks good. There's been a few updates to ros2-devel to handle the newer API that obsoletes some changes, and the package.xml change isn't needed any more, but everything else looks like a valuable update.

Comment on lines +14 to +33
# Try to find libgps, first with CMake's usual library search method, then by
# querying pkg-config.
find_library(libgps_LIBRARIES NAMES gps)
find_path(libgps_INCLUDE_DIRS NAMES libgpsmm.h gps.h)

if(NOT libgps_LIBRARIES)
message(STATUS "Checking pkg-config for libgps")
find_package(PkgConfig)
if(PkgConfig_FOUND)
pkg_check_modules(libgps libgps)
endif()
endif()

if(NOT libgps_LIBRARIES)
message(FATAL_ERROR "Could not find libgps "
"(hint for Debian/Ubuntu: apt install libgps-dev)")
else()
message(STATUS "Found libgps: ${libgps_LIBRARIES}")
endif()

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, I really like this change.

gpsd_client/package.xml Show resolved Hide resolved
Comment on lines +1 to +23
#include <libgpsmm.h>

// gps.h defines some macros which conflict with enum values in NavSatStatus.h,
// so we map them to new names before including other headers.
#ifdef STATUS_FIX
enum {
GPSD_STATUS_NO_FIX = STATUS_NO_FIX,
GPSD_STATUS_FIX = STATUS_FIX,
GPSD_STATUS_DGPS_FIX = STATUS_DGPS_FIX,
};
#undef STATUS_NO_FIX
#undef STATUS_FIX
#undef STATUS_DGPS_FIX
#else
// Renamed in gpsd >= 3.23.1 (commits d4a4d8d3, af3b7dc0, 7d7b889f) without
// revising the API version number.
enum {
GPSD_STATUS_NO_FIX = STATUS_UNK,
GPSD_STATUS_FIX = STATUS_GPS,
GPSD_STATUS_DGPS_FIX = STATUS_DGPS,
};
#endif

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is obsolete with some of the other changes that have been made to ros2-devel

@@ -23,12 +46,12 @@ class GPSDClient {
privnode.param("frame_id", frame_id, frame_id);

std::string host = "localhost";
int port = 2947;
int port = atoi(DEFAULT_GPSD_PORT);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, I like this change.

privnode.getParam("host", host);
privnode.getParam("port", port);

char port_s[12];
snprintf(port_s, 12, "%d", port);
snprintf(port_s, sizeof(port_s), "%d", port);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also good.

gpsd_client/src/client.cpp Show resolved Hide resolved
Comment on lines +263 to +269
case GPSD_STATUS_NO_FIX:
fix.status.status = NavSatStatus::STATUS_NO_FIX;
break;
// STATUS_DGPS_FIX was removed in API version 6 but re-added afterward and next renamed since the version 12
case GPSD_STATUS_FIX:
fix.status.status = NavSatStatus::STATUS_FIX;
break;
// STATUS_DGPS_FIX was removed in API version 6 but re-added afterward
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is needed any more.

Comment on lines +271 to +272
case GPSD_STATUS_DGPS_FIX:
fix.status.status = NavSatStatus::STATUS_GBAS_FIX;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not needed.

Comment on lines +277 to 282
fix.status.service = NavSatStatus::SERVICE_GPS;

fix->latitude = p->fix.latitude;
fix->longitude = p->fix.longitude;
fix->altitude = p->fix.altitude;
fix.latitude = p->fix.latitude;
fix.longitude = p->fix.longitude;
fix.altitude = p->fix.altitude;

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

fix->position_covariance_type = NavSatFix::COVARIANCE_TYPE_DIAGONAL_KNOWN;
fix.position_covariance_type = std::isnan(p->fix.epx) ?
NavSatFix::COVARIANCE_TYPE_UNKNOWN :
NavSatFix::COVARIANCE_TYPE_DIAGONAL_KNOWN;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@danthony06
Copy link
Collaborator

Ah, sorry, I just noticed you were making the changes for ROS1, not ROS2. Let me see if I can backport the API changes for v12 from the ros2-devel branch back to master so that we have a consistent implementation across the two.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants