def detect_object(self): newL = robohat.irLeft() newR = robohat.irRight() if (newL != self.lastL) or (newR != self.lastR): robohat.turnReverse(40, 40) time.sleep(0.7) robohat.spinRight(70) time.sleep(0.4) robohat.turnForward(20, 20) else: pass
def updateMotors(self): Y_axis = self.yValue X_axis = self.xValue r_speed, l_speed = self.joystickToDiff(X_axis, -Y_axis, -1, 1, -100, 100) #print("Left: " + str(l_speed) + ", Right: " + str(r_speed)) if Y_axis < 0: if X_axis > 0: if r_speed < 0: r_speed = 20.0 else: r_speed = r_speed + 20 r_speed = min(100, r_speed) robohat.turnForward(l_speed, r_speed) elif X_axis < 0: if l_speed < 0: l_speed = 20.0 else: l_speed = l_speed + 20 l_speed = min(100, l_speed) robohat.turnForward(l_speed, r_speed) else: robohat.turnForward(l_speed, r_speed) elif Y_axis > 0: if X_axis > 0: r_speed = -r_speed if l_speed < 0: l_speed = -l_speed + 20 l_speed = min(100, l_speed) else: l_speed = 20.0 robohat.turnReverse(l_speed, r_speed) elif X_axis < 0: l_speed = -l_speed if r_speed < 0: r_speed = -r_speed + 20 r_speed = max(20, r_speed) else: r_speed = 20.0 robohat.turnReverse(l_speed, r_speed) else: r_speed = -r_speed l_speed = -l_speed robohat.turnReverse(l_speed, r_speed) else: if X_axis > 0: pass robohat.spinRight(abs(l_speed)) elif X_axis < 0: pass robohat.spinLeft(abs(r_speed)) else: robohat.stop()
if keyp == 'w' or ord(keyp) == 16: robohat.forward(speed) print 'Forward', speed elif keyp == 'z' or ord(keyp) == 17: robohat.reverse(speed) print 'Reverse', speed elif keyp == 's' or ord(keyp) == 18: robohat.spinRight(speed) print 'Spin Right', speed elif keyp == 'a' or ord(keyp) == 19: robohat.spinLeft(speed) print 'Spin Left', speed elif keyp == '.' or keyp == '>': speed = min(100, speed + 10) elif keyp == 'p': robohat.turnForward(100, 30) print 'Speed+', speed elif keyp == '8': robohat.turnForward(100, 30) while True: robohat.turnForward(30, 100) print 'Speed+', speed elif keyp == 'o': robohat.turnForward(30, 100) print 'Speed+', speed elif keyp == ',' or keyp == '<': speed = max(0, speed - 10) print 'Speed-', speed elif keyp == ' ': robohat.stop() print 'Stop'
def autonomous(self, vs): robohat.turnForward(20, 20) self.pan_and_tilt(vs)
robohat.spinLeft(speed) myo.rotSetCenter() elif p == p.FINGERS_SPREAD: #print("Reverse") robohat.reverse(speed) myo.rotSetCenter() ======= print("Rest") robohat.stop() myo.rotSetCenter() #robohat.cleanup() if p == p.FIST: print("Fist") if myo.getBox() == 7: print("Turn Left") robohat.turnForward(0, speed) elif myo.getBox() == 3: print("Turn Right") robohat.turnForward(speed, 0) else: print("forward") robohat.forward(speed) if p == p.WAVE_OUT: print("Spin Right") robohat.spinRight(speed) myo.rotSetCenter() if p == p.WAVE_IN: print("Spin Left") robohat.spinLeft(speed) myo.rotSetCenter() if p == p.FINGERS_SPREAD: