console_generator.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 """
00004 This is a test script to generate console messages for testing /
00005 demonstration.
00006 """
00007 
00008 import rospy
00009 import random
00010 
00011 import rosgraph_msgs as rm
00012 from rosgraph_msgs.msg import Log
00013 
00014 class LogT(object):
00015     def __init__(self, filename, function, line, name, level, msg):
00016         self.msg = msg
00017         
00018         self.log = Log()
00019         self.log.level = level
00020         self.log.name = name
00021         self.log.file = '/home/tallest/workspaces/gir/src/' + filename
00022         self.log.line = line
00023         self.log.function = function
00024 
00025     def generate(self):
00026         self.log.header.stamp = rospy.Time.now()
00027 
00028         if isinstance(self.msg, str):
00029             self.log.msg = self.msg
00030         else:
00031             self.log.msg = self.msg()
00032         
00033         return self.log
00034 
00035 
00036 log_templates = [
00037     LogT('typewriter/src/linebreak.cpp', 'break_lines', 50,
00038          '/typewriter/output', Log.DEBUG, "Breaking\nLines."),
00039     LogT('taco_system/src/taste_evaluator.cpp', 'calc_spicy', 225,
00040          '/taste/taco_manager', Log.WARN, lambda : ('sample exceeds max capsaicin levels (%.2f)' % random.uniform(12, 19))),
00041     LogT('squirrel_observer/src/distraction.cpp', 'handle_distraction', 891,
00042          '/vision/squirrel', Log.INFO, 'squirrel detected! sending voice notification'),
00043     LogT('squirrel_observer/src/classification.cpp', 'handle_distraction', 891,
00044          '/vision/squirrel', Log.WARN, 'covariance too high, classifying as squirrel to be on safe side'),
00045     LogT('order_processing/src/obedience.cpp', 'process_orders', 12,
00046          '/behavior/mission', Log.ERROR, 'implement me!'),
00047     LogT('joint_control/src/joint_trajectory.cpp', 'iteration', 348,
00048          '/mobility/knee_controller', Log.WARN, 'low stability margin detected'),
00049     LogT('laser/src/safety_lock.cpp', 'activate_lock', 921,
00050          '/weapons/laser_eyes', Log.FATAL, 'segmentation fault')
00051     ]
00052 
00053 rospy.init_node('console_pub')
00054 rosout = rospy.Publisher('/rosout', Log, queue_size=0)
00055 
00056 while not rospy.is_shutdown():
00057     rospy.sleep(random.uniform(0.001, 0.1))
00058     msg = random.choice(log_templates).generate()
00059     rosout.publish(msg)


swri_console
Author(s): Elliot Johnson
autogenerated on Tue Sep 12 2017 03:09:35