示例#1
0
class Robot:
    def __init__(self,leftMotor,rightMotor,lightSensor,gyroSensor):
        self.drivebase = DriveBase(left,rightMotor,56,105)
        self.lightSensor = lightSensor

    def driveForward(self,time):
        self.drivebase.drive_time(300,0,time*100)

    def driveTillBlack(self,speed)
from pybricks.hubs import EV3Brick
from pybricks.ev3devices import Motor
from pybricks.parameters import Port, Stop, Direction, Button, Color
from pybricks.tools import wait, StopWatch, DataLog
from pybricks.robotics import DriveBase

# SETUP SECTION
# Initialize the EV3 Brick.

# We'll call  "brick" every time we want the brick to do something
brick = EV3Brick()

brick.speaker.beep()
# Initialize the motors.
left_motor = Motor(Port.B)
right_motor = Motor(Port.C)

# Initialize the drive base.
# The DriveBase function will set up the driving mechanic to move both wheels together
# We just need to say which motors we want to use as well as the wheels and the axle track
# We'll call "robot" every time we want the robot to move
robot = DriveBase(left_motor, right_motor, wheel_diameter=56, axle_track=114)

# START ROBOT SECTION
# Now that we're all set up, let's tell the robot what to do!
# Let's make it beep, wait 2 seconds, and then beep again so we know it's ready
wait(100)
brick.speaker.beep()

robot.drive_time(1000)
robot.straight(999999)
示例#3
0
#!/usr/bin/env pybricks-micropython

from pybricks import ev3brick as brick
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                 InfraredSensor, UltrasonicSensor, GyroSensor)
from pybricks.parameters import (Port, Stop, Direction, Button, Color,
                                 SoundFile, ImageFile, Align)
from pybricks.tools import print, wait, StopWatch
from pybricks.robotics import DriveBase

# Write your program here
brick.sound.beep()

left = Motor(Port.B)
right = Motor(Port.C)
robot = DriveBase(left, right, 56, 114)

while True:
    robot.drive_time(500, 0, 10000)
    robot.drive_time(500, 90, 5000)
    robot.drive_time(500, 90, 4000)
    robot.drive_time(500, 90, 5000)
    robot.drive_time(500, -90, 5000)
示例#4
0
class Robot:
	def __init__(self):
		# micro controller
		ev3 = EV3Brick()
		ev3.speaker.beep()
		# sensors
		# low value = registers black tape
		# high value = aluminum
		self.sensorYellow = ColorSensor(Port.S1)
		self.sensorRed = ColorSensor(Port.S3)
		self.sensorBlue = ColorSensor(Port.S2)
		# motor
		left_motor = Motor(Port.A, gears=[40, 24])
		right_motor = Motor(Port.B, gears=[40, 24])
		axle_track = 205
		wheel_diameter = 35
		self.motors = DriveBase(left_motor, right_motor,
														wheel_diameter, axle_track)
		# constants

		# intersection detection of side sensors
		self.thresholdBlueSensor = 30

		# value for making turns
		self.thresholdSideSensors = 15

		# timer

		self.watch = StopWatch()
		self.timer = 0

	def drive(self, directions):
		i = 0
		while i < len(directions):
			self.timer = self.watch.time()
			if self.timer % 100 == 0:
				print(self.timer)
			self.correctPath()

			if self.senseIntersection() == True and self.timer >= 500:
				print('intersection')
				self.motors.drive_time(0, 0, 1000) # reduce this when done
				self.executeCommand(directions[i])
				i += 1

			self.motors.drive(-125, 0)


	def executeCommand(self, cmd):
		if cmd == 0:
			print('straight')
			self.driveStraight()

		if cmd == 1:
			print('right')
			self.turnRight()

		if cmd == 2:
			print('left')
			self.turnLeft()

		if cmd == 3:
			print('reverse')
			self.reverse()

		if cmd == 4:
			print('stop')

	# turning behaviours at intersection

	def turnLeft(self):
		self.motors.drive_time(-30, 44, 2000)
		self.watch.reset()

	def turnRight(self):
		self.motors.drive_time(-30, -46, 2000)
		self.watch.reset()

	def driveStraight(self):
		self.motors.drive_time(-60, 0, 1800)
		self.watch.reset()

	def reverse(self):
		self.motors.drive_time(60, 0, 1800)
		self.motors.drive_time(0, 94, 2000)
		self.motors.drive_time(-60, 0, 800)

	# intersection detection

	def senseIntersection(self):
		if self.sensorRed.reflection() < 2 or self.sensorYellow.reflection() < 2:
			return True

	# path correction

	# completely aluminum = 23
	# completely black tape = 1
	def correctPath(self):
		if self.sensorBlue.reflection() < 8:
			self.adjustLeft()

		if self.sensorBlue.reflection() > 16:
			self.adjustRight()

	# default: -125, angle
	def adjustLeft(self):
		angle = 12 - min(self.sensorBlue.reflection(), 10)
		step = 125 + (12 - min(self.sensorBlue.reflection(), 10))
		self.motors.drive(-step, angle)

	def adjustRight(self):
		angle = max(self.sensorBlue.reflection(), 14) -12
		step = 125 + (max(self.sensorBlue.reflection(), 14) -12)
		self.motors.drive(-step, -angle)
