console_generator.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 """
4 This is a test script to generate console messages for testing /
5 demonstration.
6 """
7 
8 import rospy
9 import random
10 
11 import rosgraph_msgs as rm
12 from rosgraph_msgs.msg import Log
13 
14 class LogT(object):
15  def __init__(self, filename, function, line, name, level, msg):
16  self.msg = msg
17 
18  self.log = Log()
19  self.log.level = level
20  self.log.name = name
21  self.log.file = '/home/tallest/workspaces/gir/src/' + filename
22  self.log.line = line
23  self.log.function = function
24 
25  def generate(self):
26  self.log.header.stamp = rospy.Time.now()
27 
28  if isinstance(self.msg, str):
29  self.log.msg = self.msg
30  else:
31  self.log.msg = self.msg()
32 
33  return self.log
34 
35 
36 log_templates = [
37  LogT('typewriter/src/linebreak.cpp', 'break_lines', 50,
38  '/typewriter/output', Log.DEBUG, "Breaking\nLines."),
39  LogT('taco_system/src/taste_evaluator.cpp', 'calc_spicy', 225,
40  '/taste/taco_manager', Log.WARN, lambda : ('sample exceeds max capsaicin levels (%.2f)' % random.uniform(12, 19))),
41  LogT('squirrel_observer/src/distraction.cpp', 'handle_distraction', 891,
42  '/vision/squirrel', Log.INFO, 'squirrel detected! sending voice notification'),
43  LogT('squirrel_observer/src/classification.cpp', 'handle_distraction', 891,
44  '/vision/squirrel', Log.WARN, 'covariance too high, classifying as squirrel to be on safe side'),
45  LogT('order_processing/src/obedience.cpp', 'process_orders', 12,
46  '/behavior/mission', Log.ERROR, 'implement me!'),
47  LogT('joint_control/src/joint_trajectory.cpp', 'iteration', 348,
48  '/mobility/knee_controller', Log.WARN, 'low stability margin detected'),
49  LogT('laser/src/safety_lock.cpp', 'activate_lock', 921,
50  '/weapons/laser_eyes', Log.FATAL, 'segmentation fault')
51  ]
52 
53 rospy.init_node('console_pub')
54 rosout = rospy.Publisher('/rosout', Log, queue_size=0)
55 
56 while not rospy.is_shutdown():
57  rospy.sleep(random.uniform(0.001, 0.1))
58  msg = random.choice(log_templates).generate()
59  rosout.publish(msg)
def __init__(self, filename, function, line, name, level, msg)


swri_console
Author(s):
autogenerated on Fri Apr 3 2020 03:20:03