-
Notifications
You must be signed in to change notification settings - Fork 2
/
range_finder.py
36 lines (27 loc) · 1.16 KB
/
range_finder.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/usr/bin/env python3
# This program uses an algorithm that was written for solving metal rod
# forest. It was abandoned as the robot was too big to rotate in the forest.
# Possible fix for this was to make the infrared sensor rotate instead.
# Unfortunately due to time constraints the code was not modified.
from ev3dev2.motor import LargeMotor, MediumMotor, OUTPUT_A, OUTPUT_B, OUTPUT_C, SpeedPercent, MoveTank, MoveSteering
from ev3dev2.motor import SpeedDPS, SpeedRPM, SpeedRPS, SpeedDPM
from ev3dev2.sensor import INPUT_1, INPUT_2, INPUT_3, INPUT_4
from ev3dev2.sensor.lego import TouchSensor, ColorSensor, InfraredSensor, UltrasonicSensor
from ev3dev2.led import Leds
from ev3dev2.display import Display
from ev3dev2.button import Button
from ev3dev2.sound import Sound
from time import sleep
from tank.custom_tank import CustomMoveTank
from utils.rangemapper import RangeMapper, Reading
sound = Sound()
button = Button()
mapper = RangeMapper()
tank = CustomMoveTank(OUTPUT_B, OUTPUT_C)
sound.beep()
while not button.enter:
sleep(1)
while not button.backspace:
gap_heading = mapper.findGap()
tank.turn(gap_heading.degree)
tank.move_cm(gap_heading.dist)