Skip to content

Commit e0e3c58

Browse files
committed
some updates from the spine mapper
1 parent 262972e commit e0e3c58

File tree

11 files changed

+76
-38
lines changed

11 files changed

+76
-38
lines changed

glider/config/graph_params.yaml renamed to glider/config/example-params.yaml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ gyroscope_covariance: 0.0001
33
integration_covariance: 0.001
44
bias_covariance: 0.001
55
use_second_order: 0.0
6-
origin_x: 482990.7375634047
7-
origin_y: 4421250.443879729
86
gravity: 9.81
97
bias_num_measurements: 100
108
gps_noise: 2.0
Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
glider_node:
22
ros__parameters:
33
rate: 100.0
4-
use_odom: true
4+
use_odom: false
5+
viz: true
56
publish_nav_sat_fix: false
67
utm_zone: "18S"
78
declination: 11.82
9+
origin_easting: 482933.2819920078
10+
origin_northing: 4421345.135559781
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
accelerometer_covariance: 0.00001
2+
gyroscope_covariance: 0.00001
3+
integration_covariance: 0.001
4+
bias_covariance: 0.001
5+
use_second_order: 0.0
6+
gravity: 9.81
7+
bias_num_measurements: 100
8+
gps_noise: 1.5
9+
odom_noise: 0.5
10+
heading_noise: 0.1
11+
odom_orientation_noise: 0.1
12+
odom_translation_noise: 1.0
13+
odom_scale_noise: 50.0
14+
lag_time: 10.0
15+
imu_frame: "enu"
16+
scale_odom: true
17+
correct_imu: true

glider/include/glider/utils/parameters.hpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ struct Parameters
2222
double integration_cov;
2323
double bias_cov;
2424
double use_second_order;
25-
double origin_x;
26-
double origin_y;
2725
double gravity;
2826
double gps_noise;
2927
double heading_noise;

glider/include/ros/glider_node.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ class GliderNode : public rclcpp::Node
5858

5959
// publishers
6060
rclcpp::Publisher<nav_msgs::msg::Odometry>::SharedPtr odom_pub_;
61+
rclcpp::Publisher<nav_msgs::msg::Odometry>::SharedPtr odom_viz_pub_;
6162
rclcpp::Publisher<sensor_msgs::msg::NavSatFix>::SharedPtr gps_pub_;
6263

6364
// timers
@@ -67,8 +68,11 @@ class GliderNode : public rclcpp::Node
6768
bool initialized_;
6869
bool use_sim_time_;
6970
bool publish_nsf_;
71+
bool viz_;
7072
std::string utm_zone_;
7173
double declination_;
74+
double origin_easting_;
75+
double origin_northing_;
7276

7377
// tracker
7478
Glider::State current_state_;

glider/launch/glider-node.launch.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,13 @@ def generate_launch_description():
3131
ros_params_file = PathJoinSubstitution([
3232
glider_share,
3333
'config',
34-
'ros_params.yaml'
34+
'ros-params.yaml'
3535
])
3636

3737
graph_params_file = PathJoinSubstitution([
3838
glider_share,
3939
'config',
40-
'graph_params.yaml'
40+
'vectornav-vn100t.yaml'
4141
])
4242

4343
# Create the glider node
@@ -53,9 +53,9 @@ def generate_launch_description():
5353
'use_odom': use_odom}
5454
],
5555
remappings=[
56-
('/gps', '/ublox/fix'),
57-
('/imu', '/VN100T/imu'),
58-
('/mag', '/VN100T/mag'),
56+
('/gps', '/ublox_gps_node/fix'),
57+
('/imu', '/vectornav/imu'),
58+
('/mag', '/vectornav/magnetic'),
5959
('/odom', '/Odometry'),
6060
]
6161
)

glider/ros/conversions.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ Output Conversions::odomToRos(Glider::Odometry& odom, const char* zone)
224224
msg.twist.twist.linear.x = v(0);
225225
msg.twist.twist.linear.y = v(1);
226226
msg.twist.twist.linear.z = v(2);
227-
msg.header = getHeader(odom.getTimestamp(), "enu-utm");
227+
msg.header = getHeader(odom.getTimestamp(), "enu");
228228

229229
return msg;
230230
}
@@ -303,7 +303,7 @@ Output Conversions::stateToRos(Glider::State& state, const char* zone)
303303
msg.twist.covariance[i * cov.rows() + j] = cov(i, j);
304304
}
305305
}
306-
msg.header = getHeader(state.getTimestamp(), "enu-utm");
306+
msg.header = getHeader(state.getTimestamp(), "enu");
307307

308308
}
309309
else

glider/ros/glider_node.cpp

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ GliderNode::GliderNode(const rclcpp::NodeOptions& options) : rclcpp::Node("glide
1616
declare_parameter("publish_nav_sat_fix", false);
1717
declare_parameter("utm_zone", "18S");
1818
declare_parameter("declination", 12.0);
19+
declare_parameter("origin_easting", 0.0);
20+
declare_parameter("origin_northing", 0.0);
21+
declare_parameter("viz", false);
1922

2023
// Get parameters
2124
double freq = this->get_parameter("rate").as_double();
@@ -29,10 +32,18 @@ GliderNode::GliderNode(const rclcpp::NodeOptions& options) : rclcpp::Node("glide
2932

3033
bool use_odom = this->get_parameter("use_odom").as_bool();
3134
RCLCPP_INFO_STREAM(this->get_logger(), "Fusing Odometry: " << std::boolalpha << use_odom);
35+
3236
publish_nsf_ = this->get_parameter("publish_nav_sat_fix").as_bool();
3337
utm_zone_ = this->get_parameter("utm_zone").as_string();
34-
declination_ = this->get_parameter("declination").as_double() * M_PI / 180.0d;
38+
RCLCPP_INFO_STREAM(this->get_logger(), "Using UTM Zone: " << utm_zone_);
39+
40+
declination_ = this->get_parameter("declination").as_double() * M_PI / 180.0;
3541
RCLCPP_INFO_STREAM(this->get_logger(), "Using Magnetic Declination: " << declination_);
42+
43+
viz_ = this->get_parameter("viz").as_bool();
44+
45+
origin_easting_ = this->get_parameter("origin_easting").as_double();
46+
origin_northing_ = this->get_parameter("origin_northing").as_double();
3647

3748
glider_ = std::make_unique<Glider::Glider>(path);
3849

@@ -80,6 +91,12 @@ GliderNode::GliderNode(const rclcpp::NodeOptions& options) : rclcpp::Node("glide
8091
odom_pub_ = this->create_publisher<nav_msgs::msg::Odometry>("/glider/odom", 10);
8192
}
8293

94+
if(viz_)
95+
{
96+
RCLCPP_INFO(this->get_logger(), "Publishing Odometry Viz message on /glider/odom/viz");
97+
odom_viz_pub_ = this->create_publisher<nav_msgs::msg::Odometry>("/glider/odom/viz", 10);
98+
}
99+
83100
std::chrono::milliseconds d = GliderROS::Conversions::hzToDuration(freq);
84101
timer_ = this->create_wall_timer(d, std::bind(&GliderNode::interpolationCallback, this));
85102
RCLCPP_INFO(this->get_logger(), "GliderNode Initialized");
@@ -110,6 +127,17 @@ void GliderNode::interpolationCallback()
110127
nav_msgs::msg::Odometry msg = GliderROS::Conversions::odomToRos<nav_msgs::msg::Odometry>(odom);
111128
GliderROS::Conversions::addCovariance<nav_msgs::msg::Odometry>(current_state_, msg);
112129
odom_pub_->publish(msg);
130+
131+
if (viz_)
132+
{
133+
nav_msgs::msg::Odometry viz_msg = msg;
134+
double x = viz_msg.pose.pose.position.x - origin_easting_;
135+
double y = viz_msg.pose.pose.position.y - origin_northing_;
136+
viz_msg.pose.pose.position.x = x;
137+
viz_msg.pose.pose.position.y = y;
138+
139+
odom_viz_pub_->publish(viz_msg);
140+
}
113141
}
114142
}
115143

glider/scripts/heading_mag.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def __init__(self):
1313
# Create subscriber for magnetometer data
1414
self.subscription = self.create_subscription(
1515
MagneticField,
16-
'/VN100T/mag', # Change this to your magnetometer topic name
16+
'/vectornav/magnetic', # Change this to your magnetometer topic name
1717
self.magnetometer_callback,
1818
10
1919
)
@@ -46,13 +46,9 @@ def magnetometer_callback(self, msg):
4646
magnitude = math.sqrt(mag_x**2 + mag_y**2 + mag_z**2)
4747

4848
# Print the results
49-
self.get_logger().info(
50-
f'Magnetic Field - X: {mag_x:.3f}, Y: {mag_y:.3f}, Z: {mag_z:.3f} µT'
51-
)
5249
self.get_logger().info(
5350
f'Heading: {heading_deg:.2f}° | Magnitude: {magnitude:.3f} µT'
5451
)
55-
self.get_logger().info('---')
5652

