dummy_client.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # License: BSD
00004 #   https://raw.github.com/robotics-in-concert/rocon_devices/license/LICENSE
00005 #
00006 #################################################################################
00007 # sys
00008 import random
00009 
00010 # ros
00011 import rospy
00012 from rocon_device_msgs.msg import HueState, Hue, HueArray
00013 
00014 
00015 class Test():
00016 
00017     def __init__(self):
00018         rospy.init_node("dummy_hue_client")
00019         rospy.loginfo("dummy_hue_client start")
00020         self.set_hue_publisher = rospy.Publisher("/set_hue", Hue, queue_size=10)
00021         rospy.Subscriber("/list_hue", HueArray, self.set_valid_hues)
00022         self.hue_list = []
00023         self.pre_define_color = ['WHITE', 'RED', 'GREEN', 'BLUE', 'ORANGE']
00024 
00025     def set_valid_hues(self, data):
00026         self.hue_list = data.hue_list
00027 
00028     def spin(self):
00029         while not rospy.is_shutdown():
00030             color = random.randint(0, len(self.pre_define_color) - 1)
00031             for k in [1, 2, 3]:
00032                 hue = Hue()
00033                 hue.state.color = str(self.pre_define_color[color])
00034                 hue.light_id = k
00035                 self.set_hue_publisher.publish(hue)
00036                 rospy.sleep(0.1)
00037                 rospy.loginfo(str(k) + "  change: " + str(self.pre_define_color[color]))
00038             rospy.sleep(8.0)
00039             """
00040             for hue in self.hue_list:
00041                 if hue.state.reachable:
00042                     hue.state.hue = random.randint(0, 65535)
00043                     hue.state.sat = random.randint(0, 255)
00044                     hue.state.bri = random.randint(0, 255)
00045                     rospy.loginfo('change %s light: random color hsv [%d, %d, %d]' % (str(hue.light_id), hue.state.hue, hue.state.sat, hue.state.bri))
00046                     self.set_hue_publisher.publish(hue)
00047             rospy.sleep(5.0)
00048 
00049             for hue in self.hue_list:
00050                 if hue.state.reachable:
00051                     color = random.randint(0, len(self.pre_define_color)-1)
00052                     hue.state.color = str(self.pre_define_color[color])
00053                     rospy.loginfo('change %s light: pre defined color [%s]' % (str(hue.light_id), str(self.pre_define_color[color])))
00054                     self.set_hue_publisher.publish(hue)
00055             rospy.sleep(5.0)
00056             """
00057 if __name__ == '__main__':
00058     test = Test()
00059     test.spin()


rocon_hue
Author(s): DongWook Lee
autogenerated on Thu Jun 6 2019 17:58:51