def arm_calibration(arm_motor, touch_sensor): """ Runs the arm up until the touch sensor is hit then back to the bottom again, beeping at both locations. Once back at in the bottom position, gripper open, set the absolute encoder position to 0. You are calibrated! The Snatch3r arm needs to move 14.2 revolutions to travel from the touch sensor to the open position. Type hints: :type arm_motor: ev3.MediumMotor :type touch_sensor: ev3.TouchSensor """ # TODO: 3. Implement the arm calibration movement by fixing the code below (it has many bugs). It should to this: # Command the arm_motor to run forever in the positive direction at max speed. # Create an infinite while loop that will block code execution until the touch sensor's is_pressed value is True. # Within that loop sleep for 0.01 to avoid running code too fast. # Once past the loop the touch sensor must be pressed. So stop the arm motor quickly using the brake stop action. # Make a beep sound # Now move the arm_motor 14.2 revolutions in the negative direction relative to the current location # Note the stop action and speed are already set correctly so we don't need to specify them again # Block code execution by waiting for the arm to finish running # Make a beep sound # Set the arm encoder position to 0 (the last line below is correct to do that, it's new so no bug there) # Code that attempts to do this task but has MANY bugs (nearly 1 on every line). Fix them! arm_motor.run_forever(speed_sp=MAX_SPEED) while not touch_sensor.is_pressed: time.sleep(0.01) arm_motor.stop(stop_action="brake") ev3.Sound().beep().wait() arm_revolutions_for_full_range = 14.2 degrees_for_full_range = arm_revolutions_for_full_range * 360 arm_motor.run_to_rel_pos(position_sp=(degrees_for_full_range * -1)) arm_motor.wait_while(ev3.Motor.STATE_RUNNING) ev3.Sound().beep().wait() arm_motor.position = 0 # Calibrate the down position as 0 (this line is correct as is).
def feel(done): ir = ev3.InfraredSensor(); assert ir.connected ts = ev3.TouchSensor(); assert ts.connected screen = ev3.Screen() sound = ev3.Sound() screen.draw.text((60,40), 'Going for a walk') screen.update() while ir.proximity > 30: if done.is_set(): break time.sleep(0.1) done.set() #this will set it running in a circle ev3.Leds.set_color(ev3.Leds.LEFT, ev3.Leds.RED) ev3.Leds.set_color(ev3.Leds.RIGHT, ev3.Leds.RED) screen.clear() screen.draw.text((60,20), 'There is something is front of me') screen.update() while not ts.is_pressed: sound.speak("Where should I go next?").wait() time.sleep(0.5) done.set() #will stop the circle dance
def arm_down(self): """Move arm down""" max_speed = 900 self.arm_motor.run_to_abs_pos(position_sp=0, speed_sp=max_speed) self.arm_motor.wait_while(ev3.Motor.STATE_RUNNING) self.arm_motor.stop(stop_action='brake') ev3.Sound().beep().wait()
def tacto(done): infra = ev3.InfraredSensor() assert infra.connected touch = ev3.TouchSensor() assert touch.connected screen = ev3.Screen() sound = ev3.Sound() screen.draw.text((60, 40), 'Caminando') screen.update() while infra.proximity > 30: if done.is_set(): break time.sleep(0.1) done.set() #lo detiene de su locura haha ev3.Leds.set_color(ev3.Leds.LEFT, ev3.Leds.RED) ev3.Leds.set_color(ev3.Leds.RIGHT, ev3.Leds.RED) screen.clear() screen.draw.text((60, 20), 'There is something is front of me') screen.update() while not touch_s.is_pressed: sound.speak("Where should i go next?").wait() time.sleep(0.5) done.set() #lo detiene de su locura haha
def __init__(self, left_port, right_port, kinematics, max_speed=700, flip_dir=False): self.left_motor = ev3.LargeMotor(left_port) self.right_motor = ev3.LargeMotor(right_port) self.sound = ev3.Sound() self.kinematics = kinematics try: self.sound.beep() self.gyro = ev3.GyroSensor() self.gyro.mode = 'GYRO-CAL' time.sleep(2) self.gyro.mode = 'GYRO-ANG' time.sleep(2) self.sound.beep() except: self.gyro = None print("Gyro not found") try: self.colorSensor = ev3.ColorSensor('in2') self.colorSensor.mode = 'COL-REFLECT' except: self.colorSensor = None print("Color sensor not found") try: self.left_push_sensor = ev3.TouchSensor('in3') except: self.left_push_sensor = None print("Left push sensor not found.") self.frontColorSensor = None try: self.right_push_sensor = ev3.TouchSensor('in1') except: self.right_push_sensor = None print("Right push sensor not found.") try: self.ultrasonicSensor = ev3.UltrasonicSensor() self.ultrasonicSensor.mode = 'US-DIST-CM' except: self.ultrasonicSensor = None print("Ultrasonic sensor not found") self.max_speed = max_speed self.flip_dir = flip_dir self.log = open("sensor.log", "w+")
def arm_down_to_drop_in_bucket(robot): """Move arm down almost all of the way""" max_speed = 900 arm_revolutions_for_half_range = 7.1 degrees_for_half_range = arm_revolutions_for_half_range * 360 robot.arm_motor.run_to_rel_pos(position_sp=degrees_for_half_range * -1, speed_sp=max_speed) robot.arm_motor.wait_while(ev3.Motor.STATE_RUNNING) robot.arm_motor.stop(stop_action='brake') ev3.Sound().beep().wait()
def alarm(self): print("[alarm] Alarming!") while (self.alarm_active): beep_args = "-r 30 -l 100 -f 1000" # Starts a new thread as the EV3's beep blocks the sleep and # disarming of the alarm threading.Thread( target=ev3.Sound().beep, args=(beep_args,) ).start() time.sleep(6) print("[alarm] Disarmed - Stopped Alarming") return
def try_connect(self): connection_attempts = 0 while (not(self.connected)): connection = self.client_connection.connect() if connection: self.connected = True self.update_server() ev3.Sound().speak("Ready to Deliver") else: self.connected = False connection_attempts += 1 if connection_attempts > 20: print("[try_connect] Tried 20 times - STOPPING!") return time.sleep(1)
def arm_down(arm_motor): """ Moves the Snatch3r arm to the down position. Type hints: :type arm_motor: ev3.MediumMotor """ # DONE: 5. Implement the arm up movement by fixing the code below # Move the arm to the absolute position_sp of 0 at max speed. # Wait until the move completes # Make a beep sound # Code that attempts to do this task but has bugs. Fix them. arm_motor.run_to_abs_pos(position_sp=-14.2, speed_sp=MAX_SPEED) arm_motor.wait_while( ev3.Motor.STATE_RUNNING) # Blocks until the motor finishes running ev3.Sound().beep().wait()
def arm_up(arm_motor, touch_sensor): """ Moves the Snatch3r arm to the up position. Type hints: :type arm_motor: ev3.MediumMotor :type touch_sensor: ev3.TouchSensor """ # DONE: 4. Implement the arm up movement by fixing the code below # Command the arm_motor to run forever in the positive direction at max speed. # Create a while loop that will block code execution until the touch sensor is pressed. # Within the loop sleep for 0.01 to avoid running code too fast. # Once past the loop the touch sensor must be pressed. Stop the arm motor using the brake stop action. # Make a beep sound # Code that attempts to do this task but has many bugs. Fix them! arm_motor.run_forever(position_sp=14.2, speed_sp=MAX_SPEED) while not touch_sensor.is_pressed: time.sleep(0.01) arm_motor.stop(stop_action="brake") ev3.Sound().beep().wait()
def __init__(self, mqtt_client, logger): # Create Planet and planet_name variable self.planet = Planet() self.planet_name = None # Setup Sensors, Motors and Odometry self.rm = ev3.LargeMotor("outB") self.lm = ev3.LargeMotor("outC") self.sound = ev3.Sound() self.odometry = Odometry(self.lm, self.rm) self.motors = Motors(self.odometry) self.cs = ColorSensor(self.motors) self.us = Ultrasonic() # Setup Communication self.communication = Communication(mqtt_client, logger, self) # Create variable to write to from communication self.start_location = None self.end_location = None self.path_choice = None self.running = True
def setup_hardware(self): self.motorR = ev3.LargeMotor("outD") self.motorL = ev3.LargeMotor("outB") self.motorPointer = ev3.LargeMotor("outC") self.colourSensorR = ev3.ColorSensor("in1") self.colourSensorL = ev3.ColorSensor("in4") self.sonarF = ev3.UltrasonicSensor("in2") if self.fast_hub: self.hub = SensorHubFast() else: self.hub = SensorHub() self.sonarR = HubSonar(self.hub, "s1") self.sonarL = HubSonar(self.hub, "s0") self.line_sensor = LineSensor(self.hub) self.button = ev3.Button() self.LED = ev3.Leds() # setup modes if appropriate self.colourSensorR.mode = "COL-COLOR" self.colourSensorL.mode = "COL-COLOR" self.sonarF.mode = "US-DIST-CM" self.motorR.stop_action = "hold" self.motorL.stop_action = "hold" self.sound = ev3.Sound() self.position_from_branch = 0
__author__ = 'kanehiro' import ev3dev.ev3 as ev3 from time import sleep btn = ev3.Button() sound = ev3.Sound() while not btn.backspace: if btn.enter: sound.speak("Enter") if btn.up: sound.speak("Up") if btn.down: sound.speak("Down") if btn.left: sound.speak("Left") if btn.right: sound.speak("Right") sleep(0.1)
import ev3dev.ev3 as ev3 ev3.Sound().speak('Hello World!')
def __init__(self): self.ev3_sound = ev3.Sound()
except: print("Failed to connect to server!") traceback.print_exc() if (self.run_robot): ev3.Sound.tone([(750, 250, 0), (750, 250, 0)]).wait() # TODO: add light to indicate status if __name__ == "__main__": run_robot = None if (len(sys.argv) > 1): mode_str = sys.argv[1] #TODO: clean this up if (mode_str == 'r' or mode_str == 'robot' and ev3_package_present == True): ev3.Sound().beep().wait() run_robot = True elif (mode_str == "t" or mode_str == "test"): print("Running client in test mode...") print(''.join(['-' for x in range(40)]) + '\n') run_robot = False else: print( 'Unable to determine mode! r/robot -> robot | t/test -> test') exit() else: if (ev3_package_check): #assume robot mode run_robot = True else: print(
#!/usr/bin/python3 # sound_and_speak_xx.py by Yasushi Honda 2019 1/3 #------------------------------------------------ import ev3dev.ev3 as ev3 import time import random import datetime if __name__=='__main__': p=ev3.LegoPort(ev3.INPUT_4) p.set_device='lego-nxt-sound' ss = ev3.SoundSensor(ev3.INPUT_4) ts=ev3.TouchSensor(ev3.INPUT_3) sp=ev3.Sound() sp.speak('Hi. I can speak the current time.').wait() talk=[] talk.append('Yes. I can hear you, but speak more loudly.') leds = ev3.Leds() leds.set_color(ev3.Leds.LEFT, ev3.Leds.GREEN,pct=1.0) leds.set_color(ev3.Leds.RIGHT, ev3.Leds.YELLOW,pct=1.0) print('[[ Push touch sensor to stop.]]') #print('[[ snd ]]') while ts.value()==0: snd=967-ss.value() #print("\r %4d" % snd, end='')