def GetData(): BFRMR1serialport.sendserial([255, 255, GETDATA, 0, 0, 0, 0, 0]) # send command to get sensor data from robot while True: a = BFRMR1serialport.getserial(10) # wait here until data is received to confirm command complete if a is not None: break return a # return data packet
def RobotMove(direction, encodercount, speed, SonarThreshold, IRThreshold): # 3.4 degrees = 1 encoder count for a turn BFRMR1serialport.sendserial( [255, 255, direction, encodercount, speed, SonarThreshold, IRThreshold, 0] ) # send command to move head while True: a = BFRMR1serialport.getserial(10) # wait here until data is received to confirm command complete if a is not None: break return a # return data packet
def SonarScan(Tilt, StartAngle, EndAngle, Steps, Speed): print "Sonar Scan" ServoStart = int(128 - (StartAngle * 1.45)) # convert from angle to value between 0 and 255 ServoEnd = int(128 - (EndAngle * 1.45)) # convert from angle to value between 0 and 255 ServoTilt = int(128 + (Tilt * 1.45)) # convert from angle to value between 0 and 255 BFRMR1serialport.sendserial( [255, 255, SONARSCAN, ServoTilt, ServoStart, ServoEnd, Steps, Speed] ) # send command to start sonar scan while True: a = BFRMR1serialport.getserial(Steps + 2) # wait here until data is received to confirm command complete if a is not None: break return a # return data packet
def HeadMove(pan, tilt, speed): panservovalue = int(128 - (pan * 1.45)) # convert from angle to value between 0 and 255 tiltservovalue = int(128 + (tilt * 1.45)) if speed <= 10: BFRMR1serialport.sendserial( [255, 255, HEADMOVE, panservovalue, tiltservovalue, speed, 0, 0] ) # send command to move head while True: a = BFRMR1serialport.getserial(10) # wait here until data is received to confirm command complete if a is not None: break return a # return data packet else: print "Speed out of range. Value should be between 0 and 10"