12 from sensor_msgs.msg
import (NavSatFix, NavSatStatus)
18 kRosPackageName =
"piksi_multi_rtk" 19 kServiceTimeOutSeconds = 10.0
20 kWaitBetweenReadReqAndResSeconds = 1.0
21 kRelativeTolleranceGeodeticComparison = 1e-10
24 rospy.init_node(
'geodetic_survey')
25 rospy.loginfo(rospy.get_name() +
" start")
35 self.
navsatfix_topics_name = rospy.get_param(
'~navsatfix_topics_name',
'piksi_multi_base_station/navsatfix_spp')
39 'piksi_multi_base_station/settings_read_req')
41 'piksi_multi_base_station/settings_read_resp')
52 if msg.status.status != NavSatStatus.STATUS_FIX
and msg.status.status != NavSatStatus.STATUS_SBAS_FIX:
54 "[navsatfix_callback] received a navsatfix message with status '%d'." % (msg.status.status) +
55 " Accepted status are 'STATUS_FIX' (%d) or 'STATUS_SBAS_FIX' (%d)" % (NavSatStatus.STATUS_FIX, NavSatStatus.STATUS_SBAS_FIX))
64 "Received: [%.10f, %.10f, %.1f]; temporary average: [%.10f, %.10f, %.1f]; waiting for %d samples" % (
76 rospy.loginfo(
"Base station position set correctly.")
78 "Creating ENU frame on surveyed position and substructing specified height of base station.")
80 rospy.signal_shutdown(
"Base station position set correctly. Stop this node and launch base station node.")
82 rospy.logerr(
"Base station position not set correctly.")
83 rospy.signal_shutdown(
"Base station position not set correctly.")
88 alt0 = float(
"%.2f" % alt0)
89 rospy.loginfo(
"Setting Piksi Multi surveyed position to: %.10f, %.10f, %.1f\n" % (lat0, lon0, alt0))
96 if write_lat0_ok
and write_lon0_ok
and write_alt0_ok:
104 if read_lat0
and read_lon0
and read_alt0:
106 if self.
is_close(float(read_lat0_value), lat0,
108 float(read_lon0_value),
116 "surveyed_position",
"broadcast")
118 read_surveyed_broadcast_value =
True if (read_surveyed_broadcast_value ==
"True")
else False 119 if read_surveyed_broadcast_value:
121 "Your Piksi Multi is already configured to broadcast its surveyed position and act as base station.")
124 "Your Piksi Multi is NOT configured to broadcast its surveyed position and act as base station. " 125 "Please use piksi console (by Siwftnav) to change settings. See Wiki page where you downloaded this ROS driver.")
128 "Read values do NOT correspond to written ones. Please use piksi console (See swiftnav support).")
129 everything_ok =
False 131 rospy.logerr(
"Error while saving base station position to Piksi flash.")
132 everything_ok =
False 134 rospy.logerr(
"Error while saving base station position to Piksi flash.")
135 everything_ok =
False 137 rospy.logerr(
"Error while writing base station position to Piksi.")
138 everything_ok =
False 146 rospy.loginfo(
"Setting %s.%s to %s" % (section_setting, setting, value))
147 write_resp = write_settings_service(section_setting=section_setting, setting=setting, value=value)
148 return write_resp.success
149 except rospy.ServiceException
as exc:
150 rospy.logerr(
"Service did not process request: " + str(exc))
157 rospy.loginfo(
"Saving settings to Piksi Multi flash.")
158 save_resp = save_settings_service(
True)
159 return save_resp.success
160 except rospy.ServiceException
as exc:
161 rospy.logerr(
"Service did not process request: " + str(exc))
169 read_req_resp = read_req_settings_service(section_setting=section_setting, setting=setting)
170 except rospy.ServiceException
as exc:
171 rospy.logerr(
"Service did not process request: " + str(exc))
174 if read_req_resp.success:
176 time.sleep(GeodeticSurvey.kWaitBetweenReadReqAndResSeconds)
181 read_resp_resp = read_resp_settings_service()
182 except rospy.ServiceException
as exc:
183 rospy.logerr(
"Service did not process request: " + str(exc))
186 if read_resp_resp.success:
187 rospy.loginfo(
"Read [%s.%s: %s] from Piksi settings." % (
188 read_resp_resp.section_setting, read_resp_resp.setting, read_resp_resp.value))
189 return True, read_resp_resp.value
194 now = time.strftime(
"%Y-%m-%d-%H-%M-%S")
196 desired_path =
"%s/log_surveys/base_station_survey_%s.txt" % (package_path, now)
197 file_obj = open(desired_path,
'w')
198 file_obj.write(
"# File automatically generated on %s\n\n" % now)
199 file_obj.write(
"latitude0_deg: %.10f\n" % lat0)
200 file_obj.write(
"longitude0_deg: %.10f\n" % lon0)
201 file_obj.write(
"altitude0: %.2f\n" % alt0)
203 rospy.loginfo(
"Surveyed position saved in \'" + desired_path +
"\'")
207 now = time.strftime(
"%Y-%m-%d-%H-%M-%S")
209 desired_path =
"%s/log_surveys/enu_origin_%s.txt" % (package_path, now)
210 file_obj = open(desired_path,
'w')
211 file_obj.write(
"# File automatically generated on %s\n" % now)
214 file_obj.write(
"latitude0_deg: %.10f\n" % lat0)
215 file_obj.write(
"longitude0_deg: %.10f\n" % lon0)
218 rospy.loginfo(
"ENU origin saved in \'" + desired_path +
"\'")
221 def is_close(self, a, b, rel_tol=1e-09, abs_tol=0.0):
222 return abs(a - b) <= max(rel_tol * max(abs(a), abs(b)), abs_tol)
def navsatfix_callback(self, msg)
def log_surveyed_position(self, lat0, lon0, alt0)
int kRelativeTolleranceGeodeticComparison
def read_settings_from_piksi(self, section_setting, setting)
write_settings_service_name
save_settings_service_name
read_resp_settings_service_name
def save_settings_to_piksi(self)
def set_base_station_position(self, lat0, lon0, alt0)
def is_close(self, a, b, rel_tol=1e-09, abs_tol=0.0)
read_req_settings_service_name
def log_enu_origin_position(self, lat0, lon0, alt0)
height_base_station_from_ground
def write_settings_to_piksi(self, section_setting, setting, value)