def __init__(self): Debug.print("Initialize statemachine") self.states = {} self.transitions = {} self.currentState = None self.trans = None
def __init__(self): self.pid = PIDController(kP=1.0, kI=0.0, kD=0.1) # motors try: self.steerPair = MoveSteering(OUTPUT_B, OUTPUT_C) except ev3dev2.DeviceNotFound as e: Debug.print("Error:", e) self.speed = Config.data['pid']['fast']['speed_max']
def main(): nchan = NekoNekoChan() # create object instance of robot nchan.sound.tone([(1000, 200, 0), (1200, 150, 0)]) while not nchan.btn.any(): sleep(0.1) nchan.sound.beep() sleep(1) Debug.print('no calibration') while not nchan.btn.any(): Debug.print(nchan.sensColor.rgb) sleep(1) sleep(1) Debug.print('please calibrate') while not nchan.btn.any(): sleep(0.1) sleep(1) nchan.sensColor.calibrate_white() Debug.print('calibrated') while not nchan.btn.any(): Debug.print(nchan.sensColor.rgb) sleep(1) nchan.sound.tone([(1200, 150, 0), (1000, 200, 0)])
def firstTurn(self, sensorValues): Debug.print("Robo at Cross first Turn")
if action == "right": right() elif action == "left": left() elif action == "skip": self.steerPair.on_for_degrees( 0, -20, 50) # back off until centered on cross self.steerPair.wait_until_not_moving(2000) left() else: raise AttributeError("no valid action string given for turn()") def brake(self): self.steerPair.off() # module test if __name__ == "__main__": Debug.print("Drive Module Test") Debug.print("=" * 40) Debug.deltaTime("Modules loaded") drive = Drive() Debug.deltaTime("init drive object") Config.update() for i in range(-5, 5): drive.pid.update(i * 10) sleep(0.03) Debug.print(drive.pid.output)
#!/usr/bin/env python3 from ev3dev2.sensor.lego import ColorSensor from ev3dev2.sensor import INPUT_1 from ev3dev2.sound import Sound from toolbox import Config, Debug from time import sleep Debug.print('Hello, i am connected') Config.update() sound = Sound() Debug.print("JSON Version:", Config.data["version"]) color = ColorSensor() color.calibrate_white() while True: Debug.print(color.hls) hue = color.hls[0] if hue > 0.4 and hue < 0.68: sound.speak("dah be dee, dah be dye") sleep(1) elif hue > 0.8 or hue < 0.2: sound.speak("red") sleep(1) elif hue > 0.65: sound.speak("white") sleep(1)
defaultDistance = sensIR.proximity while sensIR.proximity > defaultDistance * 0.9: # follow line pass # search ball while True: # debug_print('Abstand: {}'.format(sensIR.proximity * 0.7)) # sleep(0.5) sleep(1) while True: if not myClaw.closed and sensTouch.is_pressed: myClaw.closeClaw() Debug.print('{}: Closed'.format(time())) sound.beep() elif btn.up: myClaw.releaseClaw() Debug.print('{}: Released'.format(time())) sound.beep() elif btn.enter: break elif btn.down: Debug.print(myClaw.closed) sleep(0.02)
def setState(self, stateName): self.currentState = self.states[stateName] Debug.print("State changed to: " + stateName)