示例#5
0
from pybricks.parameters import (Port, Stop, Direction, Button, Color,
                                 SoundFile, ImageFile, Align)
from pybricks.tools import print, wait, StopWatch
from pybricks.robotics import DriveBase

# Write your program here
brick.sound.beep()

# Initialize two motors with default settings on Port B and Port C.
left_motor = Motor(Port.B)
right_motor = Motor(Port.C)
# The wheel diameter of the Robot Educator is 56 millimeters.
# The distance between wheels (axle_track) is 114 millimeters.
wheel_diameter = 56
axle_track = 114
# Create a DriveBase object. The wheel_diameter and axle_track values are
# needed to move robot correct speed/distance when you give drive commands.
robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)

# This drives at 100 mm/sec straight
# drive(speed, steering)
#robot.drive (1, 0)
# This drives straight backwards at 500 mm/sec for 2 seconds
#robot.drive_time(10, 0, 2000)

# Drive forward at 100 mm/s for two seconds
robot.drive_time(100, 45, 2000)
# Turn at 45 deg/s for three seconds
#robot.drive_time(0, 45, 3000)

brick.sound.beep()
示例#6
0
                                 InfraredSensor, UltrasonicSensor, GyroSensor)
from pybricks.parameters import (Port, Stop, Direction, Button, Color,
                                 SoundFile, ImageFile, Align)
from pybricks.tools import print, wait, StopWatch
from pybricks.robotics import DriveBase

# Write your program here
motorA = Motor(Port.A)
motorC = Motor(Port.C)
robot = DriveBase(motorA, motorC, 56, 114)
gs = GyroSensor(Port.S4)
x = 0

while x < 2:
    print("Side 1")
    robot.drive_time(500, 0, 2000)

    motorA.run(250)
    motorC.run(-250)

    gs.reset_angle(0)

    while gs.angle() >= -75:
        wait(50)
        print("Gyro Angle :", gs.angle())

        if gs.angle() <= -75:
            robot.stop(Stop.BRAKE)

    robot.stop(Stop.BRAKE)
示例#7
0
    else:
        small.run(-75)
    '''
    
    
    #print("Light Sensor is ", onTable)
    #print("Right Side is ", r_sideOn)
    #print("Left Side is ", l_sideOn)
   
    if onTable == True:
        if (ultra.distance() <300):
            robot.drive(200,0)
        else: 
            robot.drive(100,0)
    elif onTable == False:
        robot.drive_time(-100,70,2000)
    
        
      
        
    '''
    #In the case that only the left limit switch runs off (shallow angle of approach)
    if (l_sideOn == False):
        #brick.sound.beep()
        if (onTable == True):
            left_motor.run_target(300,-1200)
        else: 
            right_motor.run(0)
            left_motor.run_time(-180,2000,Stop.COAST, True)

    #In the case that only the right limit switch runs off (shallow angle of approach)
示例#8
0
from pybricks import ev3brick as brick
from pybricks.ev3devices import Motor, UltrasonicSensor, ColorSensor, TouchSensor
from pybricks.parameters import Port, Color
from pybricks.tools import wait
from pybricks.robotics import DriveBase

left_motor = Motor(Port.B)
right_motor = Motor(Port.C)
robot = DriveBase(left_motor, right_motor, 56, 160)

button = TouchSensor(Port.S1)

# Create a walled circle around robot, with opening
# Attach touch button to front of robot
# Escape the Walls

while True:

    robot.drive(100, 0)

    if button.pressed():
        robot.drive_time(-100, 0, 2000)
        robot.drive_time(100, 180, 1000)
#!/usr/bin/env pybricks-micropython

from pybricks import ev3brick as brick
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                 InfraredSensor, UltrasonicSensor, GyroSensor)
from pybricks.parameters import (Port, Stop, Direction, Button, Color,
                                 SoundFile, ImageFile, Align)
from pybricks.tools import print, wait, StopWatch
from pybricks.robotics import DriveBase

# Write your program here
left = Motor(Port.B)
right = Motor(Port.C)
robot = DriveBase(left, right, 56, 114)

#drive_time(speed:mm/s, steering:deg/s, time:ms)
#Drive 25cm - 2.5 seconds at 100 speed
robot.drive_time(100, 0, 2500)
robot.stop()
示例#10
0
                    if color_sensor.color() == myColor:
                        break

            # start/continue driving ..
            robot.drive(drive_speed, 0)
            wait(100)

            # .. eventually make a turn
            make_turn()

        # stop and grab an item
        robot.stop()
        close_grabber()

        # move away from pick-up zone
        robot.drive_time((-1*drive_speed), 0, 4000)
        robot.drive_time(50, -90, 2000)
        loaded = True
    
    # search for drop zone and drop the item
    while loaded == True:
        # drive around and look for drop zone
        while True:
            collision_avoidance()
            if color_sensor.color() != calibration_surface:
                robot.stop()
                # if zone is detacted stop driving around
                    if color_sensor.color() == dropZoneColor:
                        break

            # start/continue driving ..
#!/usr/bin/env pybricks-micropython

from pybricks import ev3brick as brick
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                 InfraredSensor, UltrasonicSensor, GyroSensor)
from pybricks.parameters import (Port, Stop, Direction, Button, Color,
                                 SoundFile, ImageFile, Align)
from pybricks.tools import print, wait, StopWatch
from pybricks.robotics import DriveBase

# Initialize Motors
motorLeft = Motor(Port.A)
motorRight = Motor(Port.B)
robot = DriveBase(motorLeft, motorRight, 56, 114)

# Initialize Color Sensor
colorSensor = ColorSensor(Port.S1)

# Set Base Color
baseColor = colorSensor.color()

while True: 
    robot.drive(200,0)

    while baseColor != colorSensor.color():
        robot.drive_time(0,45,1)
        

示例#12
0
    # Button is released before continuing.
    while any(brick.buttons()):
        wait(10)

# Wait 2 seconds and then play a sound to indicate that the robot is
# about to drive.
wait(2000)
brick.sound.file(SoundFile.GO)
wait(1000)

# Now drive the robot using the list of stored commands.  This is done
# by going over each command in the list in a loop.
for drive_command in drive_command_list:
    # The robot turns 90 degrees to the left.
    if drive_command == Button.LEFT:
        robot.drive_time(100, -90, 1000)

        # The robot turns 90 degrees to the right.
    elif drive_command == Button.RIGHT:
        robot.drive_time(100, 90, 1000)

    # The robot drives straight forward 30 cm.
    elif drive_command == Button.UP:
        robot.drive_time(100, 0, 3000)

        # The robot drives straight backward 30 cm.
    elif drive_command == Button.DOWN:
        robot.drive_time(-100, 0, 3000)

# Play a sound to indicate that it is finished.
brick.sound.file(SoundFile.GAME_OVER)
示例#13
0
axle_track = 120
wheel_diameter = 55

robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)


# Write your program here.
ev3.speaker.beep()

# Select target from right to left side of plate
target = 4

if target == 1:

    # turn right 50 degrees
    robot.drive_time(0, 48, 1000)

    # go forward
    robot.drive_time(2000, 0, 2000)

    # turn left 85 degrees
    robot.drive_time(0, -85, 1000)

elif target == 2:

    # turn right
    robot.drive_time(0, 16, 1000)

    # go forward
    robot.drive_time(2000, 0, 3000)
示例#14
0
        right_stick_x = value
    if ev_type == 3 and code == 1:
        right_stick_y = value
    if ev_type == 1 and code == 307 and value == 1:
        weapon.run_angle(100, 30, Stop.COAST, False)
    if ev_type == 1 and code == 308 and value == 1:
        weapon.run_time(720, 5000, Stop.COAST, False)
    if ev_type == 1 and code == 305 and value == 1:
        invert = invert * -1
    if ev_type == 1 and code == 304 and value == 1:
        while (True):
            print(cs.color())
            if cs.color() == None:
                next
            elif cs.color() > 2:
                robot.drive_time(50, 80, 300)
            else:
                robot.drive_time(50, -30, 300)
            if Button.LEFT in brick.buttons():
                break

    # Scale stick positions to -100,100
    forward = scale(right_stick_y, (0, 255), (200, -200)) * invert
    left = scale(right_stick_x, (0, 255), (200, -200))

    # Set motor voltages. If we're steering left, the left motor
    # must run backwards so it has a -left component
    # It has a forward component for going forward too.
    left_motor.dc(forward - left)
    right_motor.dc(forward + left)
示例#15
0
dr = UltrasonicSensor(Port.S2)
lev_kol = Motor(Port.D)
pr_kol = Motor(Port.A)
mb = Motor(Port.B)
mc = Motor(Port.C)

robot = DriveBase(lev_kol, pr_kol, 69, 127)

skr = list()
skk = list()

for i in range(3):
    robot.drive(100, 0)
    while not (dcl.color() == Color.BLACK and dcp.color() == Color.BLACK):
        wait(10)
    robot.drive_time(50, 0, 330)
    if i == 0:
        mc.run_time(-700, 2100)
sh_code()
# robot.drive_time(150, 0, 870)
nch_hr()
for j in range(2):
    mb.track_target(360)
    wait(1300)
    mb.stop()
    wait(300)
# mc.run_time(-300, 1000)
for i in range(2):
    robot.drive(100, 0)
    while dr.distance() > 45:
        wait(10)
calibration_ramp = color_sensor_ramp.color()

while ball_count < 4:
    global last_direction_change

    collision_avoidance()
    check_ball()
    if check_container_full():
        break

    # run every 1s
    if watch.time() - last_direction_change > random_direction_change_interval:
        last_direction_change = watch.time()
        random_direction = random.randint(0, 91)
        robot.drive_time(drive_speed,
                         random_negate() * rotation_speed,
                         (random_direction / rotation_speed) * 1000)
        brick.display.clear()
    robot.drive(drive_speed, 0)

    # brick.display.clear()
    # brick.display.text(ultrasonic.presence(), (0, 20))
    # wait(200)
    # brick.display.text(ultrasonic.distance(), (0, 40))
    # brick.display.text(color_sensor_floor.rgb(), (0,10))
    # brick.display.text(color_sensor_floor.reflection(), (0,20))
    # brick.display.text(color_sensor_floor.color(), (0,30))
    # print(ultrasonic.presence())
    # print(ultrasonic.distance())
    # ultrasonic2.distance()
    # wait(100)
示例#17
0
#!/usr/bin/env pybricks-micropython

from pybricks import ev3brick as brick
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                 InfraredSensor, UltrasonicSensor, GyroSensor)
from pybricks.parameters import (Port, Stop, Direction, Button, Color,
                                 SoundFile, ImageFile, Align)
from pybricks.tools import print, wait, StopWatch
from pybricks.robotics import DriveBase

# Write your program here
left = Motor(Port.B)
right = Motor(Port.C)
robot = DriveBase(left, right, 56, 114)

#drive_time(speed:mm/s, steering:deg/s, time:ms)

robot.drive_time(100, 0, 3600)  #Drive forward 36cm
robot.drive_time(0, -55, 1000)  #Turn left
robot.drive_time(100, 0, 2500)  #Drive forward 25cm
robot.stop()

#You need to perform the same actions in reverse to complete challenge
示例#18
0
文件: 3-4.py 项目: mkoeda/LEGO_Python
#!/usr/bin/env pybricks-micropython

from pybricks.ev3devices import Motor
from pybricks.parameters import Port, Stop
from pybricks.robotics import DriveBase

left_motor = Motor(Port.B)
right_motor = Motor(Port.C)
wheel_diameter = 56
axle_track = 123
robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)

speed = [100, -200, 300]

robot.drive_time(speed[0], 0, 1000)
robot.drive_time(speed[1], 0, 1000)
robot.drive_time(speed[2], 0, 1000)
示例#19
0
obstacle_sensor = UltrasonicSensor(Port.S4)
# Initialize two motors with default settings on Port B and Port C.
# These will be the left and right motors of the drive base.
left_motor = Motor(Port.B)
right_motor = Motor(Port.C)
# The wheel diameter of the Robot Educator is 56 millimeters.
wheel_diameter = 56
# The axle track is the distance between the centers of each of the wheels.
# For the Robot Educator this is 114 millimeters.
axle_track = 114
# The DriveBase is composed of two motors, with a wheel on each motor.
# The wheel_diameter and axle_track values are used to make the motors
# move at the correct speed when you give a motor command.
robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)
# The following loop makes the robot drive forward until it detects an
# obstacle. Then it backs up and turns around. It keeps on doing this
# until you stop the program.
while True:
    # Begin driving forward at 200 millimeters per second.
    robot.drive(200, 0)
    # Wait until an obstacle is detected. This is done by repeatedly
    # doing nothing (waiting for 10 milliseconds) while the measured
    # distance is still greater than 300 mm.
    while obstacle_sensor.distance() > 300:
        wait(10)
        # Drive backward at 100 millimeters per second. Keep going for 2 seconds.
        robot.drive_time(-100, 0, 2000)
        # Turn around at 60 degrees per second, around the midpoint between
        # the wheels. Keep going for 2 seconds.
        robot.drive_time(0, 60, 2000)
            beepPlz()
        t += 1
        pass
    if (numberOfTouches == 0):
        routineBlue()
    elif (numberOfTouches < 5):
        routineYellow()
    elif (numberOfTouches < 10):
        routineGreen()
    else:
        routineRed()
    beepPlz()


# initVariables()
# beepPlz()
# display()
# wait(1000)
# routineRed()
# wait(1000)
# routineGreen()
# wait(1000)

# checkForTouch()

robot.drive_time(100, 90, 3000)
wait(100)
robot.stop()


示例#21
0
#foundvictim()
#leftturn()
#brick.sound.beep()
#MA.backward(2000)
#brick.sound.beep()
#MA.rightturn()
#brick.sound.beep()
#MA.leftturn()
#brick.sound.beep()
#colourchecker()

#Testing

#foundvictim()

