Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- # Import the necessary libraries
- import time
- import math
- from ev3dev2.motor import *
- from ev3dev2.sound import Sound
- from ev3dev2.sensor import *
- from ev3dev2.sensor.lego import *
- from ev3dev2.sensor.virtual import *
- from time import sleep
- # Create the sensors and motors objects
- motorA = LargeMotor(OUTPUT_A)
- motorB = LargeMotor(OUTPUT_B)
- left_motor = motorA
- right_motor = motorB
- tank_drive = MoveTank(OUTPUT_A, OUTPUT_B)
- steering_drive = MoveSteering(OUTPUT_A, OUTPUT_B)
- spkr = Sound()
- color_sensor_in1 = ColorSensor(INPUT_1)
- color_sensor_in2 = ColorSensor(INPUT_2)
- ultrasonic_sensor_in3 = UltrasonicSensor(INPUT_3)
- gyro_sensor_in4 = GyroSensor(INPUT_4)
- gps_sensor_in5 = GPSSensor(INPUT_5)
- motorC = LargeMotor(OUTPUT_C) # Magnet
- # Here is where your code starts
- move_value = 20
- stop_value = 0
- angle = 0
- time_spent = 0
- while True:
- c1 = color_sensor_in1.reflected_light_intensity
- c2 = color_sensor_in2.reflected_light_intensity
- if ultrasonic_sensor_in3.distance_centimeters_continuous < 25:
- left_value = stop_value
- right_value = stop_value
- # obstacle turn left first time
- temp_angle = gyro_sensor_in4.angle
- while gyro_sensor_in4.angle != temp_angle - 90:
- left_motor.on(0)
- right_motor.on(4)
- else:
- if c1 == c2:
- left_value = move_value
- right_value = move_value
- # turn right around obstacle
- if c1 == 100 and c2 == 100:
- time.sleep(0.8)
- time_spent += 1
- temp_angle = gyro_sensor_in4.angle
- if time_spent >= 3:
- time_spent = 0
- while gyro_sensor_in4.angle != temp_angle + 90:
- left_motor.on(3)
- right_motor.on(0)
- elif c1 > c2:
- left_value = move_value
- right_value = stop_value
- elif c2 > c1:
- left_value = stop_value
- right_value = move_value
- left_motor.on(left_value)
- right_motor.on(right_value)
- # Copyright Kamil Serafin 11.11.2020
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement