Wednesday, 27 January 2016

Sprint one implementation of sound Version 1.7

 Team: PI over Four
Author: David O Mahony
Date: 27/01/2016

INTRODUCTION:
This blog update will detail the current status of the sound set up and implementation of the raspberry pi as it adheres to the lampbotics first sprint. The outline for this sprint concerning the sound is to be able to play sounds that sync up with the movements of the lamp. Version 1.5 of the sound control code works on its own as a standalone implementation for set up. But will likely not alter too much in to being assimilated in to the rest of the project.  The code will set up midpoints on the x and y axis on start up.  When a value comes in for x and y in this case set by the user but in operation will be from the camera. The code will compare the new value to the past values of x and y in the code called pastUP and pastLR. If the new values are different from the old it will play one of four mp3 files. Witch file is played is determent by if the new x or y is greater or smaller than the past versions and updating the past version to the current version setting the new location of the lamp.  The code will then wait one second before going back to the start to recheck for new values of x and y to compare again with the now updated values of PastUP and PastLR.

SETTING UP:
·         Using the following document to help instal drivers needed and how to call sound effects.

·         To get audio out on the audio jack the board must be set up to play only on it. In standard mode its set to auto but is insufficient for set up.

BUGS FOUND:
·         Without the wait the code would run too fast and try to play multiple sound files at once without letting the last one end, thus a wait was needed to slow down the code to allow the sound to play before continuing.

FUTURE WORK:
·         Once known values for the range of x and y are worked out from the camera the code will be updated to include these midpoints.
·         The sound effects currently in play are for test and will later be changed to better match the movement and sync with better efficiency.
·         Waits are set for 1 second will be shorted to the actual length of sound effect
·         Will allow a smarter decision making set up to decide between sound effects

FLOW:
CURRENT VERSION OF CODE:

###################################
## VERSION 1.7                                       #
## CREATED THE 25/1/16                      #
## CREATED BY DAVID O MAHONY #
###################################

#IMPORTED FILES NEEDED
import os
import time
# FOR TESTING SETTING THIS FILES RANDOM VALUES
# TO TEST THESE VALUES WILL BE RECEIVED FROM THE VISION
# TILL THE SOUND WHAT SOUNDS TO PLAY TO MACH MOVEMENTS
PositionX =0;
PositionY =0;

#VALUES THAT TAKES IMPUTED VALUES TO BE COMPARED WITH
#PRESET VALUES
UP = PositionX;
LR = PositionY;

# PAST VALUES WILL BE SET AT MID POINT AT START
# THESE WILL CHANGE WITH EVERY LOOP OF CODE TO
# THE LAST POSITION OF THE LAMP
Pastup = 0;
PastLR = 0;

while True:
    # PRINT FUNCTIONS FOR DEBUG
    #print 'Pastup',Pastup
    #print 'up',UP
   

   
    # X AXIS SOUND FILES CONTROL
    if(UP > Pastup == True):
        ## OS.SYSTEM PLAYS THE SELECTED SOUND FILE
        ## FILE MUST BE IN SAME FOLDER AS CODE
        os.system('mpg123 -q sound1.mp3 &')
        ## SETS PASTUP TO CURRENT VALUE OF UP
        ## THUS CHANGING THE CODE TO BE SET AT THE
        ## CURRENT POSITION OF LAMP
        Pastup = UP
        #delay to stop multiple run through at once
        # set to lengh of sound effect
        time.sleep(1)
  
    elif(UP < Pastup == True):
        os.system('mpg123 -q sound2.mp3 &')
        Pastup = UP
        time.sleep(1)
       
    # Y AXIS SOUND FILES CONTROL
    elif(LR > PastLR == True):
        os.system('mpg123 -q sound3.mp3 &')
        PastLR = LR
        time.sleep(1)
       
    elif(LR < PastLR == True):
        os.system('mpg123 -q sound4.mp3 &')
        PastLR = LR
        time.sleep(1)
  
###################################################
##### END OF CODE FOR SOUND        ################
###################################################


Thanks to Luke and Philip, for helping me understand the syntax need for coding and setting the board to automatically output sound to the audio jack.



David O Mahony entry 3,

No comments:

Post a Comment