robot.drive_time(-1000, 0, 1500)
wait(1000)
main()
'''
while True:
    if Button.UP in brick.buttons():
        brick.sound.beep()
        forward(200)
    elif Button.DOWN in brick.buttons():
        brick.sound.beep()
        backwardtest(200)
    elif Button.LEFT in brick.buttons():
        brick.sound.beep()
        leftturn()
    elif Button.RIGHT in brick.buttons():
        brick.sound.beep()
示例#22
0
from pybricks.tools import print, wait, StopWatch
from pybricks.robotics import DriveBase
from pybricks.ev3devices import Motor

# Write your program here
brick.sound.beep()
gs = GyroSensor(Port.S3)
motorA = Motor(Port.A)
motorD = Motor(Port.D)
robot = DriveBase(motorA, motorD, 56, 114)

#Go forward for one seconds
#speed 500 mm/s - forward speed
#steering 0 deg/s - Turn rate of the robot
#time 1000 ms - duration
robot.drive_time(500, 0, 1000)
robot.stop(Stop.BRAKE)
wait(500)

#Reset Gyro Sensor angle  to zero
gs.reset_angle(0)

print("Gyro Angle :", gs.angle())

#Run motor A at 30 degrees per second
motorA.run(300)
motorD.run(-300)

#wait(5000)

while gs.angle() <= 80:
示例#23
0
pi = 3.14159265359 # roughly
pi2 = pi * 2.0 # roughly
angB = 0
angC = 0
oc = 0

waitBC()  # make sure motors are not moving

while oc < 4:
  oc += 1
  cycles = 0
  while (cycles < 2):
    cycles += 1
    print("Cycles: %d,%d" % (oc,cycles))
    t1 = watch.time() / 1000
    robot.drive_time(100, 45, 8000)
    t2 = watch.time() / 1000
    driveTime = t2-t1
    print("CW drive time: %5.3f" % (driveTime))
    DTFlag = True
    sleep(1)  # just in case not quite done
    mB.stop(Stop.HOLD)
    mC.stop(Stop.HOLD)
    waitBC()

  while (cycles < 4):
    cycles += 1
    print("Cycles: %d,%d" % (oc,cycles))
    t1 = watch.time() / 1000
    robot.drive_time(100, -45, 8000)
    t2 = watch.time() / 1000
示例#24
0
import time

# plug in
# A =  left motor
# D =  right motor
#
# S4 =  ultrasonic sensor

left = Motor(Port.A)
right = Motor(Port.D)
dist = UltrasonicSensor(Port.S4)
wheel_dia = 56
wheel_spacing = 114

car = DriveBase(left, right, wheel_dia, wheel_spacing)
car.drive_time(speed=20, steering=90, time=2000)
wait(2000)
car.drive(20, 90)
wait(200)
car.stop(Stop.COAST)  #or COAST, BRAKE, or HOLD

brick.sound.beep()
brick.display.clear()
while not any(brick.buttons()):
    measured = dist.distance()
    brick.display.clear()
    brick.display.text(str(measured), (0, 60))
    if measured < 2000:
        speed = dist.distance() - 100
        brick.display.text(str(speed))
        car.drive(speed, 0)
示例#25
0
    print("blue: " + str(sensorBlue.reflection()))


while True:
    while sensorBlue.reflection() < 15:  # Is motors on a path
        motors.drive(200, 0)

        # T intersection
        if sensorRed.reflection() < 15 and sensorYellow.reflection() < 15:
            sensorCheck()
            print('crossroads')
            choice = path[i]
            #choice = random.randrange(0, 3)
            if choice == 0:
                print('straight')
                motors.drive_time(speed_d, 0, speed_t)
                i += 1
            if choice == 1:
                print('right')
                turnRight()
            if choice == 2:
                print('left')
                turnLeft()

            # Y intersection to left
        elif sensorRed.reflection() < 15:
            sensorCheck()
            print('angled left')
            choice = path[i]
            #choice = random.randrange(0, 2)
            if choice == 0:
    # Print ' 'You Better Run' ' a little bit underneath it 
    brick.display.text("You Better Run", (60, 70))

    # Have the robot continue the loop for a certain number of times.
    while i > 0:
        # Spin Wings at full speed for 2 seconds
        motor3.run(400)
        # Have the robot drive at full speed until it senses something, and then stop right before it
        while sensor.distance() > 150:
            wait(10)
            robot.drive(400, 0)
        robot.stop(stop_type = Stop.BRAKE)
        # Have the robot play a laughing sound when it runs into something
        brick.sound.file(SoundFile.LAUGHING_1, 100)
        robot.drive_time(-200, 0, 1000)
        # Have the back wheel lift up
        motor4.run_time(100, 500)
        # Have the robot rotate
        robot.drive_time(0, 360, 1000)
        # Put the back wheel back on the ground
        motor4.run_time(-100, 500)

        #Have the robot stop going through that loop a certain number of times
        i = i-1

    #Lift up the back wheel
    motor4.run_time(100, 500)
    # Make wings spin at full speed
    motor3.run(400)
示例#27
0
from pybricks.robotics import DriveBase

# Create your objects here.
ev3 = EV3Brick()

# Initialize the Ultrasonic Sensors.
obstacle_sensor = UltrasonicSensor(Port.S1)
color_sensor = ColorSensor(Port.S4)

# Initialize two motors.
left_motor = Motor(Port.B)
right_motor = Motor(Port.C)
arm_motor = Motor(Port.D)

# The DriveBase is composed of two motors, with a wheel on each motor.
robot = DriveBase(left_motor, right_motor, wheel_diameter=55.5, axle_track=104)

#drive_time(speed:mm/s, steering:deg/s, time:ms)
robot.drive_time(100, 0, 1000)  #Drive forward 10cm
robot.stop()

#run arm motor (speed mm/s, rotational angle)
arm_motor.run_angle(-100, 60)

#run time with wait as FALSE
#run_time(speed deg/s, time ms, then=Stop.HOLD, wait=True)
left_motor.run_time(-100, 1000, Stop.HOLD, False)
right_motor.run_time(-100, 1000, Stop.HOLD, False)
arm_motor.run_time(50, 1000, Stop.HOLD, False)
wait(1000)
示例#28
0
from pybricks import ev3brick as brick
from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor,
                                 InfraredSensor, UltrasonicSensor, GyroSensor)
from pybricks.parameters import (Port, Stop, Direction, Button, Color,
                                 SoundFile, ImageFile, Align)
from pybricks.tools import print, wait, StopWatch
from pybricks.robotics import DriveBase

# Write your program here
LM = Motor(Port.B)
RM = Motor(Port.D)
WD = 56
AT = 114

Robot = DriveBase(LM, RM, WD, AT)

Eyes = UltrasonicSensor(Port.S3)
Col = ColorSensor(Port.S2)

while True:
    Robot.drive(0, 90)

    if Eyes.distance() < 350:
        wait(10)
        while Col.reflection() > 10:
            Robot.drive(200, 0)

        else:
            Robot.drive_time(-250, 0, 1500)
示例#29
0
#!/usr/bin/env pybricks-micropython

from pybricks.ev3devices import Motor
from pybricks.parameters import Port, Stop
from pybricks.robotics import DriveBase

left_motor = Motor(Port.B)
right_motor = Motor(Port.C)

wheel_diameter = 56
axle_track =123

robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track)

robot.drive_time(200, 0, 2000)
示例#30
0
                                 SoundFile, ImageFile, Align)
from pybricks.tools import print, wait, StopWatch
from pybricks.robotics import DriveBase

# Write your program here
brick.sound.beep(500, 500)
print("Hallo Welt!")

# Motor an Port B
motor_m = Motor(Port.B)
motor_m.run_target(500, -80)
motor_l = Motor(Port.A)
motor_l.run_target(500, 360)
motor_r = Motor(Port.D)
motor_r.run_target(500, 360)

robot = DriveBase(motor_l, motor_r, 30, 160)

sensor = InfraredSensor(Port.S4)

dist = sensor.distance()
print("Abstand: ", dist)
while dist > 10:
    robot.drive_time(50, 90, 500)
    dist = sensor.distance()
    print("Abstand: ", dist)
robot.stop()

brick.sound.beep(1500, 500)
brick.sound.beep(300, 500)
brick.sound.beep(100, 500)