Merge lp:~shadowrobot/sr-ros-interface/F_temp_monitor into lp:sr-ros-interface

Proposed by Ugo
Status: Merged
Merged at revision: 397
Proposed branch: lp:~shadowrobot/sr-ros-interface/F_temp_monitor
Merge into: lp:sr-ros-interface
Diff against target: 168 lines (+154/-0)
2 files modified
.bzrignore (+8/-0)
sr_utilities/nodes/temperature_monitor.py (+146/-0)
To merge this branch: bzr merge lp:~shadowrobot/sr-ros-interface/F_temp_monitor
Reviewer Review Type Date Requested Status
Ugo Pending
Review via email: mp+141901@code.launchpad.net

Description of the change

Added a simple curses temperature monitor for the motors.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file '.bzrignore'
2--- .bzrignore 2012-11-20 18:05:28 +0000
3+++ .bzrignore 2013-01-04 11:56:21 +0000
4@@ -312,3 +312,11 @@
5 ./sr_hand/bin/test/hand_commander_test
6 ./sr_mechanism_controllers/bin/test/test_joint_position_controller
7 ./sr_move_arm/bin/hand_posture_execution
8+sr_description/.cproject
9+sr_description/.project
10+sr_description/.pydevproject
11+sr_description/_gtest_from_src
12+sr_description/cmake_install.cmake
13+sr_hand/_gtest_from_src
14+sr_utilities/_gtest_from_src
15+./sr_utilities/.settings
16
17=== added directory 'sr_utilities/nodes'
18=== added file 'sr_utilities/nodes/temperature_monitor.py'
19--- sr_utilities/nodes/temperature_monitor.py 1970-01-01 00:00:00 +0000
20+++ sr_utilities/nodes/temperature_monitor.py 2013-01-04 11:56:21 +0000
21@@ -0,0 +1,146 @@
22+#!/usr/bin/env python
23+#
24+# Copyright 2011 Shadow Robot Company Ltd.
25+#
26+# This program is free software: you can redistribute it and/or modify it
27+# under the terms of the GNU General Public License as published by the Free
28+# Software Foundation, either version 2 of the License, or (at your option)
29+# any later version.
30+#
31+# This program is distributed in the hope that it will be useful, but WITHOUT
32+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
33+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
34+# more details.
35+#
36+# You should have received a copy of the GNU General Public License along
37+# with this program. If not, see <http://www.gnu.org/licenses/>.
38+#
39+
40+import roslib; roslib.load_manifest("sr_utilities")
41+import rospy
42+from diagnostic_msgs.msg import DiagnosticArray
43+
44+import curses, traceback
45+
46+CASE_WIDTH = 20
47+CASE_HEIGHT = 1
48+JOINT_NAMES = ["FFJ0", "FFJ3", "FFJ4",
49+ "MFJ0", "MFJ3", "MFJ4",
50+ "RFJ0", "RFJ3", "RFJ4",
51+ "LFJ0", "LFJ3", "LFJ4",
52+ "THJ1", "THJ2", "THJ3", "THJ4", "THJ5",
53+ "WRJ1", "WRJ2"]
54+COOL = 50
55+WARM = 55
56+
57+class Joint(object):
58+ def __init__(self, screen, joint_name, x, y):
59+ self.screen = screen
60+ self.x = x
61+ self.y = y
62+ self.joint_name = joint_name
63+ self.temperature = -1
64+
65+ #self.window = self.screen.subwin(1, 15, self.y+1, self.x + 1)
66+ self.refresh()
67+
68+
69+ def set_temperature(self, temperature):
70+ self.temperature = temperature
71+ self.refresh()
72+
73+ def refresh(self):
74+ self.screen.addstr(self.y+1, self.x+1, self.joint_name)
75+
76+ if self.temperature == -1: #joint not found
77+ self.screen.addstr(self.y + 1, self.x + 6, "X", curses.color_pair(4) )
78+ elif self.temperature < COOL:
79+ self.screen.addstr(self.y + 1, self.x+6, str(self.temperature), curses.color_pair(1) )
80+ elif self.temperature < WARM:
81+ self.screen.addstr(self.y + 1, self.x + 6, str(self.temperature), curses.color_pair(2) )
82+ else:
83+ self.screen.addstr(self.y + 1, self.x + 6, str(self.temperature), curses.color_pair(3) )
84+ #self.window.refresh()#0,0,0,0,1,15)
85+
86+class TemperatureMonitor(object):
87+ MAX_X = 17
88+ MAX_Y = 21
89+
90+ def __init__(self, screen = None):
91+ try:
92+ curses.curs_set(0)
93+ except:
94+ pass
95+ self.screen = screen
96+ self.pad = curses.newpad(self.MAX_Y,self.MAX_X)
97+ self.pad_pos_x_ = 0
98+ self.pad_pos_y_ = 0
99+ self.pad.border(0)
100+ self.joint_monitors = {}
101+
102+ curses.init_pair(4, curses.COLOR_WHITE, curses.COLOR_BLACK)
103+ curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_GREEN)
104+ curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_YELLOW)
105+ curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_RED)
106+
107+ for index,joint_name in enumerate(JOINT_NAMES):
108+ begin_x = 0
109+ begin_y = CASE_HEIGHT*index
110+
111+ self.joint_monitors[joint_name] = Joint(self.pad, joint_name, begin_x, begin_y)
112+
113+ self.diag_sub_ = rospy.Subscriber("/diagnostics", DiagnosticArray, self.diag_cb_)
114+ self.resize_()
115+
116+ while True:
117+ event = self.pad.getch()
118+ if event == ord("q"): break
119+ elif event == curses.KEY_RESIZE:
120+ self.resize_()
121+
122+ elif event == ord("s"):
123+ self.pad_pos_y_ += 1
124+ self.refresh_()
125+ elif event == ord("w"):
126+ self.pad_pos_y_ -= 1
127+ self.refresh_()
128+ elif event == ord("a"):
129+ self.pad_pos_x_ -= 1
130+ self.refresh_()
131+ elif event == ord("d"):
132+ self.pad_pos_x_ += 1
133+ self.refresh_()
134+
135+ def diag_cb_(self, msg):
136+ for status in msg.status:
137+ for joint in JOINT_NAMES:
138+ if joint in status.name:
139+ for value in status.values:
140+ if value.key == "Temperature":
141+ self.joint_monitors[joint].set_temperature(round(float(value.value), 1))
142+ break
143+ break
144+ self.resize_()
145+
146+ def resize_(self):
147+ self.pad_pos_x_ = 0
148+ self.pad_pos_y_ = 0
149+ self.refresh_()
150+
151+ def refresh_(self):
152+ y,x = self.screen.getmaxyx()
153+ self.pad_pos_x_ = min(max(self.pad_pos_x_, 0), self.MAX_X - 1)
154+ self.pad_pos_y_ = min(max(self.pad_pos_y_, 0), self.MAX_Y - 1)
155+ self.pad.refresh(self.pad_pos_y_, self.pad_pos_x_, 0,0, y - 1, x -1)
156+ self.pad.border(0)
157+ for monitor in self.joint_monitors.values():
158+ monitor.refresh()
159+
160+
161+
162+if __name__ == '__main__':
163+ rospy.init_node("temperature_monitor", anonymous=True)
164+ try:
165+ curses.wrapper(TemperatureMonitor)
166+ except:
167+ traceback.print_exc()
168\ No newline at end of file

Subscribers

People subscribed via source and target branches

to all changes: