Skip to content

Commit 926b78e

Browse files
committed
added failsafe for dgps startup
1 parent 648a983 commit 926b78e

File tree

7 files changed

+97
-4
lines changed

7 files changed

+97
-4
lines changed

glider/config/glider-params.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,11 @@ imu:
99
frame: "enu"
1010
gps:
1111
covariance: 2.0
12-
dgpsfm:
12+
dgps:
1313
enable: true
14+
covariance: 0.03
15+
dgpsfm:
16+
enable: false
1417
integration_threshold: 1.0
1518
covariance: 0.03
1619
constants:

glider/config/ros-params.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ glider_node:
55
nav_sat_fix: false
66
viz:
77
use: true
8-
origin_easting: 482933.2819920078
9-
origin_northing: 4421345.135559781
8+
origin_easting: 753912.0063845584
9+
origin_northing: 3385461.6073698294
1010
subscribers:
1111
use_odom: false

glider/include/glider/utils/parameters.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ struct Parameters
8181
// @brief heading noise for differential gps from motion
8282
double dgpsfm_cov;
8383

84+
bool use_dgps;
85+
double dgps_cov;
86+
8487
// @brief translation from the GPS to the IMU
8588
Eigen::Vector3d t_imu_gps;
8689
};

glider/launch/glider-node.launch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def generate_launch_description():
6262
'use_odom': False}
6363
],
6464
remappings=[
65-
('/gps', '/ublox_gps_node/fix'),
65+
('/dgps', '/dgps/fix'),
6666
('/imu', '/vectornav/imu'),
6767
('/odom', '/Odometry'),
6868
]

glider/scripts/dgps_to_gps.py

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import rclpy
2+
from rclpy.node import Node
3+
4+
from gps_msgs.msg import GPSFix
5+
from dgps_msgs.msg import DifferentialNavSatFix
6+
from sensor_msgs.msg import NavSatStatus
7+
8+
9+
def differential_nav_sat_fix_to_gps_fix(msg: DifferentialNavSatFix) -> GPSFix:
10+
"""Convert a DifferentialNavSatFix message to a GPSFix message."""
11+
fix = GPSFix()
12+
13+
# --- Header ---
14+
fix.header = msg.nmea.header
15+
16+
# --- Position (lat / lon / alt) ---
17+
fix.latitude = msg.nmea.latitude
18+
fix.longitude = msg.nmea.longitude
19+
fix.altitude = msg.nmea.altitude
20+
21+
# --- Position covariance ---
22+
# NavSatFix carries a 3x3 ENU position covariance (row-major).
23+
# GPSFix uses the same layout, so copy it directly.
24+
fix.position_covariance = list(msg.nmea.position_covariance)
25+
fix.position_covariance_type = msg.nmea.position_covariance_type
26+
27+
# --- Heading (track) and its error ---
28+
# DifferentialNavSatFix provides a heading (degrees) and scalar covariance.
29+
# GPSFix stores course-over-ground as `track` and its 1-sigma error as
30+
# `err_track` (also degrees).
31+
fix.track = float(msg.heading)
32+
fix.err_track = float(msg.heading_covariance) ** 0.5 # variance -> std-dev
33+
34+
return fix
35+
36+
37+
class DgpsConverterNode(Node):
38+
39+
INPUT_TOPIC = '/dgps/dfix'
40+
OUTPUT_TOPIC = '/dgps/fix'
41+
QUEUE_DEPTH = 10
42+
43+
def __init__(self):
44+
super().__init__('dgps_converter')
45+
46+
self._pub = self.create_publisher(
47+
GPSFix,
48+
self.OUTPUT_TOPIC,
49+
self.QUEUE_DEPTH,
50+
)
51+
52+
self._sub = self.create_subscription(
53+
DifferentialNavSatFix,
54+
self.INPUT_TOPIC,
55+
self._callback,
56+
self.QUEUE_DEPTH,
57+
)
58+
59+
self.get_logger().info(
60+
f'dgps_converter ready: '
61+
f'{self.INPUT_TOPIC} (DifferentialNavSatFix) -> '
62+
f'{self.OUTPUT_TOPIC} (GPSFix)'
63+
)
64+
65+
def _callback(self, msg: DifferentialNavSatFix) -> None:
66+
self._pub.publish(differential_nav_sat_fix_to_gps_fix(msg))
67+
68+
69+
def main(args=None):
70+
rclpy.init(args=args)
71+
node = DgpsConverterNode()
72+
try:
73+
rclpy.spin(node)
74+
except KeyboardInterrupt:
75+
pass
76+
finally:
77+
node.destroy_node()
78+
rclpy.try_shutdown()
79+
80+
81+
if __name__ == '__main__':
82+
main()

glider/src/glider.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@ Glider::Glider(const std::string& path)
3434
LOG(INFO) << "[GLIDER] Using IMU frame: " << frame_;
3535
LOG(INFO) << "[GLIDER] Using Fixed Lag Smoother: " << std::boolalpha << params.smooth;
3636
LOG(INFO) << "[GLIDER] Using DGPS From Motion: " << std::boolalpha << params.use_dgpsfm;
37+
LOG(INFO) << "[GLIDER] Using DGPS: " << std::boolalpha << params.use_dgps;
38+
assert(!(params.use_dgpsfm && params.use_dgps) && "Both DGPS and DGPS From Motion are set to true, this is not allowed");
3739
LOG(INFO) << "[GLIDER] Glider initialized";
3840
}
3941

glider/src/parameters.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ Glider::Parameters::Parameters(const std::string& path)
4040
dgpsfm_threshold = config["dgpsfm"]["integration_threshold"].as<double>();
4141
dgpsfm_cov = config["dgpsfm"]["covariance"].as<double>();
4242

43+
use_dgps = config["dgps"]["enable"].as<bool>();
44+
dgps_cov = config["dgps"]["covariance"].as<double>();
45+
4346
t_imu_gps(0) = config["gps_to_imu"]["x"].as<double>();
4447
t_imu_gps(1) = config["gps_to_imu"]["y"].as<double>();
4548
t_imu_gps(2) = config["gps_to_imu"]["z"].as<double>();

0 commit comments

Comments
 (0)