Last active
August 29, 2015 13:57
-
-
Save kcranley1/9408060 to your computer and use it in GitHub Desktop.
My version of test_pibot_hardware.py - uses picamera to record video!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# test_pibot_hardware.py | |
import time | |
import os.path | |
import sys | |
import pygame | |
import pygame.mixer | |
import picamera | |
import pibot | |
MUSIC_VOLUME = 0.5 | |
TEST_TIME = 10.0 | |
scriptPath = os.path.dirname( __file__ ) | |
# Load test result sounds | |
pygame.init() | |
pygame.mixer.init() | |
time.sleep(1) | |
pygame.mixer.music.load( scriptPath + "musical073.mp3" ) | |
pygame.mixer.music.set_volume( MUSIC_VOLUME * 16) | |
pygame.mixer.music.play() | |
time.sleep(7) | |
pygame.mixer.music.load( scriptPath + "drum_roll.mp3" ) | |
pygame.mixer.music.set_volume( MUSIC_VOLUME * 16) | |
pygame.mixer.music.play() | |
time.sleep(5) | |
camera.Picamera() | |
try: | |
camera.start_preview() | |
time.sleep(10) | |
camera.stop_preview() | |
finally: | |
camera.close() | |
# Connect to the PiBot | |
bot = pibot.PiBot() | |
testStartTime = time.time() | |
while time.time() - testStartTime < TEST_TIME: | |
curTime = time.time() - testStartTime | |
# Set motor speeds | |
if int( curTime )%2 == 0: | |
bot.setMotorSpeeds( 192, -192 ) | |
bot.setStepperSpeed( 255 ) | |
for pixelIdx in range( bot.NUM_NEO_PIXELS ): | |
bot.setNeoPixelColour( pixelIdx, 128, 0, 0 ) | |
else: | |
bot.setMotorSpeeds( -192, 192 ) | |
bot.setStepperSpeed( -255 ) | |
for pixelIdx in range( bot.NUM_NEO_PIXELS ): | |
bot.setNeoPixelColour( pixelIdx, 0, 0, 128 ) | |
# Set servo angle | |
bot.setServoAngle( (curTime / TEST_TIME) * 180.0 ) | |
print "Ultrasonic distance =", bot.getUltrasonicDistance() | |
time.sleep( 0.05 ) | |
for pixelIdx in range( bot.NUM_NEO_PIXELS ): | |
bot.setNeoPixelColour( pixelIdx, 0, 128, 0 ) | |
del bot | |
time.sleep(1) | |
pygame.mixer.music.load( scriptPath + "failure.mp3" ) | |
pygame.mixer.music.set_volume( MUSIC_VOLUME * 4 ) | |
pygame.mixer.music.play() | |
time.sleep(3) | |
pygame.mixer.music.load( scriptPath + "success.mp3" ) | |
pygame.mixer.music.set_volume( MUSIC_VOLUME ) | |
pygame.mixer.music.play() | |
time.sleep(1) | |
pygame.mixer.music.load( scriptPath + "animals023.mp3" ) | |
pygame.mixer.music.set_volume( MUSIC_VOLUME * 16 ) | |
pygame.mixer.music.play() | |
time.sleep(3) | |
pygame.mixer.music.load( scriptPath + "animals023.mp3" ) | |
pygame.mixer.music.set_volume( MUSIC_VOLUME * 16 ) | |
pygame.mixer.music.play() | |
time.sleep(3) | |
while pygame.mixer.music.get_busy(): | |
pass | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env python | |
# test_pibot_hardware.py | |
import time | |
import os.path | |
import sys | |
import pygame | |
import pygame.mixer | |
import pibot | |
MUSIC_VOLUME = 0.5 | |
TEST_TIME = 10.0 | |
scriptPath = os.path.dirname( __file__ ) | |
# Load test result sounds | |
pygame.init() | |
pygame.mixer.init() | |
time.sleep(1) | |
pygame.mixer.music.load( scriptPath + "musical073.mp3" ) | |
pygame.mixer.music.set_volume( MUSIC_VOLUME * 16) | |
pygame.mixer.music.play() | |
time.sleep(7) | |
pygame.mixer.music.load( scriptPath + "drum_roll.mp3" ) | |
pygame.mixer.music.set_volume( MUSIC_VOLUME * 16) | |
pygame.mixer.music.play() | |
time.sleep(5) | |
# Connect to the PiBot | |
bot = pibot.PiBot() | |
testStartTime = time.time() | |
while time.time() - testStartTime < TEST_TIME: | |
curTime = time.time() - testStartTime | |
# Set motor speeds | |
if int( curTime )%2 == 0: | |
bot.setMotorSpeeds( 192, -192 ) | |
bot.setStepperSpeed( 255 ) | |
for pixelIdx in range( bot.NUM_NEO_PIXELS ): | |
bot.setNeoPixelColour( pixelIdx, 128, 0, 0 ) | |
else: | |
bot.setMotorSpeeds( -192, 192 ) | |
bot.setStepperSpeed( -255 ) | |
for pixelIdx in range( bot.NUM_NEO_PIXELS ): | |
bot.setNeoPixelColour( pixelIdx, 0, 0, 128 ) | |
# Set servo angle | |
bot.setServoAngle( (curTime / TEST_TIME) * 180.0 ) | |
print "Ultrasonic distance =", bot.getUltrasonicDistance() | |
time.sleep( 0.05 ) | |
for pixelIdx in range( bot.NUM_NEO_PIXELS ): | |
bot.setNeoPixelColour( pixelIdx, 0, 128, 0 ) | |
del bot | |
time.sleep(1) | |
pygame.mixer.music.load( scriptPath + "failure.mp3" ) | |
pygame.mixer.music.set_volume( MUSIC_VOLUME * 4 ) | |
pygame.mixer.music.play() | |
time.sleep(3) | |
pygame.mixer.music.load( scriptPath + "success.mp3" ) | |
pygame.mixer.music.set_volume( MUSIC_VOLUME ) | |
pygame.mixer.music.play() | |
time.sleep(1) | |
pygame.mixer.music.load( scriptPath + "animals023.mp3" ) | |
pygame.mixer.music.set_volume( MUSIC_VOLUME * 16 ) | |
pygame.mixer.music.play() | |
time.sleep(3) | |
pygame.mixer.music.load( scriptPath + "animals023.mp3" ) | |
pygame.mixer.music.set_volume( MUSIC_VOLUME * 16 ) | |
pygame.mixer.music.play() | |
time.sleep(3) | |
while pygame.mixer.music.get_busy(): | |
pass | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment