poseEditor.py
Go to the documentation of this file.
1 import math
2 from javax.swing import *
3 from java.awt import *
4 import hrp
5 from OpenHRP.StateHolderServicePackage import CommandHolder
6 
7 class jointPanel(JPanel):
8  def __init__(self, linkinfo, seq, angle):
9  self.seq = seq
10  if len(linkinfo.ulimit) > 0:
11  self.maxDeg = linkinfo.ulimit[0]*180/math.pi
12  else:
13  self.maxDeg = 180
14  if len(linkinfo.llimit) > 0:
15  self.minDeg = linkinfo.llimit[0]*180/math.pi
16  else:
17  self.minDeg = -180
18  self.jointId = linkinfo.jointId
19  self.name = linkinfo.name
20  nameLabel = JLabel(linkinfo.name+":")
21  nameLabel.setPreferredSize(Dimension(150, 15));
22  self.add(nameLabel)
23  self.add(JLabel("%4.0f"%self.minDeg))
24  self.slider = JSlider(maximum=int(self.maxDeg), minimum=int(self.minDeg), stateChanged=self.setAngleSlider)
25  self.add(self.slider)
26  self.add(JLabel("%4.0f"%self.maxDeg))
27  self.text = JTextField(5, actionPerformed=self.setAngleText)
28  self.add(self.text)
29  self.angle = angle
30  def setAngleText(self, event):
31  txt = self.text.getText()
32  angDeg = float(txt)
33  if angDeg > self.maxDeg:
34  angDeg = self.maxDeg
35  self.text.setText(str(angDeg))
36  if angDeg < self.minDeg:
37  angDeg = self.minDeg
38  self.text.setText(str(angDeg))
39  self.slider.setValue(int(float(angDeg)))
40  self.setTargetAngle(angDeg)
41  def setAngleSlider(self, event):
42  angDeg = self.slider.getValue()
43  self.text.setText(str(angDeg))
44  self.setTargetAngle(angDeg)
45  def setCurrentAngle(self,angle):
46  self.slider.setValue(int(angle))
47  self.angle = angle
48  def setTargetAngle(self, target):
49  delta = abs(self.angle - target)
50  if delta == 0:
51  return
52  tm = delta/20.0
53  if tm < 0.1:
54  tm = 0.1
55  self.seq.waitInterpolation()
56  self.seq.setJointAngle(self.name, target*math.pi/180, tm)
57  self.angle = target
58 
59 
60 class poseEditor(JFrame):
61  def __init__(self, url, seq, sh):
62  ml = hrp.findModelLoader()
63  self.bodyInfo = ml.getBodyInfo(url)
64  self.dof = 0
65  for li in self.bodyInfo.links():
66  if li.jointId >= 0:
67  self.dof += 1
68  print "dof=",self.dof
69  self.setSize(550, 800)
70  self.seq = seq
71  self.sh = sh
72  panel = JPanel()
73  panel.setLayout(BorderLayout())
74  sPane = ScrollPane()
75  sPane.setSize(400,720)
76  jointsPanel = JPanel()
77  jointsPanel.setLayout(BoxLayout(jointsPanel,
78  BoxLayout.Y_AXIS))
79  command = CommandHolder()
80  self.sh.getCommand(command)
81  jav = command.value.jointRefs
82  self.jpanels = []
83  for li in self.bodyInfo.links():
84  if li.jointId >= 0:
85  jp = jointPanel(li, seq, jav[li.jointId]*180/math.pi)
86  self.jpanels.append(jp)
87  jointsPanel.add(jp)
88  sPane.add(jointsPanel)
89  panel.add(sPane, BorderLayout.NORTH)
90  commandPanel = JPanel()
91  commandPanel.add(JButton("get pose", actionPerformed=self.getPose))
92  panel.add(commandPanel, BorderLayout.SOUTH)
93  self.add(panel)
94  self.getPose(None)
95  self.setVisible(True)
96  def getPose(self, event):
97  command = CommandHolder()
98  self.sh.getCommand(command)
99  jav = command.value.jointRefs
100  for jp in self.jpanels:
101  jp.setCurrentAngle(jav[jp.jointId]*180/math.pi)
102 
103 
104 
105 
106 
def setAngleSlider(self, event)
Definition: poseEditor.py:41
def setTargetAngle(self, target)
Definition: poseEditor.py:48
def getPose(self, event)
Definition: poseEditor.py:96
def __init__(self, linkinfo, seq, angle)
Definition: poseEditor.py:8
def setCurrentAngle(self, angle)
Definition: poseEditor.py:45
def findModelLoader(rnc=None)
def setAngleText(self, event)
Definition: poseEditor.py:30
def __init__(self, url, seq, sh)
Definition: poseEditor.py:61


hrpsys
Author(s): AIST, Fumio Kanehiro
autogenerated on Thu May 6 2021 02:41:50