~shadowrobot/sr-ros-interface-ethercat/electric

« back to all changes in this revision

Viewing changes to sr_control_gui/src/sr_control_gui/hand_controler.py

  • Committer: Ugo Cupcic
  • Date: 2012-08-08 10:17:21 UTC
  • mfrom: (1.1.552 shadow_robot_ethercat)
  • Revision ID: ugo@shadowrobot.com-20120808101721-lutmwmwmt06srqya
1.0.0 stable release for the etherCAT hardware

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
#!/usr/bin/env python
2
 
import sys
3
 
sys.path.append("python_hand_library/")
4
 
import roslib; roslib.load_manifest('sr_control_gui')
5
 
import rospy
6
 
from shadowhand_ros import ShadowHand_ROS
7
 
from hand_joint_sliders import JointSliders
8
 
from hand_grasps_controller import GraspsSaver
9
 
from hand_joint_chooser import JointChooser
10
 
from hand_visualisation_manager import VisualisationManager
11
 
from hand_step_recorder import StepRecorder
12
 
from hand_step_player import StepPlayer
13
 
from hand_accessories import Accessories
14
 
from cyberglove_library import Cyberglove
15
 
from arm_joint_sliders import ArmJointSliders
16
 
from glove import Glove
17
 
 
18
 
#import the wxpython GUI package
19
 
import wx
20
 
import time
21
 
 
22
 
MENU_EXIT = 0
23
 
MENU_RECORD = 1
24
 
 
25
 
class MainWindow(wx.Frame):
26
 
    """
27
 
    The main window of the GUI, displaying all the information about the
28
 
    hand software.
29
 
    """
30
 
    def __init__(self, parent, id, title):
31
 
        """
32
 
        Initializes the window and create all the widgets and the menu
33
 
    
34
 
        @param parent : the window containing the program. Should be None
35
 
        @param id : the identifying number the the frame
36
 
        @param title : the title displayed on the window
37
 
        """
38
 
        wx.Frame.__init__(self, parent, id, title, size=(1280,600))    
39
 
        #Create the library
40
 
        self.myShadowHand = ShadowHand_ROS()
41
 
        #time.sleep(1.0)
42
 
        self.myCyberglove = Cyberglove()        
43
 
        #time.sleep(1.0)
44
 
 
45
 
        #Draw menu
46
 
        menubar=wx.MenuBar()
47
 
        fil=wx.Menu()
48
 
        fil.Append(MENU_EXIT,"Exit","Quit")
49
 
        rec=wx.Menu()
50
 
        rec.Append(MENU_RECORD,"Record","Record steps")
51
 
        menubar.Append(fil,"File")
52
 
        menubar.Append(rec,"Record")
53
 
        wx.EVT_MENU(self, MENU_EXIT, self.menuListener)
54
 
        wx.EVT_MENU(self, MENU_RECORD, self.menuListener)
55
 
        self.SetMenuBar(menubar)
56
 
        
57
 
        #Add the tabs
58
 
        self.tabs = wx.Notebook(self, -1, style=(wx.NB_TOP))
59
 
 
60
 
        #Create pages and layouts
61
 
        page1 = wx.Panel(self.tabs,-1)
62
 
        layout1 = wx.FlexGridSizer(cols=1, rows=2, vgap=20)
63
 
        page1.SetSizer(layout1, True)
64
 
        #if self.myShadowHand.has_arm():
65
 
            #subPage0 = wx.Panel(page1,-1)
66
 
            #sublayout0 = wx.FlexGridSizer(cols=2, hgap=10)
67
 
            #subPage0.SetSizer(sublayout0, True)
68
 
        subPage1 = wx.Panel(page1, -1)
69
 
        sublayout1 = wx.FlexGridSizer(cols=2, rows=1, vgap=20)
70
 
        subPage1.SetSizer(sublayout1, True)
71
 
        page2 = wx.Panel(self.tabs,-1)
72
 
        layout2 = wx.FlexGridSizer(cols=1, rows=2, vgap=20)
73
 
        page2.SetSizer(layout2, True)
74
 
        page3 = wx.Panel(self.tabs,-1)
75
 
        layout3 = wx.FlexGridSizer(cols=1, rows=2, vgap=20)
76
 
        page3.SetSizer(layout3, True)
77
 
        page4 = wx.Panel(self.tabs,-1)
78
 
        layout4 = wx.FlexGridSizer(cols=1, rows=2, hgap = 20,vgap=20)
