Revision 1e52c76b scout/scoutsim/GUI.py

View differences:

scout/scoutsim/GUI.py
115 115

  
116 116
            # the following lines causes lag and does not solve real issues
117 117
            # first unregister the node
118
            #cmd = "rosnode kill /%s_behavior"%self.name
119
            #temp = subprocess.Popen(cmd, shell=True)
120
            #temp.wait() 
118
            cmd = "rosnode kill /%sBehavior"%self.name
119
            temp = subprocess.Popen(cmd, shell=True)
120
            temp.wait() 
121 121
            # this node loses contact but still is not cleaned up in rosnode
122 122
            # however, this should not affect usage at all.
123 123
        
......
129 129
            self.paused = False
130 130
        self.terminateOldBehavior()
131 131
        # do rosprocess calls for new behavior
132
        roscommand = shlex.split("rosrun libscout libscout %s %s"%
132
        roscommand = ("rosrun libscout libscout %s %s"%
133 133
                            (Behaviors.getNumber(self.behavior), self.name))
134
        self.process = subprocess.Popen(roscommand, shell=False)
134
        self.process = subprocess.Popen(roscommand, shell=True)
135 135

  
136 136
    def teleop(self):
137 137
        # teleop involved only one command \
......
144 144
            #not sure why this is happening....
145 145
            # seems to be a ros thing
146 146
            print "warning, socket error, ignored"
147
    
148
    def sonar_viz(self, on_off):
149
        # teleop involved only one command \
150
        cmd = "rosservice call /set_sonar_viz %s %s"%(on_off, self.name)
151
        try:
152
            subprocess.Popen(shlex.split(cmd), shell=False)
153
        except:
154
            #not sure why this is happening....
155
            # seems to be a ros thing
156
            print "warning, socket error, ignored"
147 157

  
148 158
    def killSelf(self):
149 159
        # terminate its current behavior
......
293 303
        self.correctTeleopButton(name)
294 304
        self.scouts[name].teleop()
295 305

  
306
    def sonar_viz(self, name, sonar_vizButton):
307
        if (sonar_vizButton.GetValue() == True):
308
            # turn on the sonar viz
309
            self.scouts[name].sonar_viz("on")
310
        else:
311
            # turn off sonar viz
312
            self.scouts[name].sonar_viz("off")
313

  
296 314
    ############################ UI stuff here ###########################
297 315
    
298 316
    def initUI(self):
......
371 389
        
372 390
        # make the scout1's controller
373 391
        self.addScoutBox("scout1");
374
        
392
    
393
    
394

  
375 395
    # copied over from old GUI
376 396
    def addScoutBox(self, name):
377 397
        self.sizer[name] = wx.FlexGridSizer(rows=2, cols=5, hgap=5, vgap=5)
......
390 410
        runButton = wx.Button(self.window, label="Run")
391 411
        killButton = wx.Button(self.window, label="Kill")
392 412
        teleopButton = wx.ToggleButton(self.window, label="Teleop")
413
        sonar_vizButton = wx.ToggleButton(self.window, label="sonar viz")
393 414
        self.allTeleopButtons[name] = teleopButton
394 415
        # row 0
395 416
        self.sizer[name].Add(scoutName)
396 417
        self.sizer[name].Add(currBehaviorLabel, wx.EXPAND | wx.ALIGN_RIGHT)
397 418
        self.sizer[name].AddStretchSpacer(1)
398
        self.sizer[name].AddStretchSpacer(1)
399 419
        self.sizer[name].Add(killButton, wx.ALIGN_RIGHT)
420
        self.sizer[name].Add(sonar_vizButton)
400 421

  
401 422
        # row 1
402 423
        self.sizer[name].Add(behaviorLabel)
......
415 436
                                        currBehaviorLabel, scoutChoices))
416 437
        teleopButton.Bind(wx.EVT_TOGGLEBUTTON, 
417 438
                                lambda event: self.teleop(name))
418

  
439
        sonar_vizButton.Bind(wx.EVT_TOGGLEBUTTON, 
440
                                lambda event: 
441
                                    self.sonar_viz(name, sonar_vizButton))
419 442
        self.mainArea.Add(self.sizer[name], proportion=1,
420 443
            flag=wx.ALL | wx.EXPAND, border=10)
421 444
        self.window.Layout()

Also available in: Unified diff