def RedMission(): # Red Run (Bench Mission (including backrest removal)) # UP BUTTON #!/usr/bin/env pybricks-micropython from pybricks.hubs import EV3Brick from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, InfraredSensor, UltrasonicSensor, GyroSensor) from pybricks.parameters import Port, Stop, Direction, Button, Color from pybricks.tools import wait, StopWatch, DataLog from pybricks.robotics import DriveBase from pybricks.media.ev3dev import SoundFile, ImageFile # This program requires LEGO EV3 MicroPython v2.0 or higher. # Click "Open user guide" on the EV3 extension tab for more information. # Create your objects here. ev3 = EV3Brick() left_motor = Motor(Port.C) right_motor = Motor(Port.B) wheel_diameter = 56 axle_track = 115 robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track) Medium_Motor = Motor(Port.A) Large_Motor = Motor(Port.D) leftcolorsensor = ColorSensor(Port.S3) rightcolorsensor = ColorSensor(Port.S2) robot.settings(500) robot.straight(290) robot.stop(Stop.BRAKE) robot.settings(700,400,700,400) robot.turn(110) robot.stop(Stop.BRAKE) while True: robot.drive(200,0) if leftcolorsensor.color() == Color.BLACK: robot.stop(Stop.BRAKE) break robot.stop(Stop.BRAKE) ev3.speaker.beep(3) robot.turn(-110) robot.straight(80) BLACK = 9 WHITE = 85 threshold = (BLACK + WHITE) / 2 # Set the drive speed at 100 millimeters per second. DRIVE_SPEED = 100 # Set the gain of the proportional line controller. This means that for every PROPORTIONAL_GAIN = 1.2 runWhile = True robot.reset() ev3.speaker.beep() while True: # Calculate the deviation from the threshold. deviation = rightcolorsensor.reflection() - threshold # Calculate the turn rate. turn_rate = PROPORTIONAL_GAIN * deviation # Set the drive base speed and turn rate. robot.drive(DRIVE_SPEED, turn_rate) wait(10) print(rightcolorsensor.color()) if robot.distance() >= 100: robot.stop(Stop.BRAKE) break robot.stop(Stop.BRAKE) BLACK = 9 WHITE = 85 threshold = (BLACK + WHITE) / 2 # Set the drive speed at 100 millimeters per second. DRIVE_SPEED = 100 # Set the gain of the proportional line controller. This means that for every PROPORTIONAL_GAIN = 1.2 runWhile = True robot.reset() while True: # Calculate the deviation from the threshold. deviation = rightcolorsensor.reflection() - threshold # Calculate the turn rate. turn_rate = PROPORTIONAL_GAIN * deviation # Set the drive base speed and turn rate. robot.drive(DRIVE_SPEED, turn_rate) wait(10) print(rightcolorsensor.color()) if leftcolorsensor.color() == Color.BLACK: robot.stop(Stop.BRAKE) break robot.turn(-25) robot.straight(230) Large_Motor.run_angle(50,100,then = Stop.HOLD, wait = True) robot.straight(-60) robot.turn(35) robot.straight(-10) Large_Motor.run_angle(50,-50,then = Stop.HOLD, wait = True) robot.straight(-85) robot.turn(-85) robot.straight(500) robot.turn(-20) robot.straight(250) Large_Motor.run_angle(50,-70,then = Stop.HOLD, wait = False) robot.turn(110) robot.stop(Stop.BRAKE)
def BlueMission(): # Blue Run (Step Counter, Pull-Up Bar, Boccia Aim, Slide, Health Unit - 1) # DOWN BUTTON #!/usr/bin/env pybricks-micropython from pybricks.hubs import EV3Brick from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, InfraredSensor, UltrasonicSensor, GyroSensor) from pybricks.parameters import Port, Stop, Direction, Button, Color from pybricks.tools import wait, StopWatch, DataLog from pybricks.robotics import DriveBase from pybricks.media.ev3dev import SoundFile, ImageFile # This program requires LEGO EV3 MicroPython v2.0 or higher. # Click "Open user guide" on the EV3 extension tab for more information. #define your variables ev3 = EV3Brick() left_motor = Motor(Port.C) right_motor = Motor(Port.B) medium_motor = Motor(Port.A) large_motor = Motor(Port.D) wheel_diameter = 56 axle_track = 115 line_sensor = ColorSensor(Port.S2) line_sensor1 = ColorSensor(Port.S3) robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track) # Go towards the step counter mission from base robot.settings(800) # Speed Change robot.straight(650) robot.stop(Stop.BRAKE) wait(20) # Slow the robot down to succesfully push the step counter. robot.settings(200) # Slowly pushes the step counter by going backward and forward a couple times to increase reliability. robot.straight(230) robot.straight(-20) robot.straight(50) robot.stop(Stop.BRAKE) #robot.straight(-45) #robot.stop(Stop.BRAKE) #robot.straight(120) #robot.stop(Stop.BRAKE) robot.straight(-60) robot.stop(Stop.BRAKE) # The robot then turns and goes backwards until the right color sensor detects black. #robot.settings(250,300,250,300) robot.turn(45) robot.straight(-100) while True: robot.drive(-100,0) if line_sensor.color() == Color.BLACK: robot.stop(Stop.BRAKE) break #The large motor attatchment comes down at the same time the robot takes a turn towards #the black line underneath the pull up bar left_motor.run_angle(50,-300,then=Stop.HOLD, wait=True) # The robot then goes straight towards the line under the pull-up bar. robot.straight(120) robot.stop(Stop.BRAKE) # Robot continues to go forwards until the left color sensor detects black. while True: robot.drive(115,0) if line_sensor.color() == Color.BLACK: robot.stop(Stop.BRAKE) break right_motor.run_angle(100,150,then=Stop.HOLD, wait=True) # The robot turns using the right motor until it detects black. while True: right_motor.run(100) if line_sensor.color() == Color.BLACK: robot.stop(Stop.BRAKE) break robot.straight(-90) large_motor.run_angle(100,150,then=Stop.HOLD, wait=True) robot.stop(Stop.BRAKE) robot.stop(Stop.BRAKE) while True: right_motor.run(40) if line_sensor.color() == Color.BLACK: robot.stop(Stop.BRAKE) break robot.stop(Stop.BRAKE) ev3.speaker.beep() BLACK = 9 WHITE = 85 threshold = (BLACK + WHITE) / 2 # Set the drive speed at 100 millimeters per second. DRIVE_SPEED = 100 # Set the gain of the proportional line controller. This means that for every PROPORTIONAL_GAIN = 1.2 runWhile = True robot.reset() ev3.speaker.beep() while True: # Calculate the deviation from the threshold. deviation = line_sensor.reflection() - threshold # Calculate the turn rate. turn_rate = PROPORTIONAL_GAIN * deviation # Set the drive base speed and turn rate. robot.drive(DRIVE_SPEED, turn_rate) wait(10) print(line_sensor1.color()) if line_sensor1.color() == Color.BLACK: robot.stop(Stop.BRAKE) break robot.stop(Stop.BRAKE) robot.stop(Stop.BRAKE) large_motor.run_angle(-150, 150, then=Stop.HOLD, wait=False) robot.turn(20) robot.stop(Stop.BRAKE) robot.settings(800) robot.straight(280) ev3.speaker.beep(3) while True: robot.drive(-115,0) if line_sensor.color() == Color.BLACK: ev3.speaker.beep(10) robot.stop(Stop.BRAKE) break robot.stop(Stop.BRAKE) # robot.straight(-10) robot.stop(Stop.BRAKE) robot.turn(50) # left_motor.run_angle(100, 150) ''' large_motor.run_angle(30,-20,then=Stop.HOLD, wait=False) robot.turn(10) robot.stop(Stop.BRAKE) large_motor.run_angle(100, -50, then=Stop.HOLD, wait=False) robot.turn(90) robot.stop(Stop.BRAKE) ''' BLACK = 9 WHITE = 85 threshold = (BLACK + WHITE) / 2 # Set the drive speed at 100 millimeters per second. DRIVE_SPEED = 100 # Set the gain of the proportional line controller. This means that for every PROPORTIONAL_GAIN = 1.2 runWhile = True robot.reset() ev3.speaker.beep() while True: # Calculate the deviation from the threshold. deviation = line_sensor.reflection() - threshold # Calculate the turn rate. turn_rate = PROPORTIONAL_GAIN * deviation # Set the drive base speed and turn rate. robot.drive(DRIVE_SPEED, turn_rate) wait(10) print(line_sensor.color()) if robot.distance() >= 500: robot.stop(Stop.BRAKE) break ev3.speaker.beep(3) while True: robot.drive(40,0) if line_sensor1.color() == Color.BLACK: robot.stop(Stop.BRAKE) break robot.stop(Stop.BRAKE) ev3.speaker.beep() robot.straight(30) robot.turn(-100) robot.straight(70) large_motor.run_angle(600,150,then=Stop.HOLD, wait=True) while True: robot.drive(-50, 0) if line_sensor1.color() == Color.BLACK: robot.stop(Stop.BRAKE) break robot.stop(Stop.BRAKE) right_motor.run_angle(600,500,then=Stop.HOLD,wait=True) robot.straight(20) BLACK = 9 WHITE = 85 threshold = (BLACK + WHITE) / 2 # Set the drive speed at 100 millimeters per second. DRIVE_SPEED = 100 # Set the gain of the proportional line controller. This means that for every PROPORTIONAL_GAIN = 1.2 runWhile = True robot.reset() ev3.speaker.beep() while True: # Calculate the deviation from the threshold. deviation = line_sensor1.reflection() - threshold # Calculate the turn rate. turn_rate = PROPORTIONAL_GAIN * deviation # Set the drive base speed and turn rate. robot.drive(DRIVE_SPEED, turn_rate) wait(10) print(line_sensor1.color()) if robot.distance() >= 580: robot.stop(Stop.BRAKE) break robot.stop(Stop.BRAKE) while True: robot.drive(50, 0) if line_sensor.color() == Color.BLACK: robot.stop(Stop.BRAKE) break robot.stop(Stop.BRAKE) ev3.speaker.beep(3) robot.turn(-45) robot.stop(Stop.BRAKE) robot.straight(30) large_motor.run_angle(1000,-150,then=Stop.HOLD, wait=True) robot.straight(-40) large_motor.run_angle(1000,150,then=Stop.HOLD, wait=True) robot.straight(40) large_motor.run_angle(1000,-150,then=Stop.HOLD, wait=True) robot.straight(-115) robot.turn(95) robot.straight(420) robot.turn(-100) robot.turn(100) robot.turn(-100) robot.turn(100) robot.turn(-100) robot.turn(100) robot.turn(-100) robot.turn(100) robot.turn(-100) robot.turn(100) robot.turn(-100) robot.turn(100) robot.turn(-100) robot.turn(100) robot.turn(-100) robot.turn(100) robot.turn(-100) robot.turn(100) robot.turn(-100) robot.turn(100) robot.turn(-100) robot.turn(100) robot.turn(-100) robot.turn(100) robot.turn(-100) robot.turn(100) robot.turn(-100) robot.turn(100) robot.turn(-100) robot.turn(100) robot.turn(-100) robot.turn(100)
def BlackandGreen(): #!/usr/bin/env pybricks-micropython from pybricks.hubs import EV3Brick from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, InfraredSensor, UltrasonicSensor, GyroSensor) from pybricks.parameters import Port, Stop, Direction, Button, Color from pybricks.tools import wait, StopWatch, DataLog from pybricks.robotics import DriveBase from pybricks.media.ev3dev import SoundFile, ImageFile # This program requires LEGO EV3 MicroPython v2.0 or higher. # Click "Open user guide" on the EV3 extension tab for more information. #define your variables ev3 = EV3Brick() left_motor = Motor(Port.C) right_motor = Motor(Port.B) medium_motor = Motor(Port.A) large_motor = Motor(Port.D) wheel_diameter = 56 axle_track = 115 line_sensor = ColorSensor(Port.S2) line_sensor1 = ColorSensor(Port.S3) robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track) #follows the line underneath the pull up bar until the leftsensor detects black BLACK = 9 WHITE = 85 threshold = (BLACK + WHITE) / 2 # Set the drive speed at 100 millimeters per second. DRIVE_SPEED = 100 # Set the gain of the proportional line controller. This means that for every PROPORTIONAL_GAIN = 1.2 runWhile = True #goes straight to get ready for line following then resets the distance robot.straight(250) robot.reset() #starts to follow the line towards the replay logo while True: # Calculate the deviation from the threshold. deviation = line_sensor.reflection() - threshold # Calculate the turn rate. turn_rate = PROPORTIONAL_GAIN * deviation # Set the drive base speed and turn rate. robot.drive(DRIVE_SPEED, turn_rate) wait(10) print(robot.distance()) if (robot.distance() >= 450): robot.stop(Stop.BRAKE) break #the robot pushes the phone into the replay logo and moves back to get ready to drop the health units into the replay logo robot.straight(-75) robot.stop(Stop.BRAKE) #the robot then turns so it is going to be perfectly into the replay logo robot.turn(-35) #the robot drops the health units large_motor.run_angle(100, 150) #then turns to an angle to go back to base robot.turn(50) robot.straight(-1000) wait(50) #!/usr/bin/env pybricks-micropython from pybricks.hubs import EV3Brick from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, InfraredSensor, UltrasonicSensor, GyroSensor) from pybricks.parameters import Port, Stop, Direction, Button, Color from pybricks.tools import wait, StopWatch, DataLog from pybricks.robotics import DriveBase from pybricks.media.ev3dev import SoundFile, ImageFile # This program requires LEGO EV3 MicroPython v2.0 or higher. # Click "Open user guide" on the EV3 extension tab for more information. # Create your objects here. ev3 = EV3Brick() left_motor = Motor(Port.C) right_motor = Motor(Port.B) medium_motor = Motor(Port.A) front_largeMotor = Motor(Port.D) wheel_diameter = 56 axle_track = 114.3 robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track) ## Write your code here: ## The robot goes straight until the Boccia Mission's target. robot.straight(1060) ## The robot moves the large motor down to drop the cubes in the target. front_largeMotor.run_angle(80, 70, then=Stop.HOLD, wait=True) front_largeMotor.run_angle(-80, 70, then=Stop.HOLD, wait=True) ## Dance Mission ## The robot moves backwards to reach the Dance Floor so it can Dance as the last mission. robot.straight(-185) robot.turn(-70) robot.straight(138) ## The following code is all the dance moves we do for the Dance Mission. robot.turn(160) robot.turn(-160) robot.straight(60) front_largeMotor.run_target(500, 60) front_largeMotor.run_target(500, -40) robot.straight(-60) robot.turn(260) robot.turn(-260) robot.turn(100) robot.straight(40) robot.turn(100) front_largeMotor.run_angle(500, 30)
def BlueMission(): #!/usr/bin/env pybricks-micropython from pybricks.hubs import EV3Brick from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, InfraredSensor, UltrasonicSensor, GyroSensor) from pybricks.parameters import Port, Stop, Direction, Button, Color from pybricks.tools import wait, StopWatch, DataLog from pybricks.robotics import DriveBase from pybricks.media.ev3dev import SoundFile, ImageFile # This program requires LEGO EV3 MicroPython v2.0 or higher. # Click "Open user guide" on the EV3 extension tab for more information. #define your variables ev3 = EV3Brick() left_motor = Motor(Port.C) right_motor = Motor(Port.B) medium_motor = Motor(Port.A) large_motor = Motor(Port.D) wheel_diameter = 56 axle_track = 115 line_sensor = ColorSensor(Port.S2) line_sensor1 = ColorSensor(Port.S3) robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track) #go front towards the step counter robot.straight(650) robot.stop(Stop.BRAKE) wait(20) #makes the robot go slower robot.settings(40) #slowly pushes the step counter by going back and front 2 times robot.straight(140) robot.stop(Stop.BRAKE) robot.straight(-45) robot.stop(Stop.BRAKE) robot.straight(120) robot.stop(Stop.BRAKE) robot.settings(100) robot.straight(-30) robot.stop(Stop.BRAKE) #the robot then turns and goes backwards robot.turn(45) robot.straight(-100) # the robot then goes back until the right color sensor detects back while True: robot.drive(-30, 0) if line_sensor.color() == Color.BLACK: robot.stop(Stop.BRAKE) break #the large motor attatchment comes down at the same time the robot takes a turn towards the black line underneath the pull up bar large_motor.run_angle(50, 170, then=Stop.HOLD, wait=False) left_motor.run_angle(50, -300, then=Stop.HOLD, wait=True) #the robot then goes straight towards that line robot.straight(120) robot.stop(Stop.BRAKE) #robot continues to go forwards until the left color sensor detects black while True: robot.drive(30, 0) if line_sensor.color() == Color.BLACK: robot.stop(Stop.BRAKE) break right_motor.run_angle(50, 150, then=Stop.HOLD, wait=True) #the robot then turns with the right motor until it detects black while True: right_motor.run(85) if line_sensor.color() == Color.BLACK: robot.stop(Stop.BRAKE) break #follows the line underneath the pull up bar until the leftsensor detects black BLACK = 9 WHITE = 85 threshold = (BLACK + WHITE) / 2 # Set the drive speed at 100 millimeters per second. DRIVE_SPEED = 100 # Set the gain of the proportional line controller. This means that for every PROPORTIONAL_GAIN = 1.2 runWhile = True robot.reset() while True: # Calculate the deviation from the threshold. deviation = line_sensor.reflection() - threshold # Calculate the turn rate. turn_rate = PROPORTIONAL_GAIN * deviation # Set the drive base speed and turn rate. robot.drive(DRIVE_SPEED, turn_rate) wait(10) print(line_sensor.color()) if line_sensor1.color() == Color.BLACK: robot.stop(Stop.BRAKE) break #the robot then turns towards the boccia aim and moves straight to push it towards the target and finishes the misison robot.straight(100) #after line following, it goes straight for 100 mm robot.turn(50) robot.straight(100) robot.straight(-30) large_motor.run_angle(100, -65) robot.straight(-60) #the robot then takes a turn (at the same time bringing the attatchment down) towards the slide mission and completes the mission large_motor.run_angle(50, 80, then=Stop.HOLD, wait=False) robot.turn(-195) robot.straight(165) large_motor.run_angle(300, -120, then=Stop.HOLD, wait=True) robot.straight(-30) large_motor.run_angle(200, 120, then=Stop.HOLD, wait=True) ## The robot moves straight towards the mission, getting ready to attempt to push the slide figures off once more. (In case it didn't work before.) robot.straight(30) large_motor.run_angle(300, -120, then=Stop.HOLD, wait=True) robot.straight(-50) '''
right_motor = Motor(Port.C , positive_direction=Direction.COUNTERCLOCKWISE, gears=[40,8]) gyro_sensor = GyroSensor(Port.S3) # Initialize the color sensor. #line_sensor = ColorSensor(Port.S3) left_motor.reset_angle(0) right_motor.reset_angle(0) gyro_sensor.reset_angle(0) fudge=1 speed=100 angle=0 robot = DriveBase(left_motor, right_motor, wheel_diameter=30, axle_track=135) initial_distance = 0 robot.reset() while ((robot.distance() - initial_distance) < 350) : robot.drive(speed,angle) drift = gyro_sensor.angle() angle = (drift * fudge) * -1 wait(3) i=0 robot.stop() speed=50 while (i<2 ): fruit = gyro_sensor.angle() fruit = fruit * (-1) robot.drive(speed,fruit) wait(3) robot.drive((speed* (-1)),fruit) i = i + 1
def BlueMission(): #!/usr/bin/env pybricks-micropython from pybricks.hubs import EV3Brick from pybricks.ev3devices import (Motor, TouchSensor, ColorSensor, InfraredSensor, UltrasonicSensor, GyroSensor) from pybricks.parameters import Port, Stop, Direction, Button, Color from pybricks.tools import wait, StopWatch, DataLog from pybricks.robotics import DriveBase from pybricks.media.ev3dev import SoundFile, ImageFile # This program requires LEGO EV3 MicroPython v2.0 or higher. # Click "Open user guide" on the EV3 extension tab for more information. #define your variables ev3 = EV3Brick() left_motor = Motor(Port.C) right_motor = Motor(Port.B) medium_motor = Motor(Port.A) large_motor = Motor(Port.D) wheel_diameter = 56 axle_track = 115 line_sensor = ColorSensor(Port.S2) line_sensor1 = ColorSensor(Port.S3) robot = DriveBase(left_motor, right_motor, wheel_diameter, axle_track) #go front towards the step counter robot.settings(250) robot.straight(650) robot.stop(Stop.BRAKE) wait(20) #makes the robot go slower robot.settings(40) #slowly pushes the step counter by going back and front 2 times robot.straight(140) robot.stop(Stop.BRAKE) robot.straight(-45) robot.stop(Stop.BRAKE) robot.straight(120) robot.stop(Stop.BRAKE) robot.straight(-30) robot.stop(Stop.BRAKE) #the robot then turns and goes backwards robot.settings(250,500,250,500) robot.turn(45) robot.straight(-100) # the robot then goes back until the right color sensor detects back while True: robot.drive(-115,0) if line_sensor.color() == Color.BLACK: robot.stop(Stop.BRAKE) break #the large motor attatchment comes down at the same time the robot takes a turn towards the black line underneath the pull up bar large_motor.run_angle(50,200,then=Stop.HOLD, wait=False) left_motor.run_angle(50,-300,then=Stop.HOLD, wait=True) #the robot then goes straight towards that line robot.straight(120) robot.stop(Stop.BRAKE) #robot continues to go forwards until the left color sensor detects black while True: robot.drive(115,0) if line_sensor.color() == Color.BLACK: robot.stop(Stop.BRAKE) break right_motor.run_angle(50,150,then=Stop.HOLD, wait=True) #the robot then turns with the right motor until it detects black while True: right_motor.run(85) if line_sensor.color() == Color.BLACK: robot.stop(Stop.BRAKE) break #follows the line underneath the pull up bar until the leftsensor detects black #follows the line underneath the pull up bar until the leftsensor detects black BLACK = 9 WHITE = 85 threshold = (BLACK + WHITE) / 2 # Set the drive speed at 100 millimeters per second. DRIVE_SPEED = 100 # Set the gain of the proportional line controller. This means that for every PROPORTIONAL_GAIN = 1.2 runWhile = True robot.reset() while True: # Calculate the deviation from the threshold. deviation = line_sensor.reflection() - threshold # Calculate the turn rate. turn_rate = PROPORTIONAL_GAIN * deviation # Set the drive base speed and turn rate. robot.drive(DRIVE_SPEED, turn_rate) wait(10) print(line_sensor1.color()) if line_sensor1.color() == Color.BLACK: robot.stop(Stop.BRAKE) break #the robot then turns towards the boccia aim and moves straight to push it towards the target and finishes the misison robot.turn(25) robot.straight(250) robot.straight(-50) # this is importate kekekekee large_motor.run_angle(75,-65) robot.straight(-60) while True: robot.drive(-70,0) if line_sensor.color() == Color.BLACK: robot.stop(Stop.BRAKE) ev3.speaker.beep() break while True: left_motor.run(-50) if line_sensor1.color() == Color.BLACK: robot.stop(Stop.BRAKE) ev3.speaker.beep() break left_motor.run_angle(50, -20) right_motor.run_angle(50, 20) robot.settings(200) robot.straight(60) robot.turn(-137) #this is also importante jekeke large_motor.run_angle(50,80) robot.straight(143) large_motor.run_angle(550, -120) robot.straight(-40) large_motor.run_angle(550, 120) robot.straight(40) large_motor.run_angle(550, -120) large_motor.run_angle(300, 30, then=Stop.HOLD, wait=True) #robot.straight(40) large_motor.run_angle(300, -100, then=Stop.HOLD, wait=True) #goes to collect the health unit near the basketball (goes back to base) robot.straight(-200) robot.turn(40) robot.straight(556) robot.straight(50) robot.stop(Stop.BRAKE) while True: left_motor.run(50) if line_sensor1.color() == Color.BLACK: robot.stop(Stop.BRAKE) ev3.speaker.beep() break robot.stop(Stop.BRAKE) robot.reset() # Calculate the light threshold. Choose values based on your measurements. BLACK = 9 WHITE = 85 threshold = (BLACK + WHITE) / 2 # Set the drive speed at 100 millimeters per second. DRIVE_SPEED = 100 # Set the gain of the proportional line controller. This means that for every # percentage point of light deviating from the threshold, we set the turn # rate of the drivebase to 1.2 degrees per second. # For example, if the light value deviates from the threshold by 10, the robot # steers at 10*1.2 = 12 degrees per second. PROPORTIONAL_GAIN = 1.2 runWhile = True # Start following the line endlessly. while runWhile: # Calculate the deviation from the threshold. deviation = line_sensor1.reflection() - threshold # Calculate the turn rate. turn_rate = PROPORTIONAL_GAIN * deviation # Set the drive base speed and turn rate. robot.drive(DRIVE_SPEED, turn_rate) if robot.distance() >= 210: runWhile = False break robot.stop(Stop.BRAKE) robot.turn(5.244312) robot.straight(700) #the robot then goes back until the right color sensor detects back ''' while True: if line_sensor1.color() == Color.BLACK: robot.stop(Stop.BRAKE) break #robot.straight(980) ''' robot.stop(Stop.BRAKE)
line_sensor = ColorSensor(Port.S2) left_motor.reset_angle(0) right_motor.reset_angle(0) gyro_sensor.reset_angle(0) fudge=1 speed=100 angle=0 robot = DriveBase(left_motor, right_motor, wheel_diameter=30, axle_track=135) left_motor.dc(90) right_motor.dc(90) """ initial_distance = 0 robot.reset() while ((robot.distance() - initial_distance) < 350) : drift = gyro_sensor.angle() print(gyro_sensor.angle()) angle = (drift * fudge) * -1 wait(10) i=0 speed=200 """ # Calculate the light threshold. Choose values based on your measurements.