mirror of
https://github.com/undera/pylgbst.git
synced 2020-11-18 19:37:26 -08:00
Finish color pinned bot
This commit is contained in:
parent
3f19c983c2
commit
544aa82cf5
@ -41,7 +41,7 @@ class Automata(object):
|
||||
return clr
|
||||
|
||||
def left(self):
|
||||
self.__hub.motor_AB.angled(270, self.BASE_SPEED, -self.BASE_SPEED, end_state=EncodedMotor.END_STATE_FLOAT)
|
||||
self.__hub.motor_AB.angled(290, self.BASE_SPEED, -self.BASE_SPEED, end_state=EncodedMotor.END_STATE_FLOAT)
|
||||
time.sleep(0.1)
|
||||
self.__hub.motor_AB.stop()
|
||||
|
||||
@ -51,10 +51,10 @@ class Automata(object):
|
||||
self.__hub.motor_AB.stop()
|
||||
|
||||
def forward(self):
|
||||
self.__hub.motor_AB.angled(600, self.BASE_SPEED)
|
||||
self.__hub.motor_AB.angled(500, self.BASE_SPEED)
|
||||
|
||||
def backward(self):
|
||||
self.__hub.motor_AB.angled(600, -self.BASE_SPEED)
|
||||
self.__hub.motor_AB.angled(500, -self.BASE_SPEED)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
35
examples/automata/bot.py
Normal file
35
examples/automata/bot.py
Normal file
@ -0,0 +1,35 @@
|
||||
from examples.automata import Automata
|
||||
|
||||
from pylgbst.peripherals import *
|
||||
|
||||
|
||||
# this program is written by Sofia in early 2019
|
||||
|
||||
def action_by_color(color):
|
||||
if color == COLOR_BLUE:
|
||||
bot.forward()
|
||||
if color == COLOR_RED:
|
||||
bot.backward()
|
||||
if color == COLOR_WHITE:
|
||||
bot.right()
|
||||
if color == COLOR_YELLOW:
|
||||
bot.left()
|
||||
|
||||
|
||||
def read_color():
|
||||
bot.feed_tape()
|
||||
color = bot.get_color()
|
||||
print(COLORS[color])
|
||||
return color
|
||||
|
||||
|
||||
bot = Automata()
|
||||
number = 0
|
||||
color = None
|
||||
while color != COLOR_NONE:
|
||||
color = read_color()
|
||||
number = number + 1
|
||||
action_by_color(color)
|
||||
|
||||
print(number)
|
||||
|
Loading…
x
Reference in New Issue
Block a user