9 from std_msgs.msg
import Header
10 from nmea_msgs.msg
import Sentence
16 _MAVROS_MSGS_NAME =
"mavros_msgs" 17 _RTCM_MSGS_NAME =
"rtcm_msgs" 18 have_mavros_msgs =
False 19 have_rtcm_msgs =
False 20 if importlib.util.find_spec(_MAVROS_MSGS_NAME)
is not None:
21 have_mavros_msgs =
True 22 from mavros_msgs.msg
import RTCM
as mavros_msgs_RTCM
23 if importlib.util.find_spec(_RTCM_MSGS_NAME)
is not None:
25 from rtcm_msgs.msg
import Message
as rtcm_msgs_RTCM
31 self.
_debug = json.loads(os.environ[
"NTRIP_CLIENT_DEBUG"].lower())
37 rospy.init_node(
'ntrip_client', anonymous=
True, log_level=rospy.DEBUG)
39 rospy.init_node(
'ntrip_client', anonymous=
True)
40 host = rospy.get_param(
'~host',
'127.0.0.1')
41 port = rospy.get_param(
'~port',
'2101')
42 mountpoint = rospy.get_param(
'~mountpoint',
'mount')
45 ntrip_version = rospy.get_param(
'~ntrip_version',
None)
46 if ntrip_version ==
'':
52 if rospy.get_param(
'~authenticate',
False):
53 username = rospy.get_param(
'~username',
None)
54 password = rospy.get_param(
'~password',
None)
57 'Requested to authenticate, but param "username" was not set')
61 'Requested to authenticate, but param "password" was not set')
68 rtcm_message_package = rospy.get_param(
'~rtcm_message_package', _MAVROS_MSGS_NAME)
69 if rtcm_message_package == _MAVROS_MSGS_NAME:
74 rospy.logfatal(
'The requested RTCM package {} is a valid option, but we were unable to import it. Please make sure you have it installed'.format(rtcm_message_package))
75 elif rtcm_message_package == _RTCM_MSGS_NAME:
80 rospy.logfatal(
'The requested RTCM package {} is a valid option, but we were unable to import it. Please make sure you have it installed'.format(rtcm_message_package))
82 rospy.logfatal(
'The RTCM package {} is not a valid option. Please choose between the following packages {}'.format(rtcm_message_package, str.join([_MAVROS_MSGS_NAME, _RTCM_MSGS_NAME])))
92 mountpoint=mountpoint,
93 ntrip_version=ntrip_version,
97 logwarn=rospy.logwarn,
98 loginfo=rospy.loginfo,
99 logdebug=rospy.logdebug
103 self.
_client.ssl = rospy.get_param(
'~ssl',
False)
104 self.
_client.cert = rospy.get_param(
'~cert',
None)
105 self.
_client.key = rospy.get_param(
'~key',
None)
106 self.
_client.ca_cert = rospy.get_param(
'~ca_cert',
None)
109 self.
_client.nmea_parser.nmea_max_length = rospy.get_param(
'~nmea_max_length', NMEA_DEFAULT_MAX_LENGTH)
110 self.
_client.nmea_parser.nmea_min_length = rospy.get_param(
'~nmea_min_length', NMEA_DEFAULT_MIN_LENGTH)
111 self.
_client.reconnect_attempt_max = rospy.get_param(
'~reconnect_attempt_max', NTRIPClient.DEFAULT_RECONNECT_ATTEMPT_MAX)
112 self.
_client.reconnect_attempt_wait_seconds = rospy.get_param(
'~reconnect_attempt_wait_seconds', NTRIPClient.DEFAULT_RECONNECT_ATEMPT_WAIT_SECONDS)
113 self.
_client.rtcm_timeout_seconds = rospy.get_param(
'~rtcm_timeout_seconds', NTRIPClient.DEFAULT_RTCM_TIMEOUT_SECONDS)
117 rospy.on_shutdown(self.
stop)
121 rospy.logerr(
'Unable to connect to NTRIP server')
135 rospy.loginfo(
'Stopping RTCM publisher')
139 rospy.loginfo(
'Disconnecting NTRIP client')
144 self.
_client.send_nmea(nmea.sentence)
147 for raw_rtcm
in self.
_client.recv_rtcm():
151 return mavros_msgs_RTCM(
153 stamp=rospy.Time.now(),
160 return rtcm_msgs_RTCM(
162 stamp=rospy.Time.now(),
169 if __name__ ==
'__main__':
171 sys.exit(ntrip_ros.run())
def publish_rtcm(self, event)
def _create_rtcm_msgs_rtcm_message(self, rtcm)
def _create_mavros_msgs_rtcm_message(self, rtcm)
def subscribe_nmea(self, nmea)