5753

5854
def main(args=None):

glider/src/glider.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ Glider::Glider(const std::string& path)
1616
Parameters params = Parameters::Load(path);
1717
factor_manager_ = FactorManager(params);
1818

19-
origin_x_ = params.origin_x;
20-
origin_y_ = params.origin_y;
2119
frame_ = params.frame;
2220
correct_imu_ = params.correct_imu;
2321

@@ -74,9 +72,6 @@ void Glider::addGPS(int64_t timestamp, Eigen::Vector3d& gps)
7472
char zone[4];
7573
geodetics::LLtoUTM(gps(0), gps(1), northing, easting, zone);
7674

77-
easting = easting - origin_x_;
78-
northing = northing - origin_y_;
79-
8075
meas.head(2) << easting, northing;
8176
meas(2) = gps(2);
8277

@@ -88,40 +83,41 @@ void Glider::addIMU(int64_t timestamp, Eigen::Vector3d& accel, Eigen::Vector3d&
8883
if (frame_ == "ned")
8984
{
9085
// transfrom to enu
91-
Eigen::Quaterniond quat_ned(quat(0), quat(1), quat(2), quat(3));
92-
Eigen::Quaterniond quat_enu = ned_to_enu_quat_ * quat_ned;
93-
Eigen::Vector4d vec_enu;
94-
vec_enu << quat_enu.w(), quat_enu.x(), quat_enu.y(), quat_enu.z();
86+
Eigen::Quaterniond eig_quat(quat(0), quat(1), quat(2), quat(3));
87+
Eigen::Matrix3d imu_rot = eig_quat.toRotationMatrix();
88+
// Vectornav gives BODY wrt NED, we need NED wrt BODY --> so take the inverse
89+
Eigen::Matrix3d imu_enu = ned_to_enu_rot_ * imu_rot.inverse();
90+
Eigen::Quaterniond imu_quat(imu_enu);
91+
Eigen::Vector4d imu_vec(imu_quat.w(), imu_quat.x(), imu_quat.y(), imu_quat.z());
9592

9693
Eigen::Vector3d accel_enu = ned_to_enu_rot_ * accel;
9794
Eigen::Vector3d gyro_enu = ned_to_enu_rot_ * gyro;
98-
95+
9996
if (correct_imu_)
10097
{
101-
Eigen::Vector4d quat_corr = correctImuOrientation(vec_enu);
98+
Eigen::Vector4d quat_corr = correctImuOrientation(imu_vec);
10299
factor_manager_.addImuFactor(timestamp, accel_enu, gyro_enu, quat_corr);
103100
}
104101
else
105102
{
106-
factor_manager_.addImuFactor(timestamp, accel_enu, gyro_enu, vec_enu);
103+
factor_manager_.addImuFactor(timestamp, accel_enu, gyro_enu, imu_vec);
107104
}
108-
109105
}
110106
else if (frame_ == "enu")
111107
{
112108
if (correct_imu_)
113109
{
114110
Eigen::Vector4d quat_corr = correctImuOrientation(quat);
115111
factor_manager_.addImuFactor(timestamp, accel, gyro, quat_corr);
116-
}
112+
}
117113
else
118114
{
119115
factor_manager_.addImuFactor(timestamp, accel, gyro, quat);
120116
}
121117
}
122118
else
123119
{
124-
throw std::runtime_error("IMU Frame, not supported use ned or enu");
120+
throw std::runtime_error("IMU Frame, not supported use ENU or NED");
125121
return;
126122
}
127123
}
@@ -151,9 +147,9 @@ void Glider::addOdom(int64_t timestamp, Eigen::Isometry3d& pose)
151147
// Convert orb pose to ENU
152148
Eigen::Matrix3d odom_to_enu;
153149
double h = initial_heading_;
154-
odom_to_enu << std::cos(h), -std::sin(h), 0.0d,
155-
std::sin(h), std::cos(h), 0.0d,
156-
0.0d, 0.0d, 1.0d;
150+
odom_to_enu << std::cos(h), -std::sin(h), 0.0,
151+
std::sin(h), std::cos(h), 0.0,
152+
0.0, 0.0, 1.0;
157153
Eigen::Isometry3d enu_pose = pose.rotate(odom_to_enu);
158154

159155
// calculate the relative pose in ENU frame

0 commit comments

Comments
 (0)