Subversion Repositories Projects

Rev

Rev 716 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 716 Rev 717
Line 256... Line 256...
256
        msg = MkMsg(address=0, cmd='d', data=[500])
256
        msg = MkMsg(address=0, cmd='d', data=[500])
257
        self.getDebugMsgLn = msg.generateUartLine()
257
        self.getDebugMsgLn = msg.generateUartLine()
Line 258... Line 258...
258
       
258
       
259
 
259
 
260
    def open(self, comPort):
260
    def open(self, comPort):
261
        self.serPort = serial.Serial(comPort, 57600, timeout=0.5, rtscts=1)
261
        self.serPort = serial.Serial(comPort, 57600, timeout=0.5)
Line 262... Line 262...
262
        if not self.serPort.isOpen():
262
        if not self.serPort.isOpen():
263
            raise IOError("Failed to open serial port")
263
            raise IOError("Failed to open serial port")
Line 351... Line 351...
351
    def recordDbgMsg(self, samplePeriod, nbSamples):
351
    def recordDbgMsg(self, samplePeriod, nbSamples):
352
        result = []
352
        result = []
353
        self.serPort.flushInput()
353
        self.serPort.flushInput()
354
        msg = MkMsg(address=0, cmd='d', data=[int(samplePeriod*100)])
354
        msg = MkMsg(address=0, cmd='d', data=[int(samplePeriod*100)])
355
        self.sendMsg(msg)
355
        self.sendMsg(msg)
-
 
356
        start = time.clock()
356
        for i in range(nbSamples):
357
        for i in range(nbSamples):
357
            print i
-
 
358
            msg = self.waitForMsg('D', timeout=samplePeriod+1)
358
            msg = self.waitForMsg('D', timeout=samplePeriod+1)
359
            msg = DebugDataMsg(msg)
359
            msg = DebugDataMsg(msg)
360
            result.append(msg)
360
            result.append(msg)
-
 
361
        print "Time = ", (time.clock()-start)
-
 
362
        self.getDebugMsg();
361
        return result
363
        return result
Line -... Line 364...
-
 
364
 
Line 362... Line 365...
362
 
365
 
363
 
366
import copy
364
 
367
 
365
if __name__ == '__main__':
368
if __name__ == '__main__':
366
    try:
369
    try:
Line 367... Line 370...
367
        comm = MkComm()
370
        comm = MkComm()
368
        comm.printDebugMsg = True
371
        comm.printDebugMsg = True
Line -... Line 372...
-
 
372
        comm.open(comPort="COM4")
-
 
373
       
-
 
374
        msg = comm.getVersionMsg()
-
 
375
        print "Version: %d.%d" % msg.getVersion()
-
 
376
       
369
        comm.open(comPort="COM40")
377
        msg = MkMsg(address=2, cmd='f', data=[7, 50])
370
       
378
        comm.sendMsg(msg)
371
        msg = comm.getVersionMsg()
379
       
-
 
380
       
372
        print "Version: %d.%d" % msg.getVersion()
381
#        while True:
373
       
382
#            msg = comm.getSettingsMsg()
-
 
383
#            print "Index=",msg.getIndex()
-
 
384
#            print "Name=",msg.getName()
-
 
385
#            print
-
 
386
#            print "StickP =",msg.getSetting(SettingsMsg.IDX_STICK_P)
-
 
387
#            print "StickD =",msg.getSetting(SettingsMsg.IDX_STICK_D)
-
 
388
#            print
-
 
389
#            print "GyroP =",msg.getSetting(SettingsMsg.IDX_GYRO_P)
-
 
390
#            print "GyroI =",msg.getSetting(SettingsMsg.IDX_GYRO_I)
-
 
391
#            print "GyroD =",msg.getSetting(SettingsMsg.IDX_GYRO_D)
-
 
392
#            print "Gyro I Factor =",msg.getSetting(SettingsMsg.IDX_I_FACTOR)
-
 
393
#            
-
 
394
#            testSettings = copy.deepcopy(msg)
-
 
395
#            testSettings.setSetting(SettingsMsg.IDX_STICK_D, 0)
-
 
396
#            
-
 
397
#            testSettings.setSetting(SettingsMsg.IDX_GYRO_P, 0)
374
#        msg = comm.getSettingsMsg()
398
#            testSettings.setSetting(SettingsMsg.IDX_GYRO_I, 50)
-
 
399
#    
-
 
400
#            print "Test Settings..."
-
 
401
#            comm.sendSettings(testSettings.getSettings())
-
 
402
#            raw_input("Press ENTER to end test")
375
#        print "Index=",msg.getIndex()
403
#            
376
#        print "Name=",msg.getName()
404
#            print "Normal Settings..."
Line 377... Line 405...
377
#        print "StickP=",msg.getSetting(SettingsMsg.IDX_STICK_P)
405
#            comm.sendSettings(msg.getSettings())
378
#        print "StickD=",msg.getSetting(SettingsMsg.IDX_STICK_D)
406
       
379
#        
407
       
-
 
408
#        msg.setSetting(SettingsMsg.IDX_STICK_P, msg.getSetting(SettingsMsg.IDX_STICK_P)+1)
Line -... Line 409...
-
 
409
#        comm.sendSettings(msg.getSettings())
Line 380... Line 410...
380
#        msg.setSetting(SettingsMsg.IDX_STICK_P, msg.getSetting(SettingsMsg.IDX_STICK_P)+1)
410
       
381
#        comm.sendSettings(msg.getSettings())
411
#        messages = comm.recordDbgMsg(0.05, 20)
382
       
412
#        for msg in messages:
383
        messages = comm.recordDbgMsg(0.05, 20)
413
#            print msg.getAngleRoll()
384
        for msg in messages:
414
       
385
            print msg.getAngleRoll()
415