3 from jsk_network_tools.msg
import FC2OCS, OCS2FC
5 from threading
import Lock, Thread
7 from struct
import Struct
8 import diagnostic_updater
9 from diagnostic_msgs.msg
import DiagnosticStatus
16 from roslib.message
import get_message_class
17 from std_msgs.msg
import Time
18 from jsk_network_tools.srv
import SetSendRate, SetSendRateResponse
22 message_class_str = rospy.get_param(
"~message",
23 "jsk_network_tools/FC2OCS")
27 raise Exception(
"invalid topic type: %s"%message_class_str)
31 self.diagnostic_updater.setHardwareID(
"none")
38 "~last_input_received_time", Time)
39 self.
to_port = rospy.get_param(
"~to_port", 1024)
40 self.
to_ip = rospy.get_param(
"~to_ip",
"127.0.0.1")
46 self.
sub = rospy.Subscriber(
"~input",
58 rospy.logerr(
"failed to change send_rate. event_driven is enabled.")
59 return SetSendRateResponse(ok=
False)
60 if self.send_timer.is_alive():
61 self.send_timer.shutdown()
63 rospy.set_param(
"~send_rate", self.
send_rate)
65 rospy.loginfo(
"send_rate is set to %f" % self.
send_rate)
68 return SetSendRateResponse(ok=
True)
69 except Exception
as e:
70 rospy.logerr(
"failed to set send_rate: %s" % e)
71 return SetSendRateResponse(ok=
False)
74 self.diagnostic_updater.update()
77 stat.summary(DiagnosticStatus.OK,
"OK")
79 now = rospy.Time.now()
80 stat.add(
"Uptime [sec]",
82 stat.add(
"Time from the last sending [sec]",
84 stat.add(
"Number of transmission", self.
send_num)
85 stat.add(
"Time from the last input [sec]",
88 stat.add(
"UDP address", self.
to_ip)
89 stat.add(
"UDP port", self.
to_port)
102 self.socket_client.sendto(packed_data, (self.
to_ip, self.
to_port))
108 rospy.logdebug(
"sending message")
112 rospy.loginfo(
"no message is available")
114 if __name__ ==
"__main__":
115 rospy.init_node(
"silverhammer_lowspeed_streamer")
def messageCallback(self, msg)
def sendMessage(self, msg)
def sendTimerCallback(self, event)
last_input_received_time_pub
def diagnosticTimerCallback(self, event)
def setSendRate(self, req)
def diagnosticCallback(self, stat)