monitor.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 # The MIT License (MIT)
3 #
4 # Copyright (c) 2018 Bluewhale Robot
5 #
6 # Permission is hereby granted, free of charge, to any person obtaining a copy
7 # of this software and associated documentation files (the "Software"), to deal
8 # in the Software without restriction, including without limitation the rights
9 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 # copies of the Software, and to permit persons to whom the Software is
11 # furnished to do so, subject to the following conditions:
12 #
13 # The above copyright notice and this permission notice shall be included in all
14 # copies or substantial portions of the Software.
15 #
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 # SOFTWARE.
23 #
24 # Author: Xie fusheng
25 # Randoms
26 
27 
28 '''
29 This is a system monitor node for xiaoqiang. Monitor items are power, odom, brightness etc.
30 System status will be published at report
31 '''
32 import commands
33 import os
34 import threading
35 
36 import rospy
37 from geometry_msgs.msg import Pose
38 from nav_msgs.msg import Odometry
39 from sensor_msgs.msg import Image
40 from std_msgs.msg import Bool, Float64, String, UInt32
41 from xiaoqiang_msgs.msg import Status
42 
43 REPORT_PUB = ""
44 STATUS = Status()
45 STATUS.brightness = 0
46 STATUS.image_status = False
47 STATUS.odom_status = False
48 STATUS.orb_start_status = False
49 STATUS.orb_init_status = False
50 STATUS.power = 0
51 STATUS.orb_scale_status = False
52 POWER_LOW = 10.0
53 
54 STATUS_LOCK = threading.Lock()
55 
56 
57 def get_brightness(brightness):
58  STATUS_LOCK.acquire()
59  STATUS.brightness = brightness.data
60  STATUS_LOCK.release()
61 
62 
63 def get_image(image):
64  STATUS_LOCK.acquire()
65  if image != None:
66  STATUS.image_status = True
67  else:
68  STATUS.image_status = False
69  STATUS_LOCK.release()
70 
71 
72 def get_power(power):
73  STATUS_LOCK.acquire()
74  STATUS.power = power.data-0.3
75  STATUS_LOCK.release()
76 
77 
78 def get_odom(odom):
79  STATUS_LOCK.acquire()
80  if odom != None:
81  STATUS.odom_status = True
82  else:
83  STATUS.odom_status = False
84  STATUS_LOCK.release()
85 
86 
87 def get_orb_start_status(orb_frame):
88  STATUS_LOCK.acquire()
89  if orb_frame != None:
90  STATUS.orb_start_status = True
91  else:
92  STATUS.orb_start_status = False
93  STATUS_LOCK.release()
94 
95 
96 def get_orb_tracking_flag(camera_pose):
97  STATUS_LOCK.acquire()
98  if camera_pose != None:
99  STATUS.orb_init_status = True
100  else:
101  STATUS.orb_init_status = False
102  STATUS_LOCK.release()
103 
104 
106  STATUS_LOCK.acquire()
107  STATUS.orb_scale_status = flag.data
108  STATUS_LOCK.release()
109 
110 
111 def monitor():
112  global REPORT_PUB
113  rospy.init_node("monitor", anonymous=True)
114  rospy.Subscriber("/camera_node/brightness", UInt32, get_brightness)
115  rospy.Subscriber("/camera_node/image_raw", Image, get_image)
116  rospy.Subscriber("/orb_slam/frame", Image, get_orb_start_status)
117  rospy.Subscriber("/xiaoqiang_driver/power", Float64, get_power)
118  rospy.Subscriber("/xiaoqiang_driver/odom", Odometry, get_odom)
119  rospy.Subscriber("/orb_slam/camera", rospy.msg.AnyMsg,
120  get_orb_tracking_flag)
121  rospy.Subscriber("/orb_slam/scale_status", Bool, get_orb_scale_status)
122  REPORT_PUB = rospy.Publisher(
123  '/xiaoqiang_monitor/report', Status, queue_size=0)
124 
125 
126 if __name__ == "__main__":
127  monitor()
128  rate = rospy.Rate(1)
129 
130  while not rospy.is_shutdown():
131  STATUS_LOCK.acquire()
132  if REPORT_PUB != "":
133  REPORT_PUB.publish(STATUS)
134  # clear data
135  STATUS.brightness = 0
136  STATUS.power = 0
137  STATUS.image_status = False
138  STATUS.odom_status = False
139  STATUS.orb_init_status = False
140  STATUS.orb_start_status = False
141  STATUS.orb_scale_status = False
142  STATUS_LOCK.release()
143  rate.sleep()
def get_orb_scale_status(flag)
Definition: monitor.py:105
def get_orb_tracking_flag(camera_pose)
Definition: monitor.py:96
def get_image(image)
Definition: monitor.py:63
def get_brightness(brightness)
Definition: monitor.py:57
def get_odom(odom)
Definition: monitor.py:78
def get_power(power)
Definition: monitor.py:72
def monitor()
Definition: monitor.py:111
def get_orb_start_status(orb_frame)
Definition: monitor.py:87


xiaoqiang_monitor
Author(s):
autogenerated on Mon Jun 10 2019 15:53:30