overlay_sample.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 try:
00003   from jsk_rviz_plugins.msg import *
00004 except:
00005   import roslib;roslib.load_manifest("jsk_rviz_plugins")
00006   from jsk_rviz_plugins.msg import *
00007 
00008 from std_msgs.msg import ColorRGBA, Float32
00009 import rospy
00010 import math
00011 rospy.init_node("overlay_sample")
00012 
00013 text_pub = rospy.Publisher("text_sample", OverlayText, queue_size=1)
00014 value_pub = rospy.Publisher("value_sample", Float32, queue_size=1)
00015 counter = 0
00016 rate = 100
00017 r = rospy.Rate(rate)
00018 import random, math
00019 while not rospy.is_shutdown():
00020   counter = counter + 1
00021   text = OverlayText()
00022   theta = counter % 255 / 255.0
00023   text.width = 400
00024   text.height = 600
00025   #text.height = 600
00026   text.left = 10
00027   text.top = 10
00028   text.text_size = 12
00029   text.line_width = 2
00030   text.font = "DejaVu Sans Mono"
00031   text.text = """This is OverlayText plugin.
00032 The update rate is %d Hz.
00033 You can write several text to show to the operators.
00034 New line is supported and automatical wrapping text is also supported.
00035 And you can choose font, this text is now rendered by '%s'
00036 
00037 You can specify background color and foreground color separatelly.
00038 
00039 Of course, the text is not needed to be fixed, see the counter: %d.
00040 
00041 You can change text color like <span style="color: red;">this</span>
00042 by using <span style="font-style: italic;">css</style>.
00043   """ % (rate, text.font, counter)
00044   text.fg_color = ColorRGBA(25 / 255.0, 1.0, 240.0 / 255.0, 1.0)
00045   text.bg_color = ColorRGBA(0.0, 0.0, 0.0, 0.2)
00046   text_pub.publish(text)
00047   value_pub.publish(math.sin(counter * math.pi * 2 / 100))
00048   if int(counter % 500) == 0:
00049     rospy.logdebug('This is ROS_DEBUG.')
00050   elif int(counter % 500) == 100:
00051     rospy.loginfo('This is ROS_INFO.')
00052   elif int(counter % 500) == 200:
00053     rospy.logwarn('This is ROS_WARN.')
00054   elif int(counter % 500) == 300:
00055     rospy.logerr('This is ROS_ERROR.')
00056   elif int(counter % 500) == 400:
00057     rospy.logfatal('This is ROS_FATAL.')
00058   r.sleep()
00059 


jsk_rviz_plugins
Author(s): Kei Okada , Yohei Kakiuchi , Shohei Fujii , Ryohei Ueda
autogenerated on Wed May 1 2019 02:40:22