-
Notifications
You must be signed in to change notification settings - Fork 94
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
base: master
Are you sure you want to change the base?
Conversation
Perhaps should remove |
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. |
@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? |
Sorry, I saw this and your other PR. I'll try to get to it today or Monday. |
There was a problem hiding this 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.
# 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() | ||
|
There was a problem hiding this comment.
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.
#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 | ||
|
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also good.
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 |
There was a problem hiding this comment.
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.
case GPSD_STATUS_DGPS_FIX: | ||
fix.status.status = NavSatStatus::STATUS_GBAS_FIX; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably not needed.
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; | ||
|
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
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 |
This pull request includes a few code cleanup changes. If you would prefer these as separate pull requests, please let me know.
Uses CMake's built-in
find_library
to findlibgps
rather than relying onpkg-config
, which is not populated by default on Debian.Upgrades
package.xml
to version 2 and promotessensor_msgs
andgps_common
to runtime dependencies. Previously, these were only build time dependencies, which means thatros-noetic-gpsd-client
will not auto-installros-noetic-gps-common
and hence the message definitions will not be available (rostopic echo /extended_fix
will error, etc.)Changes
process_data_navsat
to not allocate a newNavSatFix
object each time. Theprocess_data_gps
function did not have this problem.Provides a slightly hacky workaround to the fact that
gps.h
pollutes the global namespace with its macro definitions likeSTATUS_NO_FIX
. This removes the need to hardcode the enum values forNavSatStatus::STATUS_NO_FIX
etc.Removes the hardcoded default port number and instead uses
DEFAULT_GPSD_PORT
.Frees the allocated
gpsmm
instance whenstop()
is called, eliminating an extremely minor memory leak.