15 from sensor_msgs.msg
import NavSatFix, NavSatStatus
16 from piksi_rtk_msgs.msg
import (AgeOfCorrections, BaselineEcef, BaselineHeading, BaselineNed, BasePosEcef, BasePosLlh,
17 DeviceMonitor_V2_3_15, DopsMulti, GpsTimeMulti, Heartbeat, ImuRawMulti,
18 InfoWifiCorrections, Log, MagRaw, Observation, PosEcef, PosLlhMulti,
19 ReceiverState_V2_3_15, TrackingState_V2_3_15,
20 UartState_V2_3_15, UtcTimeMulti, VelEcef, VelNed)
22 from geometry_msgs.msg
import (PoseWithCovarianceStamped, PointStamped, PoseWithCovariance, Point, TransformStamped,
25 from sbp.client.drivers.pyserial_driver
import PySerialDriver
26 from sbp.client.drivers.network_drivers
import TCPDriver
27 from sbp.client
import Handler, Framer
36 from zope.interface.exceptions
import Invalid
40 from sbp.mag
import SBP_MSG_MAG_RAW, MsgMagRaw
54 LIB_SBP_VERSION_MULTI =
'2.3.15' 57 kSemimajorAxis = 6378137
58 kSemiminorAxis = 6356752.3142
59 kFirstEccentricitySquared = 6.69437999014 * 0.001
60 kSecondEccentricitySquared = 6.73949674228 * 0.001
61 kFlattening = 1 / 298.257223563
66 rospy.init_node(
'piksi')
68 rospy.loginfo(rospy.get_name() +
" start")
71 if 'sbp.version' in sys.modules:
72 installed_sbp_version = sbp.version.get_git_version()
76 rospy.loginfo(
"libsbp version currently used: " + installed_sbp_version)
79 if PiksiMulti.LIB_SBP_VERSION_MULTI != installed_sbp_version:
80 rospy.logwarn(
"Lib SBP version in usage (%s) is different than the one used to test this driver (%s)!\n" 81 "Please run the install script: 'install/install_piksi_multi.sh'" % (
82 installed_sbp_version, PiksiMulti.LIB_SBP_VERSION_MULTI))
85 interface = rospy.get_param(
'~interface',
'serial')
87 if interface ==
'tcp':
88 tcp_addr = rospy.get_param(
'~tcp_addr',
'192.168.0.222')
89 tcp_port = rospy.get_param(
'~tcp_port', 55555)
91 self.
driver = TCPDriver(tcp_addr, tcp_port)
93 rospy.logerr(
"Unable to open TCP connection %s:%s", (tcp_addr, tcp_port))
96 serial_port = rospy.get_param(
'~serial_port',
'/dev/ttyUSB0')
97 baud_rate = rospy.get_param(
'~baud_rate', 230400)
99 self.
driver = PySerialDriver(serial_port, baud=baud_rate)
101 rospy.logerr(
"Swift receiver not found on serial port '%s'", serial_port)
111 rospy.loginfo(
"Swift driver started in debug mode, every available topic will be published.")
113 debug_delayed_corrections_stack_size = rospy.get_param(
'~debug_delayed_corrections_stack_size', 10)
117 rospy.loginfo(
"Swift driver started in normal mode.")
122 self.
udp_port = rospy.get_param(
'~broadcast_port', 26078)
124 '~base_station_ip_for_latency_estimation',
130 self.
var_spp = rospy.get_param(
'~var_spp', [25.0, 25.0, 64.0])
132 self.
var_rtk_fix = rospy.get_param(
'~var_rtk_fix', [0.0049, 0.0049, 0.01])
148 if rospy.has_param(
'~latitude0_deg')
and rospy.has_param(
'~longitude0_deg')
and rospy.has_param(
150 latitude0 = rospy.get_param(
'~latitude0_deg')
151 longitude0 = rospy.get_param(
'~longitude0_deg')
152 altitude0 = rospy.get_param(
'~altitude0')
156 rospy.loginfo(
"Origin ENU frame set by rosparam.")
191 rospy.Timer(rospy.Duration(30), self.
cb_watchdog,
True)
199 self.handler.add_callback(self.
cb_sbp_heartbeat, msg_type=SBP_MSG_HEARTBEAT)
200 self.handler.add_callback(self.
cb_sbp_pos_llh, msg_type=SBP_MSG_POS_LLH)
202 self.handler.add_callback(self.
cb_sbp_obs, msg_type=SBP_MSG_OBS)
210 SBP_MSG_BASELINE_ECEF, MsgBaselineECEF,
211 'tow',
'x',
'y',
'z',
'accuracy',
'n_sats',
'flags')
213 SBP_MSG_BASELINE_NED, MsgBaselineNED,
214 'tow',
'n',
'e',
'd',
'h_accuracy',
'v_accuracy',
'n_sats',
'flags')
216 SBP_MSG_DOPS, MsgDops,
'tow',
'gdop',
'pdop',
'tdop',
'hdop',
'vdop',
'flags')
218 SBP_MSG_GPS_TIME, MsgGPSTime,
'wn',
'tow',
'ns_residual',
'flags')
220 SBP_MSG_UTC_TIME, MsgUtcTime,
221 'flags',
'tow',
'year',
'month',
'day',
'hours',
'minutes',
'seconds',
'ns')
223 SBP_MSG_POS_ECEF, MsgPosECEF,
224 'tow',
'x',
'y',
'z',
'accuracy',
'n_sats',
'flags')
226 SBP_MSG_VEL_ECEF, MsgVelECEF,
227 'tow',
'x',
'y',
'z',
'accuracy',
'n_sats',
'flags')
229 SBP_MSG_VEL_NED, MsgVelNED,
230 'tow',
'n',
'e',
'd',
'h_accuracy',
'v_accuracy',
'n_sats',
'flags')
232 SBP_MSG_LOG, MsgLog,
'level',
'text')
234 SBP_MSG_BASELINE_HEADING, MsgBaselineHeading,
'tow',
'heading',
'n_sats',
'flags')
236 SBP_MSG_AGE_CORRECTIONS, MsgAgeCorrections,
'tow',
'age')
238 SBP_MSG_DEVICE_MONITOR, MsgDeviceMonitor,
'dev_vin',
'cpu_vint',
'cpu_vaux',
239 'cpu_temperature',
'fe_temperature')
244 SBP_MSG_IMU_RAW, MsgImuRaw,
245 'tow',
'tow_f',
'acc_x',
'acc_y',
'acc_z',
'gyr_x',
'gyr_y',
'gyr_z')
247 SBP_MSG_MAG_RAW, MsgMagRaw,
'tow',
'tow_f',
'mag_x',
'mag_y',
'mag_z')
260 rospy.loginfo(
"Starting device in Base Station Mode")
263 rospy.loginfo(
"Starting device in Rover Mode")
267 num_wifi_corrections = InfoWifiCorrections()
268 num_wifi_corrections.header.seq = 0
269 num_wifi_corrections.received_corrections = 0
270 num_wifi_corrections.latency = -1
272 return num_wifi_corrections
275 receiver_state_msg = ReceiverState_V2_3_15()
276 receiver_state_msg.num_sat = 0
277 receiver_state_msg.rtk_mode_fix =
False 278 receiver_state_msg.sat = []
279 receiver_state_msg.cn0 = []
280 receiver_state_msg.system_error = 255
281 receiver_state_msg.io_error = 255
282 receiver_state_msg.swift_nap_error = 255
283 receiver_state_msg.external_antenna_present = 255
284 receiver_state_msg.num_gps_sat = 0
285 receiver_state_msg.cn0_gps = []
286 receiver_state_msg.num_sbas_sat = 0
287 receiver_state_msg.cn0_sbas = []
288 receiver_state_msg.num_glonass_sat = 0
289 receiver_state_msg.cn0_glonass = []
290 receiver_state_msg.fix_mode = ReceiverState_V2_3_15.STR_FIX_MODE_UNKNOWN
292 return receiver_state_msg
297 :return: python dictionary, with topic names used as keys and publishers as values. 301 publishers[
'rtk_fix'] = rospy.Publisher(rospy.get_name() +
'/navsatfix_rtk_fix',
302 NavSatFix, queue_size=10)
303 publishers[
'spp'] = rospy.Publisher(rospy.get_name() +
'/navsatfix_spp',
304 NavSatFix, queue_size=10)
305 publishers[
'best_fix'] = rospy.Publisher(rospy.get_name() +
'/navsatfix_best_fix',
306 NavSatFix, queue_size=10)
307 publishers[
'heartbeat'] = rospy.Publisher(rospy.get_name() +
'/heartbeat',
308 Heartbeat, queue_size=10)
309 publishers[
'tracking_state'] = rospy.Publisher(rospy.get_name() +
'/tracking_state',
310 TrackingState_V2_3_15, queue_size=10)
311 publishers[
'receiver_state'] = rospy.Publisher(rospy.get_name() +
'/debug/receiver_state',
312 ReceiverState_V2_3_15, queue_size=10)
316 publishers[
'vel_ned'] = rospy.Publisher(rospy.get_name() +
'/vel_ned',
317 VelNed, queue_size=10)
318 publishers[
'log'] = rospy.Publisher(rospy.get_name() +
'/log',
320 publishers[
'uart_state'] = rospy.Publisher(rospy.get_name() +
'/uart_state',
321 UartState_V2_3_15, queue_size=10)
322 publishers[
'device_monitor'] = rospy.Publisher(rospy.get_name() +
'/device_monitor',
323 DeviceMonitor_V2_3_15, queue_size=10)
325 publishers[
'enu_pose_fix'] = rospy.Publisher(rospy.get_name() +
'/enu_pose_fix',
326 PoseWithCovarianceStamped, queue_size=10)
327 publishers[
'enu_point_fix'] = rospy.Publisher(rospy.get_name() +
'/enu_point_fix',
328 PointStamped, queue_size=10)
329 publishers[
'enu_transform_fix'] = rospy.Publisher(rospy.get_name() +
'/enu_transform_fix',
330 TransformStamped, queue_size=10)
331 publishers[
'enu_pose_spp'] = rospy.Publisher(rospy.get_name() +
'/enu_pose_spp',
332 PoseWithCovarianceStamped, queue_size=10)
333 publishers[
'enu_point_spp'] = rospy.Publisher(rospy.get_name() +
'/enu_point_spp',
334 PointStamped, queue_size=10)
335 publishers[
'enu_transform_spp'] = rospy.Publisher(rospy.get_name() +
'/enu_transform_spp',
336 TransformStamped, queue_size=10)
337 publishers[
'gps_time_multi'] = rospy.Publisher(rospy.get_name() +
'/gps_time',
338 GpsTimeMulti, queue_size=10)
339 publishers[
'baseline_ned_multi'] = rospy.Publisher(rospy.get_name() +
'/baseline_ned',
340 BaselineNed, queue_size=10)
341 publishers[
'utc_time_multi'] = rospy.Publisher(rospy.get_name() +
'/utc_time',
342 UtcTimeMulti, queue_size=10)
343 publishers[
'baseline_heading'] = rospy.Publisher(rospy.get_name() +
'/baseline_heading',
344 BaselineHeading, queue_size=10)
345 publishers[
'age_of_corrections'] = rospy.Publisher(rospy.get_name() +
'/age_of_corrections',
346 AgeOfCorrections, queue_size=10)
347 publishers[
'enu_pose_best_fix'] = rospy.Publisher(rospy.get_name() +
'/enu_pose_best_fix',
348 PoseWithCovarianceStamped, queue_size=10)
352 publishers[
'imu_raw'] = rospy.Publisher(rospy.get_name() +
'/imu_raw',
353 ImuRawMulti, queue_size=10)
354 publishers[
'mag_raw'] = rospy.Publisher(rospy.get_name() +
'/mag_raw',
355 MagRaw, queue_size=10)
359 publishers[
'rtk_float'] = rospy.Publisher(rospy.get_name() +
'/navsatfix_rtk_float',
360 NavSatFix, queue_size=10)
361 publishers[
'vel_ecef'] = rospy.Publisher(rospy.get_name() +
'/vel_ecef',
362 VelEcef, queue_size=10)
363 publishers[
'enu_pose_float'] = rospy.Publisher(rospy.get_name() +
'/enu_pose_float',
364 PoseWithCovarianceStamped, queue_size=10)
365 publishers[
'enu_point_float'] = rospy.Publisher(rospy.get_name() +
'/enu_point_float',
366 PointStamped, queue_size=10)
367 publishers[
'enu_transform_float'] = rospy.Publisher(rospy.get_name() +
'/enu_transform_float',
368 TransformStamped, queue_size=10)
369 publishers[
'baseline_ecef_multi'] = rospy.Publisher(rospy.get_name() +
'/baseline_ecef',
370 BaselineEcef, queue_size=10)
371 publishers[
'dops_multi'] = rospy.Publisher(rospy.get_name() +
'/dops',
372 DopsMulti, queue_size=10)
373 publishers[
'pos_ecef_multi'] = rospy.Publisher(rospy.get_name() +
'/pos_ecef',
374 PosEcef, queue_size=10)
375 publishers[
'observation'] = rospy.Publisher(rospy.get_name() +
'/observation',
376 Observation, queue_size=10)
377 publishers[
'base_pos_llh'] = rospy.Publisher(rospy.get_name() +
'/base_pos_llh',
378 BasePosLlh, queue_size=10)
379 publishers[
'base_pos_ecef'] = rospy.Publisher(rospy.get_name() +
'/base_pos_ecef',
380 BasePosEcef, queue_size=10)
382 publishers[
'wifi_corrections'] = rospy.Publisher(rospy.get_name() +
'/debug/wifi_corrections',
383 InfoWifiCorrections, queue_size=10)
389 Advertise service servers. 390 :return: python dictionary, with service names used as keys and servers as values. 394 servers[
'reset_piksi'] = rospy.Service(rospy.get_name() +
396 std_srvs.srv.SetBool,
399 servers[
'settings_write'] = rospy.Service(rospy.get_name() +
404 servers[
'settings_read_req'] = rospy.Service(rospy.get_name() +
405 '/settings_read_req',
409 servers[
'settings_read_resp'] = rospy.Service(rospy.get_name() +
410 '/settings_read_resp',
414 servers[
'settings_save'] = rospy.Service(rospy.get_name() +
416 std_srvs.srv.SetBool,
423 Ping base station periodically without blocking the driver. 425 ping_deadline_seconds = 3
426 interval_between_pings_seconds = 5
428 while not rospy.is_shutdown():
431 "-w", str(ping_deadline_seconds),
434 ping = subprocess.Popen(command, stdout=subprocess.PIPE)
436 out, error = ping.communicate()
438 matcher = re.compile(
"(\d+.\d+)/(\d+.\d+)/(\d+.\d+)/(\d+.\d+)")
440 if matcher.search(out) ==
None:
444 self.num_wifi_corrections.latency = -1
446 groups_rtt = matcher.search(out).groups()
447 avg_rtt = groups_rtt[1]
450 self.num_wifi_corrections.latency = float(avg_rtt)
452 time.sleep(interval_between_pings_seconds)
456 Dynamic generator for callback functions for message types from 458 Inputs: 'sbp_type' name of SBP message type. 459 'ros_message' ROS message type with SBP format. 460 'pub' ROS publisher for ros_message. 461 'attrs' array of attributes in SBP/ROS message. 462 Returns: callback function 'callback'. 465 def callback(msg, **metadata):
466 sbp_message = sbp_type(msg)
467 ros_message.header.stamp = rospy.Time.now()
471 if (sbp_message.flags & 0x07) == 0:
474 setattr(ros_message, attr, getattr(sbp_message, attr))
475 pub.publish(ros_message)
479 def init_callback(self, topic_name, ros_datatype, sbp_msg_type, callback_data_type, *attrs):
481 Initializes the callback function for an SBP 483 Inputs: 'topic_name' name of ROS topic for publisher 484 'ros_datatype' ROS custom message type 485 'sbp_msg_type' name of SBP message type for callback function 486 'callback_data_type' name of SBP message type for SBP library 487 '*attrs' array of attributes in ROS/SBP message 491 ros_message = ros_datatype()
495 callback_function = self.
make_callback(callback_data_type, ros_message, pub, attrs)
496 self.handler.add_callback(callback_function, msg_type=sbp_msg_type)
500 msg = MsgObs(msg_raw)
502 obs_msg = Observation()
503 obs_msg.header.stamp = rospy.Time.now()
505 obs_msg.tow = msg.header.t.tow
506 obs_msg.ns_residual = msg.header.t.ns_residual
507 obs_msg.wn = msg.header.t.wn
508 obs_msg.n_obs = msg.header.n_obs
519 obs_msg.sid_code = []
521 for observation
in msg.obs:
522 obs_msg.P.append(observation.P)
523 obs_msg.L_i.append(observation.L.i)
524 obs_msg.L_f.append(observation.L.f)
525 obs_msg.D_i.append(observation.D.i)
526 obs_msg.D_f.append(observation.D.f)
527 obs_msg.cn0.append(observation.cn0)
528 obs_msg.lock.append(observation.lock)
529 obs_msg.flags.append(observation.flags)
530 obs_msg.sid_sat.append(observation.sid.sat)
531 obs_msg.sid_code.append(observation.sid.code)
533 self.
publishers[
'observation'].publish(obs_msg)
536 self.multicaster.sendSbpPacket(msg_raw)
540 msg = MsgBasePosLLH(msg_raw)
542 pose_llh_msg = BasePosLlh()
543 pose_llh_msg.header.stamp = rospy.Time.now()
545 pose_llh_msg.lat = msg.lat
546 pose_llh_msg.lon = msg.lon
547 pose_llh_msg.height = msg.height
549 self.
publishers[
'base_pos_llh'].publish(pose_llh_msg)
553 msg = MsgBasePosECEF(msg_raw)
555 pose_ecef_msg = BasePosEcef()
556 pose_ecef_msg.header.stamp = rospy.Time.now()
558 pose_ecef_msg.x = msg.x
559 pose_ecef_msg.y = msg.y
560 pose_ecef_msg.z = msg.z
562 self.
publishers[
'base_pos_ecef'].publish(pose_ecef_msg)
565 self.multicaster.sendSbpPacket(msg_raw)
568 msg = MsgUartState(msg_raw)
569 uart_state_msg = UartState_V2_3_15()
571 uart_state_msg.latency_avg = msg.latency.avg
572 uart_state_msg.latency_lmin = msg.latency.lmin
573 uart_state_msg.latency_lmax = msg.latency.lmax
574 uart_state_msg.latency_current = msg.latency.current
575 uart_state_msg.obs_period_avg = msg.obs_period.avg
576 uart_state_msg.obs_period_pmin = msg.obs_period.pmin
577 uart_state_msg.obs_period_pmax = msg.obs_period.pmax
578 uart_state_msg.obs_period_current = msg.obs_period.current
580 self.
publishers[
'uart_state'].publish(uart_state_msg)
596 self.
framer(msg, **metadata)
599 self.num_wifi_corrections.header.seq += 1
600 self.num_wifi_corrections.header.stamp = rospy.Time.now()
601 self.num_wifi_corrections.received_corrections += 1
606 rospy.logwarn(
"Received external SBP msg, but Piksi not connected.")
610 self.multicaster.sendSbpPacket(msg_raw)
613 if ((rospy.get_rostime() - self.
watchdog_time).to_sec() > 10.0):
614 rospy.logwarn(
"Heartbeat failed, watchdog triggered.")
617 rospy.signal_shutdown(
"Watchdog triggered, was gps disconnected?")
620 msg = MsgPosLLH(msg_raw)
623 if msg.flags == PosLlhMulti.FIX_MODE_INVALID:
626 elif msg.flags == PosLlhMulti.FIX_MODE_SPP:
629 elif msg.flags == PosLlhMulti.FIX_MODE_DGNSS:
631 "[cb_sbp_pos_llh]: case FIX_MODE_DGNSS was not implemented yet." +
632 "Contact the package/repository maintainers.")
636 elif msg.flags == PosLlhMulti.FIX_MODE_FLOAT_RTK:
640 elif msg.flags == PosLlhMulti.FIX_MODE_FIX_RTK:
647 elif msg.flags == PosLlhMulti.FIX_MODE_DEAD_RECKONING:
649 "[cb_sbp_pos_llh]: case FIX_MODE_DEAD_RECKONING was not implemented yet." +
650 "Contact the package/repository maintainers.")
653 elif msg.flags == PosLlhMulti.FIX_MODE_SBAS:
657 "[cb_sbp_pos_llh]: Unknown case, you found a bug!" +
658 "Contact the package/repository maintainers." +
659 "Report: 'msg.flags = %d'" % (msg.flags))
663 self.receiver_state_msg.rtk_mode_fix =
True if (msg.flags == PosLlhMulti.FIX_MODE_FIX_RTK)
else False 665 if msg.flags == PosLlhMulti.FIX_MODE_INVALID:
666 self.receiver_state_msg.fix_mode = ReceiverState_V2_3_15.STR_FIX_MODE_INVALID
667 elif msg.flags == PosLlhMulti.FIX_MODE_SPP:
668 self.receiver_state_msg.fix_mode = ReceiverState_V2_3_15.STR_FIX_MODE_SPP
669 elif msg.flags == PosLlhMulti.FIX_MODE_DGNSS:
670 self.receiver_state_msg.fix_mode = ReceiverState_V2_3_15.STR_FIX_MODE_DGNSS
671 elif msg.flags == PosLlhMulti.FIX_MODE_FLOAT_RTK:
672 self.receiver_state_msg.fix_mode = ReceiverState_V2_3_15.STR_FIX_MODE_FLOAT_RTK
673 elif msg.flags == PosLlhMulti.FIX_MODE_FIX_RTK:
674 self.receiver_state_msg.fix_mode = ReceiverState_V2_3_15.STR_FIX_MODE_FIXED_RTK
675 elif msg.flags == PosLlhMulti.FIX_MODE_DEAD_RECKONING:
676 self.receiver_state_msg.fix_mode = ReceiverState_V2_3_15.FIX_MODE_DEAD_RECKONING
677 elif msg.flags == PosLlhMulti.FIX_MODE_SBAS:
678 self.receiver_state_msg.fix_mode = ReceiverState_V2_3_15.STR_FIX_MODE_SBAS
680 self.receiver_state_msg.fix_mode = ReceiverState_V2_3_15.STR_FIX_MODE_UNKNOWN
684 def publish_spp(self, latitude, longitude, height, variance, navsatstatus_fix):
705 def publish_wgs84_point(self, latitude, longitude, height, variance, navsat_status, pub_navsatfix, pub_pose,
706 pub_point, pub_transform, pub_navsatfix_best_pose, pub_pose_best_fix):
708 navsatfix_msg = NavSatFix()
709 navsatfix_msg.header.stamp = rospy.Time.now()
711 navsatfix_msg.position_covariance_type = NavSatFix.COVARIANCE_TYPE_APPROXIMATED
712 navsatfix_msg.status.service = NavSatStatus.SERVICE_GPS
713 navsatfix_msg.latitude = latitude
714 navsatfix_msg.longitude = longitude
715 navsatfix_msg.altitude = height
716 navsatfix_msg.status.status = navsat_status
717 navsatfix_msg.position_covariance = [variance[0], 0, 0,
724 pose_msg = PoseWithCovarianceStamped()
725 pose_msg.header.stamp = navsatfix_msg.header.stamp
730 point_msg = PointStamped()
731 point_msg.header.stamp = navsatfix_msg.header.stamp
736 transform_msg = TransformStamped()
737 transform_msg.header.stamp = navsatfix_msg.header.stamp
743 pub_navsatfix.publish(navsatfix_msg)
744 pub_pose.publish(pose_msg)
745 pub_point.publish(point_msg)
746 pub_transform.publish(transform_msg)
747 pub_navsatfix_best_pose.publish(navsatfix_msg)
748 pub_pose_best_fix.publish(pose_msg)
751 msg = MsgHeartbeat(msg_raw)
761 heartbeat_msg = Heartbeat()
762 heartbeat_msg.header.stamp = rospy.Time.now()
763 heartbeat_msg.system_error = msg.flags & 0x01
764 heartbeat_msg.io_error = msg.flags & 0x02
765 heartbeat_msg.swift_nap_error = msg.flags & 0x04
766 heartbeat_msg.sbp_minor_version = (msg.flags & 0xFF00) >> 8
767 heartbeat_msg.sbp_major_version = (msg.flags & 0xFF0000) >> 16
768 heartbeat_msg.external_antenna_present = (msg.flags & 0x80000000) >> 31
770 self.
publishers[
'heartbeat'].publish(heartbeat_msg)
773 self.receiver_state_msg.system_error = heartbeat_msg.system_error
774 self.receiver_state_msg.io_error = heartbeat_msg.io_error
775 self.receiver_state_msg.swift_nap_error = heartbeat_msg.swift_nap_error
776 self.receiver_state_msg.external_antenna_present = heartbeat_msg.external_antenna_present
780 self.multicaster.sendSbpPacket(msg_raw)
783 msg = MsgTrackingState(msg_raw)
791 tracking_state_msg = TrackingState_V2_3_15()
792 tracking_state_msg.header.stamp = rospy.Time.now()
793 tracking_state_msg.sat = []
794 tracking_state_msg.code = []
795 tracking_state_msg.fcn = []
796 tracking_state_msg.cn0 = []
806 for single_tracking_state
in msg.states:
809 if single_tracking_state.cn0 > 0.0:
811 tracking_state_msg.sat.append(single_tracking_state.sid.sat)
812 tracking_state_msg.code.append(single_tracking_state.sid.code)
813 tracking_state_msg.fcn.append(single_tracking_state.fcn)
814 tracking_state_msg.cn0.append(single_tracking_state.cn0)
817 code = single_tracking_state.sid.code
818 if code == TrackingState_V2_3_15.CODE_GPS_L1CA
or \
819 code == TrackingState_V2_3_15.CODE_GPS_L2CM
or \
820 code == TrackingState_V2_3_15.CODE_GPS_L1P
or \
821 code == TrackingState_V2_3_15.CODE_GPS_L2P:
823 cn0_gps.append(single_tracking_state.cn0)
825 if code == TrackingState_V2_3_15.CODE_SBAS_L1CA:
827 cn0_sbas.append(single_tracking_state.cn0)
829 if code == TrackingState_V2_3_15.CODE_GLO_L1CA
or \
830 code == TrackingState_V2_3_15.CODE_GLO_L1CA:
832 cn0_glonass.append(single_tracking_state.cn0)
835 if len(tracking_state_msg.sat) \
836 and len(tracking_state_msg.code) \
837 and len(tracking_state_msg.fcn) \
838 and len(tracking_state_msg.cn0):
839 self.
publishers[
'tracking_state'].publish(tracking_state_msg)
842 self.receiver_state_msg.num_sat = num_gps_sat + num_sbas_sat + num_glonass_sat
843 self.receiver_state_msg.sat = tracking_state_msg.sat
844 self.receiver_state_msg.cn0 = tracking_state_msg.cn0
845 self.receiver_state_msg.num_gps_sat = num_gps_sat
846 self.receiver_state_msg.cn0_gps = cn0_gps
847 self.receiver_state_msg.num_sbas_sat = num_sbas_sat
848 self.receiver_state_msg.cn0_sbas = cn0_sbas
849 self.receiver_state_msg.num_glonass_sat = num_glonass_sat
850 self.receiver_state_msg.cn0_glonass = cn0_glonass
855 self.receiver_state_msg.header.stamp = rospy.Time.now()
875 rospy.loginfo(
"Origin ENU frame set to: %.6f, %.6f, %.2f" % (latitude, longitude, altitude))
880 lat_rad = math.radians(latitude)
881 lon_rad = math.radians(longitude)
882 xi = math.sqrt(1 - PiksiMulti.kFirstEccentricitySquared * math.sin(lat_rad) * math.sin(lat_rad))
883 x = (PiksiMulti.kSemimajorAxis / xi + altitude) * math.cos(lat_rad) * math.cos(lon_rad)
884 y = (PiksiMulti.kSemimajorAxis / xi + altitude) * math.cos(lat_rad) * math.sin(lon_rad)
885 z = (PiksiMulti.kSemimajorAxis / xi * (1 - PiksiMulti.kFirstEccentricitySquared) + altitude) * math.sin(lat_rad)
892 vect = np.array([0.0, 0.0, 0.0])
896 ret = self.ecef_to_ned_matrix.dot(vect)
909 return east, north, -down
911 def n_re(self, lat_radians, lon_radians):
912 s_lat = math.sin(lat_radians)
913 s_lon = math.sin(lon_radians)
914 c_lat = math.cos(lat_radians)
915 c_lon = math.cos(lon_radians)
918 ret[0, 0] = -s_lat * c_lon
919 ret[0, 1] = -s_lat * s_lon
924 ret[2, 0] = c_lat * c_lon
925 ret[2, 1] = c_lat * s_lon
931 pose_msg = PoseWithCovariance()
934 pose_msg.covariance[6 * 0 + 0] = variance[0]
935 pose_msg.covariance[6 * 1 + 1] = variance[1]
936 pose_msg.covariance[6 * 2 + 2] = variance[2]
939 pose_msg.pose.position.x = east
940 pose_msg.pose.position.y = north
941 pose_msg.pose.position.z = up
944 pose_msg.pose.orientation.x = 0.0
945 pose_msg.pose.orientation.y = 0.0
946 pose_msg.pose.orientation.z = 0.0
947 pose_msg.pose.orientation.w = 1.0
962 transform_msg = Transform()
965 transform_msg.translation.x = east
966 transform_msg.translation.y = north
967 transform_msg.translation.z = up
970 transform_msg.rotation.x = 0.0
971 transform_msg.rotation.y = 0.0
972 transform_msg.rotation.z = 0.0
973 transform_msg.rotation.w = 1.0
978 response = std_srvs.srv.SetBoolResponse()
982 reset_sbp = SBP(SBP_MSG_RESET)
983 reset_sbp.payload =
'' 984 reset_msg = reset_sbp.pack()
985 self.driver.write(reset_msg)
987 rospy.logwarn(
"Swift receiver hard reset via rosservice call.")
993 response.success =
True 994 response.message =
"Swift receiver reset command sent." 996 response.success =
False 997 response.message =
"Swift receiver reset command not sent." 1002 response = SettingsWriteResponse()
1004 self.
settings_write(request.section_setting, request.setting, request.value)
1005 response.success =
True 1006 response.message =
"Settings written. Please use service 'settings_read_req' if you want to double check." 1011 response = SettingsReadReqResponse()
1016 response.success =
True 1017 response.message =
"Read-request sent. Please use 'settings_read_resp' to get the response." 1022 response = SettingsReadRespResponse()
1025 response.success =
True 1026 response.message =
"" 1031 response.success =
False 1032 response.message =
"Please trigger a new 'settings_read_req' via service call." 1033 response.section_setting = []
1034 response.setting = []
1042 response = std_srvs.srv.SetBoolResponse()
1046 response.success =
True 1047 response.message =
"Swift receiver settings have been saved to flash." 1049 response.success =
False 1050 response.message =
"Please pass 'true' to this service call to explicitly save to flash the local settings." 1055 command = [
"pip",
"show",
"sbp"]
1056 pip_show_output = subprocess.Popen(command, stdout=subprocess.PIPE)
1057 out, error = pip_show_output.communicate()
1060 version_output = re.search(
"Version: \d+.\d+.\d+", out)
1062 if version_output
is None:
1064 rospy.logfatal(
"No SBP library found. Please install it by using script in 'install' folder.")
1065 rospy.signal_shutdown(
"No SBP library found. Please install it by using script in 'install' folder.")
1069 version_output_string = version_output.group()
1070 version_number = re.search(
"\d+.\d+.\d+", version_output_string)
1071 return version_number.group()
1075 Write the defined configuration to Swift receiver. 1077 setting_string =
'%s\0%s\0%s\0' % (section_setting, setting, value)
1078 write_msg = MsgSettingsWrite(setting=setting_string)
1083 Save settings message persists the device's current settings 1084 configuration to its on-board flash memory file system. 1086 save_msg = MsgSettingsSave()
1091 Request a configuration value to Swift receiver. 1093 setting_string =
'%s\0%s\0' % (section_setting, setting)
1094 read_req_msg = MsgSettingsReadReq(setting=setting_string)
1095 self.
framer(read_req_msg)
1099 Response to a settings_read_req. 1101 msg = MsgSettingsReadResp(msg_raw)
1102 setting_string = msg.setting.split(
'\0')
1109 Request a configuration value to Swift receiver by parameter index number. 1111 read_req_by_index_msg = MsgSettingsReadByIndexReq(index=index)
1112 self.
framer(read_req_by_index_msg)
1116 Response to a settings_read_by_index_req. 1118 msg = MsgSettingsReadByIndexResp(msg_raw)
1119 setting_string = msg.setting.split(
'\0')
def cb_sbp_heartbeat(self, msg_raw, metadata)
def publish_rtk_fix(self, latitude, longitude, height)
def enu_to_point_msg(self, east, north, up)
def init_callback(self, topic_name, ros_datatype, sbp_msg_type, callback_data_type, attrs)
def cb_settings_read_resp(self, msg_raw, metadata)
def clear_last_setting_read(self)
def reset_piksi_service_callback(self, request)
def settings_read_req_server(self, request)
def init_receiver_state_msg(self)
def geodetic_to_enu(self, latitude, longitude, altitude)
def create_topic_callbacks(self)
last_section_setting_read
def enu_to_pose_msg(self, east, north, up, variance)
def publish_rtk_float(self, latitude, longitude, height)
def publish_wgs84_point(self, latitude, longitude, height, variance, navsat_status, pub_navsatfix, pub_pose, pub_point, pub_transform, pub_navsatfix_best_pose, pub_pose_best_fix)
def cb_sbp_uart_state(self, msg_raw, metadata)
base_station_ip_for_latency_estimation
def cb_sbp_pos_llh(self, msg_raw, metadata)
def ecef_to_ned(self, x, y, z)
def cb_sbp_base_pos_ecef(self, msg_raw, metadata)
def init_num_corrections_msg(self)
def settings_write_server(self, request)
def enu_to_transform_msg(self, east, north, up)
def cb_sbp_settings_read_by_index_resp(self, msg_raw, metadata)
def cb_sbp_obs(self, msg_raw, metadata)
def cb_sbp_glonass_biases(self, msg_raw, metadata)
def cb_sbp_tracking_state(self, msg_raw, metadata)
def cb_sbp_base_pos_llh(self, msg_raw, metadata)
def multicast_callback(self, msg, metadata)
def settings_read_req(self, section_setting, setting)
def settings_write(self, section_setting, setting, value)
def settings_read_resp_server(self, request)
def advertise_topics(self)
def make_callback(self, sbp_type, ros_message, pub, attrs)
def advertise_services(self)
def publish_spp(self, latitude, longitude, height, variance, navsatstatus_fix)
def get_installed_sbp_version(self)
def cb_watchdog(self, event)
def settings_save_callback(self, request)
def init_geodetic_reference(self, latitude, longitude, altitude)
def publish_receiver_state_msg(self)
def settings_read_by_index_req(self, index)
def geodetic_to_ecef(self, latitude, longitude, altitude)
def n_re(self, lat_radians, lon_radians)
def ping_base_station_over_wifi(self)