From e25bac778eff1fb4afe76252594f797ce2bb5ffc Mon Sep 17 00:00:00 2001 From: janis Date: Mon, 27 Jun 2022 15:07:47 +0200 Subject: [PATCH] FollowTheLine --- .idea/micro_bit_interface.iml | 6 ++- .idea/misc.xml | 2 +- .../micro_bit_soft/follow_the_line/ftl.py | 47 ++++++++++++------- .../follow_the_line/ftl_dumb_version.py | 17 +++++++ .../micro_bit_soft/follow_the_line/run.py | 4 +- 5 files changed, 53 insertions(+), 23 deletions(-) create mode 100644 bin/micro_bit/micro_bit_soft/follow_the_line/ftl_dumb_version.py diff --git a/.idea/micro_bit_interface.iml b/.idea/micro_bit_interface.iml index d0876a7..7c8b463 100644 --- a/.idea/micro_bit_interface.iml +++ b/.idea/micro_bit_interface.iml @@ -1,8 +1,10 @@ - - + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml index dc9ea49..281858d 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -1,4 +1,4 @@ - + \ No newline at end of file diff --git a/bin/micro_bit/micro_bit_soft/follow_the_line/ftl.py b/bin/micro_bit/micro_bit_soft/follow_the_line/ftl.py index 84bb9cd..f014c46 100644 --- a/bin/micro_bit/micro_bit_soft/follow_the_line/ftl.py +++ b/bin/micro_bit/micro_bit_soft/follow_the_line/ftl.py @@ -1,29 +1,40 @@ import maqueen_driver -import microbit -import music md = maqueen_driver.Driver() + class FollowTheLine: def __init__(self): self.__activated = 0 + self.__repeated = 0 def run(self): while True: - if md.getDistance() < 20: - md.stop() - md.setLEDs(on=1) - music.pitch(440, 20) - else: - if md.getLineTracker(1) == 0: - self.__activated = 0 - md.motor(0, 100, 0, 255) - elif md.getLineTracker(2) == 0: - self.__activated = 0 - md.motor(0, 255, 0, 100) + if md.getLineTracker(1) == 0: + self.__activated = 0 + if self.__repeated >= 75 and self.__repeated < 150: + self.__repeated += 1 + md.motor(0, 10, 0, 100) + elif self.__repeated >= 100: + md.motor(0, 0, 0, 100) else: - if self.__activated <= 50: - self.__activated += 1 - md.motor(0, 140, 0, 140) - else: - md.motor(0, 255, 0, 255) + self.__repeated += 1 + md.motor(0, 50, 0, 100) + elif md.getLineTracker(2) == 0: + self.__activated = 0 + self.__repeated += 1 + if self.__repeated >= 75 and self.__repeated < 150: + self.__repeated += 1 + md.motor(0, 100, 0, 10) + elif self.__repeated >= 100: + md.motor(0, 100, 0, 0) + else: + self.__repeated += 1 + md.motor(0, 100, 0, 50) + else: + self.__repeated = 0 + if self.__activated <= 2000: + self.__activated += 1 + md.motor(0, 100, 0, 100) + else: + md.motor(0, 255, 0, 255) diff --git a/bin/micro_bit/micro_bit_soft/follow_the_line/ftl_dumb_version.py b/bin/micro_bit/micro_bit_soft/follow_the_line/ftl_dumb_version.py new file mode 100644 index 0000000..56e33c4 --- /dev/null +++ b/bin/micro_bit/micro_bit_soft/follow_the_line/ftl_dumb_version.py @@ -0,0 +1,17 @@ +import maqueen_driver + +md = maqueen_driver.Driver() + + +class FollowTheLineDumnb: + def __init__(self): + pass + + def run(self): + while True: + if md.getLineTracker(1) == 1: + md.motor(0, 10, 0, 75) + elif md.getLineTracker(2) == 2: + md.motor(0, 75, 0, 10) + else: + md.motor(0, 75, 0, 75) diff --git a/bin/micro_bit/micro_bit_soft/follow_the_line/run.py b/bin/micro_bit/micro_bit_soft/follow_the_line/run.py index 4ba7bbf..c0e2ba8 100644 --- a/bin/micro_bit/micro_bit_soft/follow_the_line/run.py +++ b/bin/micro_bit/micro_bit_soft/follow_the_line/run.py @@ -1,3 +1,3 @@ -import ftl +import ftl_dumb_version -ftl.FollowTheLine().run() +ftl_dumb_version.FollowTheLineDumnb().run()