rosping_ric.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 import rospy
00004 from resized_image_client import ResizedImageClient
00005 from std_msgs.msg import Float64
00006 
00007 
00008 class TrafficMode():
00009     stop = 0
00010     error = 1
00011     narrow = 2
00012     normal = 3
00013     wide = 4
00014 
00015 class RospingRIC(ResizedImageClient):
00016     def __init__(self, node, ping_node, x=0.1, y=0.1, mps=1.0):
00017         ResizedImageClient.__init__(self, node, x, y, mps)
00018         self.sub_ping = rospy.Subscriber(ping_node, Float64, self.pingCB)
00019         self.old_mode = TrafficMode.stop
00020         self.mode = TrafficMode.narrow
00021 
00022     def pingCB(self, data):
00023         delay = data.data
00024 
00025         # sample
00026         # if delay > 0:
00027         # self.msg_per_second = 10.0
00028         # self.resize_scale_x = 1.0/(1.0 + delay)
00029         # self.resize_scale_y = 1.0/(1.0 + delay)
00030 
00031         if delay < 0:
00032             self.mode = TrafficMode.error
00033         elif delay < 10.0:
00034             self.mode = TrafficMode.wide
00035         elif delay < 500.0:
00036             self.mode = TrafficMode.normal
00037         else:
00038             self.mode = TrafficMode.narrow
00039 
00040         if self.old_mode != self.mode:
00041             if self.mode == TrafficMode.error:
00042                 self.msg_per_second = 10.0
00043                 self.resize_scale_x = 0.1
00044                 self.resize_scale_y = 0.1
00045             elif self.mode == TrafficMode.narrow:
00046                 self.msg_per_second = 1.0
00047                 self.resize_scale_x = 0.1
00048                 self.resize_scale_y = 0.1
00049             elif self.mode == TrafficMode.normal:
00050                 self.msg_per_second = 1.0
00051                 self.resize_scale_x = 0.3
00052                 self.resize_scale_y = 0.3
00053             elif self.mode == TrafficMode.wide:
00054                 self.msg_per_second = 1.0
00055                 self.resize_scale_x = 1.0
00056                 self.resize_scale_y = 1.0
00057 
00058             self.update()
00059             self.old_mode = self.mode
00060 
00061 if __name__ == '__main__':
00062     rospy.init_node('rosping_resized_image_client')
00063     image_node = rospy.get_param('image_node', '/head_resized')
00064     delay_node = rospy.get_param('delay_node', '/ping/delay')
00065     ric = RospingRIC(image_node, delay_node)
00066     rospy.spin()
00067     while True:
00068         ric.update()
00069         time.sleep(1)
00070 
00071 
00072 


resized_image_transport
Author(s): Yohei Kakiuchi
autogenerated on Mon Oct 6 2014 01:16:31