Skip to content

Commit 4ca0179

Browse files
committed
Lots of changes, latest change was support for OpenStreetmaps
1 parent ae42f2c commit 4ca0179

File tree

8 files changed

+965
-116
lines changed

8 files changed

+965
-116
lines changed

CMakeLists.txt

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ project(ros2ascii)
33

44
## Compile as C++11, supported in ROS Kinetic and newer
55
# add_compile_options(-std=c++11)
6+
set(CMAKE_CXX_STANDARD 17)
67

78
## Find catkin macros and libraries
89
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
@@ -13,7 +14,10 @@ find_package(catkin REQUIRED COMPONENTS
1314
std_msgs
1415
geometry_msgs
1516
sensor_msgs
16-
message_generation
17+
# message_generation
18+
tf2
19+
tf2_ros
20+
geodesy
1721
)
1822

1923
## System dependencies are found with CMake's conventions
@@ -72,10 +76,10 @@ find_package(catkin REQUIRED COMPONENTS
7276
# )
7377

7478
## Generate added messages and services with any dependencies listed here
75-
generate_messages(
76-
DEPENDENCIES
77-
std_msgs
78-
)
79+
#generate_messages(
80+
# DEPENDENCIES
81+
# std_msgs
82+
# )
7983

8084
################################################
8185
## Declare ROS dynamic reconfigure parameters ##
@@ -107,7 +111,7 @@ generate_messages(
107111
## CATKIN_DEPENDS: catkin_packages dependent projects also need
108112
## DEPENDS: system dependencies of this project that dependent projects also need
109113
catkin_package(
110-
# INCLUDE_DIRS include #uncomment
114+
INCLUDE_DIRS include #uncomment
111115
# LIBRARIES can_speed_decoder
112116
# CATKIN_DEPENDS roscpp rospy std_msgs
113117
CATKIN_DEPENDS message_runtime
@@ -121,7 +125,7 @@ CATKIN_DEPENDS message_runtime
121125
## Specify additional locations of header files
122126
## Your package locations should be listed before other locations
123127
include_directories(
124-
# include
128+
include
125129
${catkin_INCLUDE_DIRS}
126130
)
127131

@@ -239,20 +243,9 @@ else()
239243
message(" - curses-gfx NOT found")
240244
endif()
241245

242-
#add_executable(gpsfix src/gps_node.cpp)
243-
#target_link_libraries(gpsfix ${catkin_LIBRARIES})
244-
245-
if(DEFINED LIBPANDA_FOUND)
246-
# add_executable(publish_libpanda src/publish_libpanda.cpp)
247-
# target_link_libraries(publish_libpanda ${catkin_LIBRARIES} libpandac.so) #libpandac.so
248-
endif()
249-
250-
#add_executable(cbf_smoother src/cbf_smoother.cpp)
251-
#target_link_libraries(cbf_smoother ${catkin_LIBRARIES})
252246

253247
if(DEFINED CURSES_GFX_FOUND)
254-
add_executable(radar2ascii src/radar2ascii.cpp)
248+
add_executable(radar2ascii src/radar2ascii.cpp src/osm-loader.cpp)
255249
target_link_libraries(radar2ascii ${catkin_LIBRARIES} ncurses cursesgfx)
256250
endif()
257251

258-
# message( " @@@@@@@@@@@@@@@@@@@@@@@ " ${PROJECT_SOURCE_DIR})

docs/.DS_Store

0 Bytes
Binary file not shown.

include/.DS_Store

6 KB
Binary file not shown.

include/19/135742/205619.png

10.2 KB
Loading

include/osm-loader.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
Author: Matt Bunting
3+
Copyright (c) 2023 Vanderbilt
4+
All rights reserved.
5+
6+
*/
7+
8+
/*
9+
This Documentaion
10+
*/
11+
12+
// https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
13+
14+
#ifndef OSM_LOADER_H
15+
#define OSM_LOADER_H
16+
17+
typedef struct _OsmTile {
18+
int zoom;
19+
int x;
20+
int y;
21+
} OsmTile;
22+
23+
OsmTile latLongToTile(int zoom, double longitude, double latitude);
24+
25+
26+
void tileToLatLong(const OsmTile& tile, double& longitude, double& latitude);
27+
double tileWidthInMeters(double latitude, int zoom);
28+
bool downloadTile(const OsmTile& tile, const char* cachedirectory, char* resultPath);
29+
30+
void longLatToOffsetMeters(int zoom, double longitude, double latitude, double& xOffset, double& yOffset);
31+
32+
#endif //OSM_LOADER_H

include/test.cpp

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Author: Matt Bunting
3+
Copyright (c) 2023 Vanderbilt
4+
All rights reserved.
5+
6+
*/
7+
8+
/*
9+
This Documentaion
10+
*/
11+
#include <iostream>
12+
#include <cstdio>
13+
14+
#include "osm-loader.h"
15+
16+
int main(void) {
17+
OsmTile result = latLongToTile(19, -86.7931535, 36.14507466666666);
18+
19+
printf("https://tile.openstreetmap.org/%d/%d/%d.png\n", result.zoom, result.x, result.y);
20+
21+
char tileFile[100];
22+
if(downloadTile(result, ".", tileFile)) {
23+
printf("Failed to download file!\n");
24+
return 1;
25+
}
26+
printf("File result: %s\n", tileFile);
27+
28+
29+
double latitude, longitude;
30+
tileToLatLong(result, longitude, latitude);
31+
printf("Upper left tile Longitude/Latitude: %f,%f\n", longitude, latitude);
32+
33+
34+
printf("Width of tile (meters): %f\n", tileWidthInMeters(latitude, result.zoom));
35+
return 0;
36+
};

src/osm-loader.cpp

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/*
2+
Author: Matt Bunting
3+
Copyright (c) 2023 Vanderbilt
4+
All rights reserved.
5+
6+
*/
7+
8+
/*
9+
This Documentaion
10+
*/
11+
12+
#include "osm-loader.h"
13+
14+
#include <cstdlib>
15+
#include <cstdio>
16+
#include <math.h>
17+
18+
// https://wiki.openstreetmap.org/wiki/Slippy_map_tilenames
19+
20+
OsmTile latLongToTile(int zoom, double longitude, double latitude) {
21+
OsmTile result;
22+
int n = 1 << zoom;
23+
result.x = n*((longitude + 180) / 360);
24+
double lat_rad = latitude*3.1415926535897/180.0;
25+
result.y = n*(1.0 - (log(tan(lat_rad) + 1.0/cos(lat_rad))/3.1415926535897))/2;
26+
result.zoom = zoom;
27+
return result;
28+
}
29+
30+
void longLatToOffsetMeters(int zoom, double longitude, double latitude, double& xOffset, double& yOffset) {
31+
OsmTile tile = latLongToTile( zoom, longitude, latitude);
32+
33+
double longTile, latTile;
34+
tileToLatLong(tile, longTile, latTile);
35+
36+
const double EARTH_CIR_METERS = 40075016.686;
37+
const double degreesPerMeter = 360 / EARTH_CIR_METERS;
38+
39+
double metersPerPixelEW = EARTH_CIR_METERS / (double)(1 << (zoom + 8));
40+
double metersPerPixelNS = EARTH_CIR_METERS / (double)(1 << (zoom + 8)) * cos(latitude*3.1415926535897/180.0);
41+
42+
// const shiftMetersEW = width/2 * metersPerPixelEW;
43+
// const shiftMetersNS = height/2 * metersPerPixelNS;
44+
45+
xOffset = ( longTile - longitude)/ degreesPerMeter* cos(latitude*3.1415926535897/180.0);
46+
yOffset = ( latTile - latitude)/ degreesPerMeter;
47+
48+
}
49+
50+
void tileToLatLong(const OsmTile& tile, double& longitude, double& latitude) {
51+
int n = 1 << tile.zoom;
52+
longitude = ((double)tile.x/(double)n) * 360.0 - 180.0;
53+
double lat_rad = atan(sinh(3.1415926535897*(1.0 - 2.0*((double)tile.y/(double)n))));
54+
latitude = lat_rad*180.0/3.1415926535897;
55+
}
56+
57+
double tileWidthInMeters(double latitude, int zoom) {
58+
return 156543.03 * cos(latitude*3.1415926535897/180.0) / (double)(1 << zoom) * 256; // each image is 256 pixels
59+
}
60+
61+
bool downloadTile(const OsmTile& tile, const char* cachedirectory, char* resultPath) {
62+
char command[256];
63+
64+
snprintf(resultPath, 200, "%s/%d/%d/%d.png", cachedirectory, tile.zoom, tile.x, tile.y);
65+
66+
snprintf(command, 256, "[ -f %s ]", resultPath);
67+
// printf("Executing command: %s\n", command);
68+
if(system(command) == 0) {
69+
return 0;
70+
}
71+
snprintf(command, 256, "mkdir -p %s/%d/%d", cachedirectory, tile.zoom, tile.x);
72+
// printf("Executing command: %s\n", command);
73+
system(command);
74+
// snprintf(command, 256, "curl --remove-on-error --max-time 3 https://tile.openstreetmap.org/%d/%d/%d.png -o %s", tile.zoom, tile.x, tile.y, resultPath);
75+
snprintf(command, 256, "curl --silent --max-time 2 https://tile.openstreetmap.org/%d/%d/%d.png -o %s", tile.zoom, tile.x, tile.y, resultPath);
76+
// printf("Executing command: %s\n", command);
77+
78+
if(system(command) != 0) {
79+
return 1;
80+
}
81+
82+
return 0;
83+
}

0 commit comments

Comments
 (0)