#!/usr/bin/python3 print("Please wait...") # Encourage patience :-) # http://www.inf.ed.ac.uk/teaching/courses/sdp/SDP2018/sdp_ev3.pdf import ev3dev.ev3 as ev3 import getch m1 = ev3.LargeMotor('outA') # front m2 = ev3.LargeMotor('outB') # right m3 = ev3.LargeMotor('outC') # back m4 = ev3.LargeMotor('outD') # left #s1=ev3.TouchSensor('in1') # left sensor #s2=ev3.TouchSensor('in2') # right sensor ult1 = ev3.UltrasonicSensor('in1') #Front-sensor ult2 = ev3.UltrasonicSensor('in2') #Right-sensor ult3 = ev3.UltrasonicSensor('in3') #Back-sensor ult4 = ev3.UltrasonicSensor('in4') #Left-sensor quit_moving = "Stop" # String to return if user decides to stop obj_detected = "Obstacle" # String to return if there is an object detected def moveBACKWARD(speed, time): m1.run_timed(speed_sp=-speed, time_sp=time) m3.run_timed(speed_sp=speed, time_sp=time) def moveFORWARD(speed, time): m1.run_timed(speed_sp=speed, time_sp=time)
def main(): print("--------------------------------------------") print("IR Remote") print(" - Use IR remote channel 1 to drive around") print(" - Use IR remote channel 2 to for the arm") print(" - Press the Back button on EV3 to exit") print("--------------------------------------------") ev3.Sound.speak("I R Remote") arm = ev3.MediumMotor(ev3.OUTPUT_A) assert arm.connected touch_sensor = ev3.TouchSensor() assert touch_sensor.connected left_motor = ev3.LargeMotor(ev3.OUTPUT_B) assert left_motor.connected right_motor = ev3.LargeMotor(ev3.OUTPUT_C) assert right_motor.connected ev3.Leds.all_off() # Turn the leds off robot = robo.Snatch3r() dc = DataContainer() # Done: 4. Add the necessary IR handler callbacks as per the instructions above. # Remote control channel 1 is for driving the crawler tracks around (none of these functions exist yet below). # Remote control channel 2 is for moving the arm up and down (all of these functions already exist below). # For our standard shutdown button. btn = ev3.Button() btn.on_backspace = lambda state: handle_shutdown(state, dc) robot.arm_calibration() # Start with an arm calibration in this program. def up_stuff(button_state, motor): if button_state: ev3.Sound.speak("I R Remote") ev3.Leds.set_color(ev3.Leds.LEFT, ev3.Leds.GREEN) motor.run_forever(speed_sp=600) else: ev3.Leds.set_color(ev3.Leds.LEFT, ev3.Leds.BLACK) motor.stop(stop_action='brake') def down_stuff(button_state, motor): if button_state: ev3.Leds.set_color(ev3.Leds.LEFT, ev3.Leds.RED) motor.run_forever(speed_sp=-600) else: ev3.Leds.set_color(ev3.Leds.LEFT, ev3.Leds.BLACK) motor.stop(stop_action='brake') def up_stuff2(button_state, motor): if button_state: ev3.Leds.set_color(ev3.Leds.RIGHT, ev3.Leds.GREEN) motor.run_forever(speed_sp=600) else: ev3.Leds.set_color(ev3.Leds.RIGHT, ev3.Leds.BLACK) motor.stop(stop_action='brake') def down_stuff2(button_state, motor): if button_state: ev3.Leds.set_color(ev3.Leds.RIGHT, ev3.Leds.RED) motor.run_forever(speed_sp=-600) else: ev3.Leds.set_color(ev3.Leds.RIGHT, ev3.Leds.BLACK) motor.stop(stop_action='brake') ir1 = ev3.RemoteControl(channel=1) ir1.on_red_up = lambda state: up_stuff(state, left_motor) ir1.on_red_down = lambda state: down_stuff(state, left_motor) ir1.on_blue_up = lambda state: up_stuff2(state, right_motor) ir1.on_blue_down = lambda state: down_stuff2(state, right_motor) ir2 = ev3.RemoteControl(channel=2) ir2.on_red_up = lambda state: handle_arm_up_button(state, robot) ir2.on_red_down = lambda state: handle_arm_down_button(state, robot) ir2.on_blue_up = lambda state: handle_calibrate_button(state, robot) btn.on_backspace = lambda state: handle_shutdown(state, dc) while dc.running: # TODO: 5. Process the RemoteControl objects. ir1.process() ir2.process() btn.process() time.sleep(0.01) # Done: 2. Have everyone talk about this problem together then pick one member to modify libs/robot_controller.py # as necessary to implement the method below as per the instructions in the opening doc string. Once the code has # been tested and shown to work, then have that person commit their work. All other team members need to do a # VCS --> Update project... # Once the library is implemented any team member should be able to run his code as stated in todo3. robot.shutdown()
# -*- coding: utf-8 -*- """ Created on Tue Oct 2 13:10:48 2018 @author: coren """ import ev3dev.ev3 as ev3 import signal #from time import sleep #TEMP///////////////////// # Connect two motors mAleft = ev3.LargeMotor('outA') mBright = ev3.LargeMotor('outB') mCFence = ev3.MediumMotor('outC') #input, light sensors and gyro sensor lightSensorLeft1 = ev3.ColorSensor('in1') lightSensorRight2 = ev3.ColorSensor('in4') gyro = ev3.GyroSensor('in2') Sonar = ev3.UltrasonicSensor('in3') # Put the US sensor into distance mode. Sonar.mode = 'US-DIST-CM' units = Sonar.units # reports 'cm' even though the sensor measures 'mm' # Check if the sensors are connected assert lightSensorLeft1.connected, "LightSensorLeft(ColorSensor) is not connected" assert lightSensorRight2.connected, "LightSensorRight(LightSensor) is not conected" # Constantes
print("Initializing") from ev3dev import ev3 sensor = ev3.UltrasonicSensor() stopbutton = ev3.TouchSensor() left = ev3.LargeMotor('outC') right = ev3.LargeMotor('outB') flippyboi = ev3.MediumMotor('outA') sensor.mode = sensor.MODE_US_DIST_IN lights = ev3.Leds() print("Initialized! Press enter to start fighting") input("Press enter") while True: distance = sensor.distance_inches if distance < 6: print("Robot detected, ATTACKING!") lights.red_left lights.red_right right.run_forever(speed_sp=-900) left.run_forever(speed_sp=-900) flippyboi.run_to_rel_pos(speed_sp=1000, position_sp=-1) flippyboi.run_to_rel_pos(speed_sp=1000, position_sp=1) else: print("No robot detected, spinning") lights.set_color(lights.LEFT, lights.ORANGE) lights.set_color(lights.RIGHT, lights.ORANGE) right.run_forever(speed_sp=900) left.run_forever(speed_sp=-900) if stopbutton.is_pressed:
import time import robot_controller as robo # Note that todo2 is farther down in the code. That method needs to be written before you do todo3. # DONE: 3. Have someone on your team run this program on the EV3 and make sure everyone understands the code. # Can you see what the robot does and explain what each line of code is doing? Talk as a group to make sure. class DataContainer(object): """ Helper class that might be useful to communicate between different callbacks.""" def __init__(self): self.running = True left_motor = ev3.LargeMotor(ev3.OUTPUT_B) right_motor = ev3.LargeMotor(ev3.OUTPUT_C) assert left_motor.connected assert right_motor.connected def main(): print("--------------------------------------------") print("IR Remote") print(" - Use IR remote channel 1 to drive around") print(" - Use IR remote channel 2 to for the arm") print(" - Press the Back button on EV3 to exit") print("--------------------------------------------") ev3.Sound.speak("I R Remote") ev3.Leds.all_off() # Turn the leds off
def __init__(self): self.speed = 100 self.btn = ev3.Button() self.motor_left = ev3.LargeMotor('outA') self.motor_right = ev3.LargeMotor('outD')
#!/usr/bin/env python3 import ev3dev.ev3 as ev3 import time m_l = ev3.LargeMotor('outA') m_r = ev3.LargeMotor('outD') m_l.run_timed(time_sp=2000, speed_sp=500) m_r.run_timed(time_sp=2000, speed_sp=500) m_l.stop() m_r.stop() #25cm nach Vorne gefahren m_r.run_timed(time_sp=1000, speed_sp=500) m_r.stop() #90° turn left m_l.run_timed(time_sp=2000, speed_sp=500) m_r.run_timed(time_sp=2000, speed_sp=500) m_l.stop() m_r.stop() #25cm nach links gefahren (Ecke links unten) m_l.run_timed(time_sp=1000, speed_sp=500) m_l.stop() #90° trun right (untenlinks) m_l.run_timed(time_sp=4000, speed_sp=500) m_r.run_timed(time_sp=4000, speed_sp=500) m_l.stop() m_r.stop() #50cm gefahren nach oben (Ecke oben links) m_l.run_timed(time_sp=1000, speed_sp=500) m_l.stop() #90° trun right (obenlinks)
#!/usr/bin/env python3 import ev3dev.ev3 as ev3 rightMotor = ev3.LargeMotor('outC') # The motor connected to the right wheel leftMotor = ev3.LargeMotor('outB') # The motor connected to the left wheel button = ev3.Button() # Any button camera = ev3.Sensor(address=ev3.INPUT_1) # The camera assert camera.connected, "Connect a color sensor to any sensor port" CAMERA_WIDTH_PIXELS = 255 CAMERA_HEIGHT_PIXELS = 255 camera.mode = 'SIG1' def follow_object(kp, kd): #P-control objCount = camera.value(0) prevEr = 0 while (not button.any()): objCount = camera.value( 0) # get the number of objects seen by the camera if (objCount > 0): # if we've seen at least one object # get the position and dimensions of the largest object seen x = camera.value(1) # x coordinate of middle of largest object y = camera.value(2) # y coordinate of middle of largest object w = camera.value(3) # width of largest object h = camera.value(4) # height of largest object
from ev3dev import ev3 from odometry import Odometry from math import pi odometry = Odometry(ev3.LargeMotor("outB"), ev3.LargeMotor("outC"), 6.0, 2.7, 6.0, 2 * pi / 5.0) odometry.drive_to(-30.0, 0.0, 0) odometry.drive_to(-30.0, 30.0, 0) odometry.drive_to(-60.0, 60.0, pi)
""" #象の足を動かす motor_left = ev3.LargeMotor('outA') motor_left.run_forever(speed_sp=500) time.sleep(3) motor_left.stop(stop_action='brake') """ #自己紹介文をしゃべる speakSFC() #入力受付スレッドを開始 thread1 = threading.Thread(target=quit_input) thread1.start() #タッチセンサの指定 ts1 = ev3.TouchSensor('in1') #象の鼻を下方向に動かす motor_left = ev3.LargeMotor('outB') t0 = time.time() #motor_left.set_speed_sp(motor_left.count_per_rot; print(motor_left.count_per_rot) minPos = 30 maxPos = 700 musicPos = -500 #motor_left.run_to_abs_pos(position_sp=90, speed_sp=500, stop_action='break') motor_left.run_to_abs_pos(position_sp=minPos, speed_sp=100, stop_action='brake') #ループをカウント count = 0 while (time.time() - t0 < 30): if (flag_quit): break
true = 1 #function to ensure the motor has stopped before moving on def waitformotor(motor): xxx = 0 while motor.state != []: xxx = 0 # define motors and use brake mode col = ev3.ColorSensor() paper = ev3.MediumMotor('outA') pen1 = ev3.LargeMotor('outB') pen2 = "" head = ev3.MediumMotor('outC') pen1.stop_action = "brake" head.stop_action = "brake" paper.stop_action = "brake" head.reset() pen1.reset() paper.reset() #move paper until color sensor recieves >50 reading #paper.speed_regulation_enabled=u'on' pen1.run_to_rel_pos(speed_sp=-400, position_sp=-53) waitformotor(pen1)
# -*- coding: utf-8 -*- from ev3dev.ev3 import * import ev3dev.ev3 as ev3 from time import sleep from threading import Thread from time import sleep import threading from math import sqrt import sys cor = ev3.ColorSensor() assert cor.connected cor.mode = 'COL-COLOR' # intensidade da luz # motors me = ev3.LargeMotor('outB') assert me.connected # motor esquerdo md = ev3.LargeMotor('outC') assert md.connected # motor direito lcd = Screen() smile = True class Jogo: def __init__(self): self.lista_inicial = ["1:3,5", "2:3,3", "3:5,3", "4:5,5", "5:2,3"] self.cores = ('unknown', 'black', 'blue', 'green', 'yellow', 'red', 'white', 'brown') def tela():
import ev3dev.ev3 as ev3 import time wheel1 = ev3.LargeMotor('outA') wheel2 = ev3.LargeMotor('outD') #s = int(input("Speed: ")) timeRotation = 300 timeMoving = 1000 speedRotation = -50 speedMoving = -200 while True: k = input() if (k == 'w'): wheel1.run_timed(speed_sp=-speedMoving, time_sp=timeMoving) wheel2.run_timed(speed_sp=-speedMoving, time_sp=timeMoving) elif (k == 's'): wheel1.run_timed(speed_sp=speedMoving, time_sp=timeMoving) wheel2.run_timed(speed_sp=speedMoving, time_sp=timeMoving) elif (k == 'a'): wheel1.run_timed(speed_sp=-speedRotation, time_sp=timeRotation) wheel2.run_timed(speed_sp=speedRotation, time_sp=timeRotation) elif (k == 'd'): wheel1.run_timed(speed_sp=speedRotation, time_sp=timeRotation) wheel2.run_timed(speed_sp=-speedRotation, time_sp=timeRotation)
#!/usr/bin/env python3 '''Hello to the world from ev3dev.org''' import os import sys import time import ev3dev.ev3 as ev3 # state constants ON = True OFF = False leftWheel = ev3.LargeMotor('outA') rightWheel = ev3.LargeMotor('outC') gyro = ev3.GyroSensor() color = ev3.ColorSensor() units = gyro.units def debug_print(*args, **kwargs): '''Print debug messages to stderr. This shows up in the output panel in VS Code. ''' print(*args, **kwargs, file=sys.stderr) def reset_console(): '''Resets the console to the default state''' print('\x1Bc', end='')
gyro = ev3.GyroSensor() gyro.mode = 'GYRO-ANG' us = ev3.UltrasonicSensor() ir = ev3.InfraredSensor('in4') ir4 = True #geeft aan of de IR-sensor op poort 4 aangesloten is. try: us.mode = 'US-DIST-CM' ir.mode = 'IR-PROX' except Exception: ir = ev3.InfraredSensor('in3') ir4 = False us.mode = 'US-DIST-CM' ir.mode = 'IR-PROX' motorleft = ev3.LargeMotor('outB') motorright = ev3.LargeMotor('outC') motorir = ev3.MediumMotor('outA') step = 10 def debug_print(*args, **kwargs): print(*args, **kwargs, file=sys.stderr) def irvalue(): if ir4: return ir.value() else: return us.value()
#!/usr/bin/env python3 import ev3dev.ev3 as ev3 from time import sleep M_DIREITO_SENSOR = ev3.MediumMotor('outA') M_ESQUERDO_SENSOR = ev3.MediumMotor('outB') M_ESQUERDO = ev3.LargeMotor('outC') M_DIREITO = ev3.LargeMotor('outD') CL = ev3.ColorSensor('in1') CL.mode = 'COL-COLOR' PROX1 = ev3.InfraredSensor('in2') # DIREITA PROX2 = ev3.InfraredSensor('in3') # ESQUERDA PROX1.mode = 'IR-PROX' PROX2.mode = 'IR-PROX' GYRO = ev3.GyroSensor('in4') GYRO.mode = 'TILT-ANG' log = open("log.txt", "w") VARIACAO_SENSOR = 15 DISTANCIA_BONECOS = 35 VELOCIDADE_CURVA = 300 VELOCIDADE_ATUAL = 400 KP = 1.5 VERDE = 3 VERMELHO = 5 AZUL = 2 PRETO = 1 lista_valores = [0, 0, 0] # indice 0 - VERMELHO, indice 1 - VERDE, indice 2 - AZUL cor_caminho = ["", ""]
import time, termios, tty, sys import ev3dev.ev3 as ev3 from time import sleep import serial motor_right_A = ev3.LargeMotor('outA') motor_right_B = ev3.LargeMotor('outB') speed = [50, 0, 0] # Set Speed gearA = [0] gearB = [0] i = 50 n = 50 def getch(): fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(sys.stdin.fileno()) ch = sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) return ch def forward(): motor_right_A.run_direct(duty_cycle_sp=speed[gearA[0]]) motor_right_B.run_direct(duty_cycle_sp=speed[gearB[0]])
def __init__(self, port): # port must be 'B' or 'C' for left/right wheels self._motor = ev3.LargeMotor('out' + port)
def run(self): # sensors cs = ev3.ColorSensor() assert cs.connected # measures light intensity us = ev3.UltrasonicSensor() assert us.connected # measures distance cs.mode = 'COL-REFLECT' # measure light intensity us.mode = 'US-DIST-CM' # measure distance in cm # motors lm = ev3.LargeMotor('outB') assert lm.connected # left motor rm = ev3.LargeMotor('outC') assert rm.connected # right motor mm = ev3.MediumMotor('outD') assert mm.connected # medium motor speed = 360 # deg/sec, [-1000, 1000] dt = 500 # milliseconds stop_action = "coast" # PID tuning Kp = 1 # proportional gain Ki = 0 # integral gain Kd = 0 # derivative gain integral = 0 previous_error = 0 # initial measurment target_value = cs.value() # Start the main loop while not self.shut_down: # deal with obstacles distance = us.value() // 10 # convert mm to cm if distance <= 5: # sweep away the obstacle mm.run_timed(time_sp=600, speed_sp=+150, stop_action="hold").wait() mm.run_timed(time_sp=600, speed_sp=-150, stop_action="hold").wait() # Calculate steering using PID algorithm error = target_value - cs.value() integral += (error * dt) derivative = (error - previous_error) / dt # u zero: on target, drive forward # u positive: too bright, turn right # u negative: too dark, turn left u = (Kp * error) + (Ki * integral) + (Kd * derivative) # limit u to safe values: [-1000, 1000] deg/sec if speed + abs(u) > 1000: if u >= 0: u = 1000 - speed else: u = speed - 1000 # run motors if u >= 0: lm.run_timed(time_sp=dt, speed_sp=speed + u, stop_action=stop_action) rm.run_timed(time_sp=dt, speed_sp=speed - u, stop_action=stop_action) sleep(dt / 1000) else: lm.run_timed(time_sp=dt, speed_sp=speed - u, stop_action=stop_action) rm.run_timed(time_sp=dt, speed_sp=speed + u, stop_action=stop_action) sleep(dt / 1000) previous_error = error # Check if buttons pressed (for pause or stop) if not self.btn.down: # Stop print("Exit program... ") self.shut_down = True elif not self.btn.left: # Pause print("[Pause]") self.pause()
#!/usr/bin/python3.4 import ev3dev.ev3 as ev3 from time import sleep import signal btn = ev3.Button() mA = ev3.LargeMotor('outA') mB = ev3.LargeMotor('outB') THRESHOLD_LEFT = 30 THRESHOLD_RIGHT = 350 BASE_SPEED = 30 TURN_SPEED = 80 #lightSensorLeft = ev3.ColorSensor('in1') #lightSensorRight = ev3.LightSensor('in2') TouchSensor = ev3.TouchSensor('in3') #assert lightSensorLeft.connected, "LightSensorLeft(ColorSensor) is not connected" #assert lightSensorRight.connected, "LightSensorRight(LightSensor) is not conected" assert TouchSensor.connected, "Touch sensor is not connected" mB.run_direct() mA.run_direct()
import ev3dev.ev3 as ev3 # motors spinner = ev3.MediumMotor(ev3.OUTPUT_C) hammer = ev3.LargeMotor(ev3.OUTPUT_D) # hammer swings down until it hits something # then swings back up until def swing_hammer(speed_down, speed_up): hammer.reset() hammer.run_forever(speed_sp=speed_down) hammer.wait_until_not_moving() hammer.reset() hammer.run_forever(speed_sp=-speed_up) hammer.wait_until_not_moving() hammer.stop() # start and stop rear weapon def enable_spinner(speed): spinner.run_forever(speed_sp=speed) def disable_spinner(): spinner.stop() def stop(): spinner.stop(), hammer.stop()
import ev3dev.ev3 as ev3 import time # motors l_side = ev3.LargeMotor(ev3.OUTPUT_A) r_side = ev3.LargeMotor(ev3.OUTPUT_B) # checks if motors are still spinning def running(): if (l_side.state == 'running', r_side.state == 'running'): return True return False # abstract functions # make wheels wait def wait(duration): if (duration <= 0): # wait until both wheels stuck l_side.wait_until_not_moving(), r_side.wait_until_not_moving() stop() elif (time > 0): # wait until timer ends l_side.wait(time), r_side.wait(time) stop() def stop():
''' GREEN ENABLED ''' #!/usr/local/bin/python3 import ev3dev.ev3 as ev3 import time # Connect Motors motorL = ev3.LargeMotor('outD') assert motorL.connected, "Error while connecting left LargeMotor" motorR = ev3.LargeMotor('outA') assert motorR.connected, "Error while connecting right LargeMotor" # Connect color sensors colSensorL = ev3.ColorSensor('in4') assert colSensorL.connected, "Error while connecting left ColorSensor" colSensorR = ev3.ColorSensor('in1') assert colSensorR.connected, "Error while connecting right ColorSensor" ''' # Connect pixy cam and set mode pixy = ev3.Sensor('in2') assert pixy.connected, "Error while connecting Pixy camera" pixy.mode = 'SIG1' ''' # Constants KP = 0.5 # Proportional constant KI = 0.01 # Integral constant KD = 0.005 # Derivative constant GAIN = 10 # Gain for motorspeed BASE_SPEED = 200 # Base speed # PID variables
def handle_move_right_forward(button_state, robot): robot.right_motor = ev3.LargeMotor(ev3.OUTPUT_C) if button_state: robot.right_motor.run_forever(speed_sp=900) else: robot.right_motor.stop()
import ev3dev.ev3 as ev3 import time m1 = ev3.LargeMotor('outA') m2 = ev3.LargeMotor('outD') go = 0 turn = 0 while True: direction = input() # The recommended speed range is from -900 to 900 if (direction == 'w' and go < 9): go = go + 1 elif (direction == 's' and go > -9): go = go - 1 elif (direction == 'a' and turn != -1): turn = turn - 1 elif (direction == 'd' and turn != 1): turn = turn + 1 elif (direction == 'x'): m1.stop() m2.stop() go = 0 turn = 0 if (turn == 0): m1.run_forever(speed_sp=go * 100) m2.run_forever(speed_sp=go * 100) elif (turn == -1): m1.run_forever(speed_sp=-400)
def handle_move_left_back(button_state, robot): robot.left_motor = ev3.LargeMotor(ev3.OUTPUT_B) if button_state: robot.left_motor.run_forever(speed_sp=-900) else: robot.left_motor.stop()
def main(): print("--------------------------------------------") print("Running Snatch3r IR hardware test program") print(" - Use IR remote channel 1 to drive around") print(" - Use IR remote channel 2 to for the arm") print(" - Press backspace button on EV3 to exit") print("--------------------------------------------") ev3.Leds.all_off() # Turn the leds off # Connect two large motors on output ports B and C and medium motor on A left_motor = ev3.LargeMotor(ev3.OUTPUT_B) right_motor = ev3.LargeMotor(ev3.OUTPUT_C) arm_motor = ev3.MediumMotor(ev3.OUTPUT_A) # Check that the motors are actually connected assert left_motor.connected assert right_motor.connected assert arm_motor.connected # Only using 1 sensor in this program touch_sensor = ev3.TouchSensor() # address=in1 assert touch_sensor # Remote control channel 1 is for driving the crawler tracks around. rc1 = ev3.RemoteControl(channel=1) assert rc1.connected rc1.on_red_up = lambda state: handle_ir_move_button( state, left_motor, ev3.Leds.LEFT, 1) rc1.on_red_down = lambda state: handle_ir_move_button( state, left_motor, ev3.Leds.LEFT, -1) rc1.on_blue_up = lambda state: handle_ir_move_button( state, right_motor, ev3.Leds.RIGHT, 1) rc1.on_blue_down = lambda state: handle_ir_move_button( state, right_motor, ev3.Leds.RIGHT, -1) # Remote control channel 2 is for moving the arm up and down. rc2 = ev3.RemoteControl(channel=2) assert rc2.connected rc2.on_red_up = lambda state: handle_arm_up_button(state, arm_motor, touch_sensor) rc2.on_red_down = lambda state: handle_arm_down_button(state, arm_motor) rc2.on_blue_up = lambda state: handle_calibrate_button( state, arm_motor, touch_sensor) # Allows testing of the arm without the IR remote btn = ev3.Button() btn.on_up = lambda state: handle_arm_up_button(state, arm_motor, touch_sensor) btn.on_down = lambda state: handle_arm_down_button(state, arm_motor) btn.on_left = lambda state: handle_calibrate_button( state, arm_motor, touch_sensor) btn.on_right = lambda state: handle_calibrate_button( state, arm_motor, touch_sensor) btn.on_backspace = lambda state: handle_shutdown(state) ev3.Sound.speak("Ready") arm_calibration(arm_motor, touch_sensor) while True: rc1.process() rc2.process() btn.process() time.sleep(0.01)
from ev3dev.auto import * import ev3dev.ev3 as ev3 import time typeMotor = ["LargeMotor", "MiddleMotor"] whatMotor = ["black", "blue"] tM = 0 wM = 0 power = 40 cycles = 1000 fileName = "data%s_%s_%dpwr_%dsec.txt" % (typeMotor[tM], whatMotor[wM], power, cycles) fout = open(fileName, "w") m = ev3.LargeMotor(ev3.OUTPUT_A) m.reset() m.duty_cycle_sp = power m.run_forever() t_start = time.time() for i in range(0, cycles): t = time.time() - t_start angle = m.position line = '%f\t%d\n' % (t, angle) fout.write(line) time.sleep(0.0005) fout.close()
def __init__(self, port, motor_type='wheel'): # port must be 'A', 'B', 'C', or 'D'. Use 'arm' as motor_type for Arm. if motor_type == 'wheel': self._motor = ev3.LargeMotor('out' + port) else: self._motor = ev3.MediumMotor('out' + port)
#!/usr/bin/env python3 import ev3dev.ev3 as ev3 import time ev3.Sound.beep().wait() m = ev3.LargeMotor('outA') ts1 = ev3.TouchSensor('in1') while True: if ts1.value() == 0: m.stop(stop_action="brake") else: m.run_forever(speed_sp=180) # equivalent to power=20 in EV3-G