コード例 #1
0
ファイル: lapswimmer.py プロジェクト: pjsier/FinchPythonDemos
laps = 0

# Get the number of laps Finch will swim:

while laps <= 0:
    laps = int(input('Enter number of laps: '))

    if laps < 0:
        print('Cannot swim a negative number of laps!')
    elif laps == 0:
        print('Zero laps? I want to swim!')

# Move forward until an obstacle is present and measure the time:

start = time()
finch.wheels(0.5, 0.5)
sleep(0.1)
while True:
    left_obstacle, right_obstacle = finch.obstacle()
    if left_obstacle or right_obstacle:
        half_lap_time = time() - start
        finch.wheels(0, 0)
        break

print('Obstacle found, backing up')

# Move backwards for the same amount of time spent moving forward

finch.wheels(-0.5, -0.5)
sleep(half_lap_time)
laps -= 1
コード例 #2
0
ファイル: dance.py プロジェクト: pjsier/FinchPythonDemos
# A simple Finch dance in Python

from lib.finch import Finch
from time import sleep

print("Finch's First Python program.")
# Instantiate the Finch object
snakyFinch = Finch()


# Do a six step dance
snakyFinch.led(255,0,0)
snakyFinch.wheels(1,1)
sleep(1)

snakyFinch.led(0,255,0)
snakyFinch.wheels(0,1)
sleep(1)

snakyFinch.led(0,0,255)
snakyFinch.wheels(1,0)
sleep(1)

snakyFinch.led(255,0,255)
snakyFinch.wheels(-1,-1)
sleep(0.5)

snakyFinch.led(0,255,255)
snakyFinch.wheels(0.2,-1)
sleep(1)
コード例 #3
0
ファイル: racedriver.py プロジェクト: pjsier/FinchPythonDemos
# Race track driver, an example program for the Finch
# Watch the Finch navigate a square race track

from lib.finch import Finch
from time import sleep

#Main function for the race track driver example program."""

#Initialize the finch
finch = Finch()

#Set both wheels to one-half forward throttle for 1.5s
finch.wheels(0.5,0.5)
finch.led(0, 255, 255)
sleep(1.5)

# Now set the left wheel at half throttle, right wheel off to turn
finch.wheels(0.5,0)
finch.led(0, 255, 0)
sleep(1.28)


finch.wheels(0.5,0.5)
finch.led(0, 255, 255)
sleep(1.5)


finch.wheels(0.5,0)
finch.led(0, 255, 0)
sleep(1.28)
コード例 #4
0
ファイル: wanderer.py プロジェクト: pjsier/FinchPythonDemos
from time import sleep

# Instantiate the Finch object and connect to Finch
tweety = Finch()

# Get the Z-Axis acceleration
zAccel = tweety.acceleration()[2]

# Do the following while the Finch is not upside down (z value in gees above -0.7)
while zAccel > -0.7:

    left_obstacle, right_obstacle = tweety.obstacle()
    # If there's an obstacle on the left, back up and arc
    if left_obstacle:
        tweety.led(255,0,0)
        tweety.wheels(-0.3,-1.0)
        sleep(1.0)
    # Back up and arc in the opposite direction if there's something on the right
    elif right_obstacle:
        tweety.led(255,255,0)
        tweety.wheels(-1.0, -0.3)
        sleep(1.0)
    # Else just go straight
    else:
        tweety.wheels(1.0, 1.0)
        tweety.led(0,255,0)
    # Keep reading in the Z acceleration
    zAccel = tweety.acceleration()[2]

tweety.close()
コード例 #5
0
window.keypad(1)

window.addstr(0, 0, "Hit 'q' to quit")
window.move(2, 0)
window.refresh()

key = ''
while key != ord('q'):
    key = window.getch()
    window.addch(2, 0, key)
    window.refresh()

    if key == curses.KEY_UP:
        window.clrtobot()
        window.addstr(2, 0, "Finch goes forward!")
        myFinch.wheels(1, 1)
        sleep(0.1)
        myFinch.halt()

    elif key == curses.KEY_DOWN:
        window.clrtobot()
        window.addstr(2, 0, "Finch goes backwards!")
        myFinch.wheels(-1, -1)
        sleep(0.1)
        myFinch.halt()

    elif key == curses.KEY_LEFT:
        window.clrtobot()
        window.addstr(2, 0, "Finch goes left!")
        myFinch.wheels(0, 1)
        sleep(0.1)