getDockIR.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 #########AUTHOR: Younghun Ju <yhju@yujinrobot.comm>, <yhju83@gmail.com>
3 
4 import roslib; roslib.load_manifest('kobuki_node')
5 import rospy
6 
7 from kobuki_msgs.msg import DockInfraRed
8 from kobuki_msgs.msg import SensorState
9 
10 class Converter(object):
11 
12  def __init__(self):
13  rospy.init_node("dock_ir_intepreter", anonymous=True)
14  self.sub_dock_ir = rospy.Subscriber("/mobile_base/sensors/dock_ir", DockInfraRed, self.DockIRCallback)
15  self.sub_core = rospy.Subscriber("/mobile_base/sensors/core" , SensorState, self.SensorStateCallback)
16  self.window = rospy.get_param('~window',10)
17  self.oneline = rospy.get_param('~oneline',False)
18  self.stack = []
19  self.bumper = 0
20  self.charger = 0
21 
22 
23  def SensorStateCallback(self,data):
24  self.bumper = data.bumper
25  self.charger = data.charger
26 
27  def DockIRCallback(self,data):
28  #v1 not filtering
29  array = [ ord(x) for x in data.data]
30  array.reverse()
31  #v2 filtering
32  self.stack.append(array)
33  while len(self.stack) > self.window:
34  del self.stack[0]
35  if not self.oneline: print
36  head = "window: {0:d}/{1:d} ".format(len(self.stack),self.window)
37  head += "charger: {0:d} ".format(self.charger)
38  head += "[ON] " if self.charger else "[ ] "
39  head += "bumper: ["
40  head += "L" if self.bumper&4 else "~"
41  head += "C" if self.bumper&2 else "~"
42  head += "R" if self.bumper&1 else "~"
43  head += "]"
44 
45  array = [0,0,0]
46  for i in range(len(self.stack)):
47  for j in range(3):
48  array[j] |= self.stack[i][j]
49 
50 
51  delimiter = " " if self.oneline else "\n"
52  ostr = ""
53  ostr_top = "[far ] "; ostr_bot = "[near] "; ostr_bin="[bin ] "; ostr_dec="[dec ] "
54  for ir in array:
55  #ver1: just digits:
56  #ostr += "{0:3d}".format(ord(array[i])) + " "
57  #ver2: just binary number:
58  #ostr += "{0:#08b}".format(ord(array[i]))[2:] + " "
59  #ver3: [far]/[near] = [R|C|L]/[R|C|L] for each channel
60  #ostr_top = ""; ostr_bot = ""
61  top = ir>>3; bot =ir
62  ostr_top += " L" if top&2 else " ~" # far left is 16
63  ostr_top += "|C" if top&1 else "|~" # far center is 8
64  ostr_top += "|R" if top&4 else "|~" # far right is 32
65  ostr_bot += " L" if bot&1 else " ~" # near left is 1
66  ostr_bot += "|C" if bot&2 else "|~" # near center is 2
67  ostr_bot += "|R" if bot&4 else "|~" # near right is 4
68  ostr_top += " "; ostr_bot += " "
69  ostr_bin += "{0:#08b}".format(ir)[2:] + " "
70  #ostr_dec += "{0:3d}".format(ir) + " "
71  ostr = head + delimiter + ostr_top + delimiter + ostr_bot + delimiter + ostr_bin# + "\n" + ostr_dec
72  #verN: average
73  #verN:
74  print ostr
75 
76 if __name__ == '__main__':
77  try:
78  instance = Converter()
79  print
80  print "It converts dock_ir data to human friendly format."
81  print
82  rospy.spin()
83  except rospy.ROSInterruptException: pass
def SensorStateCallback(self, data)
Definition: getDockIR.py:23
def DockIRCallback(self, data)
Definition: getDockIR.py:27
def __init__(self)
Definition: getDockIR.py:12


kobuki_auto_docking
Author(s): Younghun Ju
autogenerated on Mon Jun 10 2019 13:44:57