3 Use this node to establish a connection with the metraTec IPS receiver or USB stick. You have to pass the USB port the 4 stick is connected to or the IP address of the regular receiver as a command line argument or as a private parameter 5 when you are using a launch file. 7 Running from command line: 8 $ rosrun ros_ips receiver.py <TYPE> <REQUIRED> <OPTIONAL> 10 $ rosrun ros_ips receiver.py usb /dev/ttyUSB0 11 $ rosrun ros_ips receiver.py tcp 192.168.2.223 14 - ips/receiver/send (std_msgs/String): 15 Message to be sent over the TCP or serial connection to the IPS receiver or USB stick 18 - ips/receiver/raw (ros_ips/StringStamped): 19 Raw messages received from the receiver or USB stick 22 - ~host (string, default=None): 23 IP address of the connected receiver 24 - ~port (with host: int, default=10001; without host: string, default=None): 25 Port for the TCP connection if '~host' parameter is present, otherwise specifies the USB port of the stick 26 - ~baudrate (int, default=115200): 27 Baudrate to use for serial communication with USB receiver 30 from __future__
import print_function
33 from std_msgs.msg
import String
34 from ros_ips.msg
import StringStamped
41 Use this class to establish a connection with the metraTec IPS receiver or USB stick and publish the received 42 messages to the ips/receiver/raw topic. The node also listens to the ips/receiver/send topic and invokes a 43 callback that forwards these messages to the connected receiver when it is updated. 47 Initialize IPS receiver class by passing the IP address the receiver or port the USB stick is connected to. 48 :param type: String: type of the connection, either 'tcp' or 'usb' 49 :param required: String: Either HOST_IP or USB_PORT of the receiver 50 :param optional: Int: Either TCP_PORT or BAUDRATE to use for the connection 59 if self.
type ==
'usb':
60 baudrate = self.
opt if self.
opt is not None else 115200
62 elif self.
type ==
'tcp':
63 port = self.
opt if self.
opt is not None else 10001
66 print(
'Connection type "{}" is invalid. Shutting down node!'.format(self.
type))
67 rospy.signal_shutdown(
'Connection type "{}" is invalid. Shutting down node!'.format(self.
type))
72 self.
rec_pub = rospy.Publisher(
'ips/receiver/raw', StringStamped, queue_size=10)
78 Send message to connected device when /ips/receiver/send topic is updated. 79 :param msg: String: message to be sent to the connected device 81 self.con.send(msg.data)
86 """Publish raw receiver messages to the ips/receiver/raw topic.""" 87 while not rospy.is_shutdown():
89 line = self.con.get_line(b
'\r')
92 msg.header.stamp = rospy.Time.now()
95 self.rec_pub.publish(msg)
100 """Close USB connection on shutdown.""" 106 Return required and optional parameters for this node. Parameters are taken from ROS parameter server if available, 107 otherwise from command line arguments. Required arguments are either HOST_IP or USB_PORT. Depending on the required 108 parameter the optional parameter is either a TCP_PORT or the BAUDRATE, respectively. 109 :param args: CommandLineArguments: arguments passed after $rosrun receiver 110 :return: String/None: required parameter (HOST_IP for TCP/IP connection, USB_PORT for USB connection) 111 Int/None: optional parameter (TCP_PORT for TCP/IP connection, BAUDRATE for USB connection) 113 type, req, opt =
None,
None,
None 114 if rospy.has_param(
'~host'):
116 req = str(rospy.get_param(
'~host'))
117 if rospy.has_param(
'~port'):
118 opt = int(rospy.get_param(
'~port'))
119 elif rospy.has_param(
'~port'):
121 req = str(rospy.get_param(
'~port'))
122 if rospy.has_param(
'~baudrate'):
123 opt = int(rospy.get_param(
'~baudrate'))
130 return type, req, opt
133 if __name__ ==
'__main__':
135 rospy.init_node(
'receiver', anonymous=
True, disable_signals=
True)
143 except rospy.ROSInterruptException:
def __init__(self, type, required, optional)