79
 
        page4.SetSizer(layout4, True)
80
 
 
81
 
        #Create the widgets
82
 
        #if self.myShadowHand.has_arm():
83
 
            #jointSliders = JointSliders(subPage0, -1,"Joints",self.myShadowHand)
84
 
        #else:
85
 
            #jointSliders = JointSliders(page1, -1,"Joints",self.myShadowHand)
86
 
        jointSliders = JointSliders(page1, -1,"Joints",self.myShadowHand)
87
 
        jointChooser = JointChooser(subPage1,-1,"Joint Chooser", self.myShadowHand)
88
 
        self.grasps = GraspsSaver(subPage1, -1, "Grasps", self.myShadowHand, jointChooser)
89
 
        visualisation = VisualisationManager(page2, -1, "Visualisation", self.myShadowHand)
90
 
        self.step = StepRecorder(self,-1,'Step recorder', self.myShadowHand, self.grasps)
91
 
        self.player = StepPlayer(page3,-1,'Step Player', self.myShadowHand)
92
 
 
93
 
        self.accessories = Accessories(page4,-1,'Accessories', self.myShadowHand)
94
 
        if self.myCyberglove.has_glove():
95
 
            self.glove = Glove(page4,-1,'Cyberglove', self.myCyberglove)
96
 
        
97
 
        if self.myShadowHand.has_arm():
98
 
            arm_slider = ArmJointSliders(page4, -1, "Arm", self.myShadowHand)
99
 
 
100
 
        #Add the widgets to display
101
 
        self.addControler(layout1, jointSliders)
102
 
        layout1.Add(subPage1)
103
 
        self.addControler(sublayout1, self.grasps)
104
 
        self.addControler(sublayout1, jointChooser)
105
 
        
106
 
        self.addControler(layout2, visualisation)
107
 
        self.addControler(layout3, self.player)
108
 
        self.addControler(layout4, self.accessories)
109
 
        if self.myShadowHand.has_arm():
110
 
            self.addControler(layout4, arm_slider)
111
 
        else:
112
 
            layout4.Add(wx.Panel(page4,-1))
113
 
        if self.myCyberglove.has_glove():
114
 
            self.addControler(layout4, self.glove)
115
 
        else:
116
 
            layout4.Add(wx.Panel(page4,-1))
117
 
        #Add the pages
118
 
        self.tabs.AddPage(page1,'Hand control')            
119
 
        self.tabs.AddPage(page2, 'Visualisation')
120
 
        self.tabs.AddPage(page3, 'Player')
121
 
        self.tabs.AddPage(page4, 'Accessories')
122
 
        
123
 
        if self.myShadowHand.has_arm():
124
 
            print "Arm detected."
125
 
 
126
 
        if self.myCyberglove.has_glove():
127
 
            print "Glove detected."
128
 
 
129
 
 
130
 
    def addControler(self,container,controler, flag = wx.ALIGN_CENTER):
131
 
        """
132
 
        Adds a widget to the window        
133
 
 
134
 
        @param container : the sizer which should contain the widget
135
 
        @param controler : the widget to add
136
 
        """
137
 
        sizertmp=wx.StaticBoxSizer(controler,wx.HORIZONTAL)
138
 
        sizertmp.Add(controler.panel,0,wx.ALL,2)
139
 
        container.Add(sizertmp, flag)    
140
 
    
141
 
    def menuListener(self, event):
142
 
        """
143
 
        Bind the menu to its action
144
 
 
145
 
        @param event : the event thrown by the clicked component
146
 
        """
147
 
        if event.GetId() == MENU_EXIT : 
148
 
            self.Close()
149
 
        if event.GetId() == MENU_RECORD :
150
 
            #self.step = StepRecorder(self,-1,'Step recorder', self.myShadowHand, self.grasps)
151
 
            self.step.Show(True)    
152
 
        
153
 
 
154
 
class MyApp(wx.App):
155
 
 
156
 
    def OnInit(self):
157
 
 
158
 
        frame = MainWindow(None,-1, "ShadowHand controller")
159
 
        frame.Show(True)
160
 
 
161
 
        self.SetTopWindow(frame)
162
 
 
163
 
        return True
164
 
 
165
 
def main():
166
 
    app = MyApp(0)
167
 
    app.MainLoop()
168
 
 
169
 
#start the script
170
 
if __name__ == "__main__":
171
 
    main()