viewer_helper.py
Go to the documentation of this file.
2  def update(*args):
3  None
4 
5  def updateElementConfig(*args):
6  None
7 
8 
9 def stateFullSize(robot, additionalData=()):
10  return [float(val) for val in robot.state.value + additionalData]
11 
12 
13 def refreshView(robot):
14  if robot.name == "robot":
15  name = "hrp"
16  if robot.name == "robot_device":
17  name = "hrp"
18  else:
19  name = robot.name
20  robot.viewer.updateElementConfig(name, robot.stateFullSize())
21 
22  for f in robot.displayList:
23  f()
24 
25 
26 def incrementView(robot, dt):
27  """Increment then refresh."""
28  robot.incrementNoView(dt)
29  robot.refresh()
30 
31 
32 def setView(robot, *args):
33  """Set robot config then refresh."""
34  robot.setNoView(*args)
35  # print('view')
36  robot.refresh()
37 
38 
39 def addRobotViewer(robot, **args):
40  """
41  Arguments are:
42  * small=False
43  * server='XML-RPC' == { 'XML-RPC' | 'CORBA' }
44  * verbose=True
45  """
46  verbose = args.get("verbose", True)
47  small = args.get("small", False)
48  small_extra = args.get("small_extra", 10)
49  server = args.get("server", "XML-RPC")
50 
51  try:
52  import robotviewer
53 
54  RobotClass = robot.__class__
55 
56  if small:
57  if verbose:
58  print("using a small robot")
59  RobotClass.stateFullSize = lambda x: stateFullSize(x, small_extra * (0.0,))
60  else:
61  RobotClass.stateFullSize = stateFullSize
62 
63  robot.viewer = robotviewer.client(server)
64 
65  RobotClass.refresh = refreshView
66  RobotClass.incrementNoView = RobotClass.increment
67  RobotClass.increment = incrementView
68  RobotClass.setNoView = RobotClass.set
69  RobotClass.set = setView
70 
71  robot.displayList = []
72 
73  # Check the connection
74  if args.get("dorefresh", True):
75  robot.refresh()
76 
77  except Exception:
78  if verbose:
79  print("No robot viewer, sorry.")
80  robot.viewer = RobotViewerFaked()
81 
82 
83 # ------------------------------------------------------------------------------
84 # ------------------------------------------------------------------------------
85 # ------------------------------------------------------------------------------
86 # Add a visual output when an event is called.
88  def __init__(self, viewer):
89  self.pos = 1
90  self.viewer = viewer
91  self.refresh()
92 
93  def refresh(self):
94  self.viewer.updateElementConfig("pong", [0, 0.9, self.pos * 0.1, 0, 0, 0])
95 
96  def __call__(self):
97  self.pos += 1
98  self.refresh()
99 
100 
101 def updateComDisplay(robot, comsig, objname="com"):
102  if comsig.time > 0:
103  robot.viewer.updateElementConfig(
104  objname, [comsig.value[0], comsig.value[1], 0, 0, 0, 0]
105  )
dynamic_graph.sot.core.utils.viewer_helper.incrementView
def incrementView(robot, dt)
Definition: viewer_helper.py:26
dynamic_graph.sot.core.utils.viewer_helper.addRobotViewer
def addRobotViewer(robot, **args)
Definition: viewer_helper.py:39
dynamic_graph.sot.core.utils.viewer_helper.VisualPinger.__call__
def __call__(self)
Definition: viewer_helper.py:96
dynamic_graph.sot.core.utils.viewer_helper.VisualPinger
Definition: viewer_helper.py:87
dynamic_graph.sot.core.utils.viewer_helper.VisualPinger.__init__
def __init__(self, viewer)
Definition: viewer_helper.py:88
dynamic_graph.sot.core.utils.viewer_helper.RobotViewerFaked.update
def update(*args)
Definition: viewer_helper.py:2
f
void f(void)
Definition: test_mailbox.cpp:33
dynamic_graph.sot.core.utils.viewer_helper.RobotViewerFaked.updateElementConfig
def updateElementConfig(*args)
Definition: viewer_helper.py:5
dynamic_graph.sot.core.utils.viewer_helper.RobotViewerFaked
Definition: viewer_helper.py:1
dynamic_graph.sot.core.utils.viewer_helper.stateFullSize
def stateFullSize(robot, additionalData=())
Definition: viewer_helper.py:9
dynamic_graph.sot.core.utils.viewer_helper.VisualPinger.viewer
viewer
Definition: viewer_helper.py:90
dynamic_graph.sot.core.utils.viewer_helper.setView
def setView(robot, *args)
Definition: viewer_helper.py:32
dynamic_graph.sot.core.utils.viewer_helper.refreshView
def refreshView(robot)
Definition: viewer_helper.py:13
dynamic_graph.sot.core.utils.viewer_helper.VisualPinger.pos
pos
Definition: viewer_helper.py:89
dynamic_graph.sot.core.utils.viewer_helper.VisualPinger.refresh
def refresh(self)
Definition: viewer_helper.py:93
dynamic_graph.sot.core.utils.viewer_helper.updateComDisplay
def updateComDisplay(robot, comsig, objname="com")
Definition: viewer_helper.py:101


sot-core
Author(s): Olivier Stasse, ostasse@laas.fr
autogenerated on Tue Oct 24 2023 02:26:32