14
14
#include < std_msgs/Float64.h>
15
15
16
16
bool g_is_sim;
17
+ bool g_publish_pose;
17
18
18
19
geodetic_converter::GeodeticConverter g_geodetic_converter;
19
20
sensor_msgs::Imu g_latest_imu_msg;
@@ -126,11 +127,14 @@ void gps_callback(const sensor_msgs::NavSatFixConstPtr& msg)
126
127
}
127
128
}
128
129
129
- g_gps_pose_pub.publish (pose_msg);
130
+ if (g_publish_pose) {
131
+ g_gps_pose_pub.publish (pose_msg);
132
+ }
130
133
g_gps_position_pub.publish (position_msg);
131
134
132
135
// Fill up transform message
133
- geometry_msgs::TransformStampedPtr transform_msg (new geometry_msgs::TransformStamped);
136
+ geometry_msgs::TransformStampedPtr transform_msg (
137
+ new geometry_msgs::TransformStamped);
134
138
transform_msg->header = msg->header ;
135
139
transform_msg->header .frame_id = " world" ;
136
140
transform_msg->transform .translation .x = x;
@@ -145,8 +149,7 @@ void gps_callback(const sensor_msgs::NavSatFixConstPtr& msg)
145
149
g_gps_transform_pub.publish (transform_msg);
146
150
}
147
151
148
- int main (int argc, char ** argv)
149
- {
152
+ int main (int argc, char **argv) {
150
153
ros::init (argc, argv, " gps_to_pose_conversion_node" );
151
154
ros::NodeHandle nh;
152
155
ros::NodeHandle pnh (" ~" );
@@ -166,41 +169,57 @@ int main(int argc, char** argv)
166
169
ros::param::param (" ~trust_gps" , g_trust_gps, false );
167
170
168
171
// Get manual parameters
169
- ros::param::param (" ~fixed_covariance/position/x" , g_covariance_position_x, 4.0 );
170
- ros::param::param (" ~fixed_covariance/position/y" , g_covariance_position_y, 4.0 );
171
- ros::param::param (" ~fixed_covariance/position/z" , g_covariance_position_z, 100.0 );
172
- ros::param::param (" ~fixed_covariance/orientation/x" , g_covariance_orientation_x, 0.02 );
173
- ros::param::param (" ~fixed_covariance/orientation/y" , g_covariance_orientation_y, 0.02 );
174
- ros::param::param (" ~fixed_covariance/orientation/z" , g_covariance_orientation_z, 0.11 );
172
+ ros::param::param (" ~fixed_covariance/position/x" , g_covariance_position_x,
173
+ 4.0 );
174
+ ros::param::param (" ~fixed_covariance/position/y" , g_covariance_position_y,
175
+ 4.0 );
176
+ ros::param::param (" ~fixed_covariance/position/z" , g_covariance_position_z,
177
+ 100.0 );
178
+ ros::param::param (" ~fixed_covariance/orientation/x" ,
179
+ g_covariance_orientation_x, 0.02 );
180
+ ros::param::param (" ~fixed_covariance/orientation/y" ,
181
+ g_covariance_orientation_y, 0.02 );
182
+ ros::param::param (" ~fixed_covariance/orientation/z" ,
183
+ g_covariance_orientation_z, 0.11 );
184
+
185
+ // Specify whether to publish pose or not
186
+ ros::param::param (" ~publish_pose" , g_publish_pose, false );
175
187
176
188
// Wait until GPS reference parameters are initialized.
177
189
double latitude, longitude, altitude;
178
190
do {
179
191
ROS_INFO (" Waiting for GPS reference parameters..." );
180
- if (nh.getParam (" /gps_ref_latitude" , latitude) && nh.getParam (" /gps_ref_longitude" , longitude)
181
- && nh.getParam (" /gps_ref_altitude" , altitude)) {
192
+ if (nh.getParam (" /gps_ref_latitude" , latitude) &&
193
+ nh.getParam (" /gps_ref_longitude" , longitude) &&
194
+ nh.getParam (" /gps_ref_altitude" , altitude)) {
182
195
g_geodetic_converter.initialiseReference (latitude, longitude, altitude);
183
196
} else {
184
- ROS_INFO (" GPS reference not ready yet, use set_gps_reference_node to set it" );
185
- ros::Duration (0.5 ).sleep (); // sleep for half a second
197
+ ROS_INFO (
198
+ " GPS reference not ready yet, use set_gps_reference_node to set it" );
199
+ ros::Duration (0.5 ).sleep (); // sleep for half a second
186
200
}
187
201
} while (!g_geodetic_converter.isInitialised ());
188
202
189
203
// Show reference point
190
204
double initial_latitude, initial_longitude, initial_altitude;
191
- g_geodetic_converter.getReference (&initial_latitude, &initial_longitude, &initial_altitude);
192
- ROS_INFO (" GPS reference initialized correctly %f, %f, %f" , initial_latitude, initial_longitude,
193
- initial_altitude);
205
+ g_geodetic_converter.getReference (&initial_latitude, &initial_longitude,
206
+ &initial_altitude);
207
+ ROS_INFO (" GPS reference initialized correctly %f, %f, %f" , initial_latitude,
208
+ initial_longitude, initial_altitude);
194
209
195
210
// Initialize publishers
196
- g_gps_pose_pub = nh.advertise < geometry_msgs::PoseWithCovarianceStamped > (" gps_pose" , 1 );
197
- g_gps_transform_pub = nh.advertise < geometry_msgs::TransformStamped > (" gps_transform" , 1 );
198
- g_gps_position_pub = nh.advertise < geometry_msgs::PointStamped > (" gps_position" , 1 );
211
+ g_gps_pose_pub =
212
+ nh.advertise <geometry_msgs::PoseWithCovarianceStamped>(" gps_pose" , 1 );
213
+ g_gps_transform_pub =
214
+ nh.advertise <geometry_msgs::TransformStamped>(" gps_transform" , 1 );
215
+ g_gps_position_pub =
216
+ nh.advertise <geometry_msgs::PointStamped>(" gps_position" , 1 );
199
217
200
218
// Subscribe to IMU and GPS fixes, and convert in GPS callback
201
219
ros::Subscriber imu_sub = nh.subscribe (" imu" , 1 , &imu_callback);
202
220
ros::Subscriber gps_sub = nh.subscribe (" gps" , 1 , &gps_callback);
203
- ros::Subscriber altitude_sub = nh.subscribe (" external_altitude" , 1 , &altitude_callback);
221
+ ros::Subscriber altitude_sub =
222
+ nh.subscribe (" external_altitude" , 1 , &altitude_callback);
204
223
205
224
ros::spin ();
206
225
}
0 commit comments