Author: ks156
Date: 2009-04-07 08:50:17 +0200 (Tue, 07 Apr 2009)
New Revision: 4375

Added:
   software_suite_v2/software/scripts/skeleton/
   software_suite_v2/software/scripts/skeleton/branches/
   software_suite_v2/software/scripts/skeleton/tags/
   software_suite_v2/software/scripts/skeleton/trunk/
   software_suite_v2/software/scripts/skeleton/trunk/prog_skeleton_tux.py
Log:
* Added a script skeleton made by Skapin Gaelle.
  
  Many thanks to him for this useful skeleton. It contains all the callback 
  functions you may need for your scripts. Don't forget to remove / comment 
  them if you don't need them.
  
  You can read his original message in the community forum at :
  http://bbs.tuxisalive.com/viewtopic.php?id=46


Added: software_suite_v2/software/scripts/skeleton/trunk/prog_skeleton_tux.py
===================================================================
--- software_suite_v2/software/scripts/skeleton/trunk/prog_skeleton_tux.py      
                        (rev 0)
+++ software_suite_v2/software/scripts/skeleton/trunk/prog_skeleton_tux.py      
2009-04-07 06:50:17 UTC (rev 4375)
@@ -0,0 +1,577 @@
+#!/usr/bin/python
+# -*- coding: UTF8 -*-
+
+"""
+    Tux Droid - Programm skeleton for tux interaction
+    Copyright (C) 2008 Gaelle Largeteau <glargeteau _at_ yahoo _dot_ fr>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2, or (at your option)
+    any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+"""
+
+#replace all fields by your data (but keep the GPL licence)
+__author__  = 'Gaelle Largeteau-skapin <glargeteau _at_ yahoo _dot_ fr>'
+__appname__ = 'Programm skeleton'
+__version__ = '1.0.0'
+__date__    = '2009/01/12'
+__license__ = 'GPL'
+
+
+
+#----------------------------------------------------------------------
+#                            DESCRIPTION
+#----------------------------------------------------------------------
+# put here the description of your programm
+
+
+# Here is the skeleton of a programm for tuxdroid interaction.
+# replace the print instructions by your own code
+# comment out the callbacks and the lines in the main part you dont need
+
+# Ce programme est le squelette d'un programme pour interagir avec tuxdroid
+# il suffit de remplacer les print par votre propre code
+# n'oubliez pas de mettre en commentaire les callbacks 
+# et les lignes servant à les lier
+# dans la partie principale
+
+# I hope this will help beginers to programm their tuxdroid
+# j'espere que cela aidera les débutants à programmer leur tux droid.
+
+
+#---------------------------------------------------------------------
+#        IMPORT LIBRARIES
+#---------------------------------------------------------------------
+# here are the calssical useful libraries
+
+from sys import *
+path.append('/opt/tuxdroid/api/python/')
+
+# to interact with Tux
+# pour interagir avec Tux
+from tuxisalive.api import *
+
+# For the thread we need
+import threading
+
+
+# for url oppening
+# pour ouvrir des url
+from urllib2 import *
+
+# for regular expression
+# pour les expression reguliere
+from re import *
+
+#----------------------------------------------------------------------
+#   GLOBAL VARIABLES
+#----------------------------------------------------------------------
+# definition and initialisations of global variables
+
+# var out allows to break the waiting event loop in the main part
+# it is turn to 0 in the myStandbyCallback function
+# la variable out sert à couper la boucle d'attente d'evenement
+# elle est mise a 0 lorsqu'on appuie sur standby pour arreter ce programme
+global out
+out=1
+
+# move_lock is a semaphore for the wings mouvement access
+# I don't know if this realy works, 
+# can possibly be replace by a class like the speakThread class
+global moveWingsLock
+moveWingsLock=threading.RLock()
+
+# rotate_lock is a semaphor for the rotation
+global moveRotLock
+moveRotLock=threading.RLock()
+
+#-------------------------------------------------------------------------------------------
+#                      AUX FUNCTIONS
+#-------------------------------------------------------------------------------------------
+# where we define auxilaries functions
+# ici on definit les fonctions auxiliaires
+
+
+#------------------------------------
+#       SAY
+#------------------------------------
+# here is a very useful class to make tux speak 
+class SpeakThread(threading.Thread):
+     def __init__(self, TextToSay,Speaker,Pi):
+          threading.Thread.__init__(self)
+          self.text = TextToSay
+          self.loc = Speaker
+          self.pitch = Pi
+     def run(self):
+         # Here is the code that runs when the function say is called
+
+          tux.mouth.open()
+          if tux.access.waitAcquire(10.0, ACCESS_PRIORITY_NORMAL):
+               tux.tts.speak(self.text,self.loc,self.pitch)
+               tux.access.release()
+          tux.mouth.close()
+          return
+
+def say(param_text):
+     # locutor must be in ["Bruno","Julie"] for french 
+     # and ["Ryan","Heather"] for english
+     local_locutor="Julie"
+
+     # Pitch can modulate the voice and must be in 50..200
+     local_pitch=150
+
+     saythread = SpeakThread(param_text,local_locutor,local_pitch)
+     saythread.start()
+
+#----------------------------------------------
+#   EXAMPLES OF TUX MOVES
+#-------------------------------------------------
+#for an exaustive list see the API (http://doc.tuxisalive.com/api/python/)
+# I haven't try all of these so there migth be some errors left
+
+def wingsup():
+     global moveWingsLock
+     say("wings UP")
+     moveWingsLock.acquire()
+     # speed in (1|2|3|4|5) from vey slow to very fast
+     tux.flippers.on(1,finalState="UP",speed=1)
+     move_lock.release()
+    
+def wingsdown():
+     global moveWingsLock
+     say("wings DOWN")
+     move_wings_lock.acquire()
+     tux.flippers.on(1,finalState="DOWN",speed=1)
+     move_wings_lock.release()
+
+def turnleft():
+    global moveRotLock
+    # rotation to the left
+    # rotation vers la gauche
+
+    # speed in (1|2|3|4|5) from vey slow to very fast
+    # time_duration : float : rotation duration in second, durée de la 
rotation en seconde
+    speed=3
+    nb_rotation=2,0
+
+    moveRotLock.aquire()
+    tux.spinning.leftOnDuring(5,0,speed)
+    moveRotLock.release()
+    
+    
+def blink_movnt():
+    # eye mouvements
+    # number= mouvnt num, FinalState is the final desired state in 
(NDEF|OPEN|CLOSE)
+    number=4
+    tux.eyes.on(number, FinalState='OPEN')
+
+
+def led_blink_alter():
+    # leds actions
+    speed=3
+    count=5
+    transtype='LFX_NONE'
+    tux.led.left.blink(speed,count,transtype)
+    tux.led.right.blink(speed,count,transtype)
+
+    # speed in (1|2|3|4|5) from vey slow to very fast
+    # transtype in (LFX_NONE|LFX_FADE|LFX_STEP)
+
+    tux.led.both.blink(3,4,0,'LFX_FADE')
+
+#--------------------------------------------------------------------------------
+#    WakeUp and ShutDown
+#--------------------------------------------------------------------------------
+# my personnal function to say hello and goodbye
+
+def WakeUp():
+     tux.led.both.on()
+     tux.eyes.open()
+     tux.mouth.close()
+     time.sleep(1)
+     tux.mouth.open()
+     time.sleep(1) 
+     tux.mouth.close() 
+     say("bonjour")    
+   
+def ShutDown():
+    tux.tts.stop()
+    say("aurevoir")
+    tux.mouth.close()
+    tux.eyes.close()
+    tux.led.both.off()
+#----------------------------------------------------------------------------------
+#                        CALLBACK FUNCTION(S)
+#----------------------------------------------------------------------------------
+# Callback functions are those that are related to button event
+
+# les callback sont les fonctions qui sont liée aux 
+# évenements sur les boutons
+
+#!!!!!!!!!!!!!!!!!!!!!!!!!ATTENTION!!!!!!!!!!!!!!!!!!!!!!!!
+# DO NOT FORGET TO COMMENT OUT THE CALLBACKS YOU DON'T NEED
+# AND THE RELATED LINES IN THE MAIN PART
+#
+# WHEN YOU BIND A CALLBACK TO AN EVENT 
+# IT REPLACE IT'S DEFAULT/PREVIOUS BEHAVIOR
+#
+
+
+# !!!!!!!!!!!!!!!!!!!ATTENTION!!!!!!!!!!!!!!!!!!
+# N'OUBLIEZ PAS DE COMMENTER LES CALLBACK DONT VOUS N'AVEZ PAS BESOIN
+# ET LES LIGNES QUI LEUR CORRESPONDENT DANS LA PARTIE PRINCIPALE
+#
+# LORSQU'ON RELIE UNE CALLBACK A UN EVENEMENT, CELA REMPLACE LE
+# COMPORTEMENT PRECEDENT/PAR DEFAUT
+
+#---------------------------------------------------------------
+#                   REMOTE PART
+#---------------------------------------------------------------
+# I haven't put all of the possible remote button event
+# but i think it's sufficient for a beginning
+
+def myStandbyCallback(*args):
+    # function performed when remote Standby button is pressed
+    # this function can do something else if the exit 
+    # is done in the myStandbyCallback_released function
+    # function executée lorsque le bouton K_STANDBY est appuyé
+    # cette fonction peut faire autrechose que quitter 
+    # si la sortie est faite dans la fonciton myStandbyCallback_released
+    global out
+    
+    print "This is The End, My Friend"
+    say("This is The End, My Friend")
+    out=0
+
+def myK1Callback(*args):
+    #function performed when remote K1 button is pressed
+    print "K1 pushed"
+    say("K1 pushed")
+
+def myK_OKCallback(*args):
+    #function performed when remote K_OK button is pressed
+    print "OK pushed"
+    say("OK pushed")
+
+def mySTOPCallback(*args):
+    #function performed when remote K_STOP button is pressed
+    print "STOP pushed"
+    say("STOP pushed")
+
+def myPREVCallback(*args):
+    #function performed when remote K_PREVIOUS button is pressed
+    print "PREV pushed"
+    say("PREV pushed")
+
+def myNEXTCallback(*args):
+    #function performed when remote K_NEXT button is pressed
+    print "NEXT pushed"
+    say("NEXT pushed")
+
+def myPAUSECallback(*args):
+    #function performed when remote K_PLAYPAUSE button is pressed
+    print "PLAYPAUSE pushed"
+    say("PLAYPAUSE pushed")
+
+def myUPCallback(*args):
+    #function performed when remote K_UP button is pressed
+    print "UP pushed"
+    say("UP pushed")
+
+def myDOWNCallback(*args):
+    #function performed when remote K_DOWN button is pressed
+    print "DOWN pushed"
+    say("DOWN  pushed")
+
+def myK_HANGUPCallback(*args):
+    #function performed when remote K_HANGUP button is pressed
+    print "K_HANGUP pushed"
+    say("K_HANGUP  pushed")
+
+def myK_RECEIVECALLCallback(*args):
+    #function performed when remote K_RECEIVECALL button is pressed
+    print "K_RECEIVECALL pushed"
+    say("K_RECEIVECALL  pushed")
+
+def myK_REDCallback(*args):
+    #function performed when remote K_RED button is pressed
+    print "K_RED pushed"
+    say("K_RED  pushed")
+
+def myK_GREENCallback(*args):
+    #function performed when remote K_GREEN button is pressed
+    print "K_GREEN pushed"
+    say("K_GREEN  pushed")
+    
+def myK_BLUECallback(*args):
+    #function performed when remote K_GREEN button is pressed
+    print "K_BLUE pushed"
+    say("K_BLUE  pushed")
+
+
+def myK_YELLOWCallback(*args):
+    #function performed when remote K_YELLOW button is pressed
+    print "K_YELLOW pushed"
+    say("K_YELLOW  pushed")
+
+def myK_RIGHTCallback(*args):
+    #function performed when remote K_RIGHT button is pressed
+    print "K_RIGHT pushed"
+    say("K_RIGHT  pushed")
+
+def myK_LEFTCallback(*args):
+    #function performed when remote K_LEFT button is pressed
+    print "K_LEFT pushed"
+    say("K_LEFT  pushed")
+
+def myK_STARTVOIPCallback(*args):
+    #function performed when remote K_STARTVOIP button is pressed
+    print "K_STARTVOIP pushed"
+    say("K_STARTVOIP  pushed")
+
+#-----------------------------------------------------------------
+# button released part
+# those release callbacks aren't bind in the main part
+# uncomment related lines in the principal part to use them
+    
+def myStandbyCallback_released(*args):
+    # Function performed when remote Standby button is released
+    # Be aware that this function is only usefull 
+    # if the myStandbyCallback doesn't set variable out to 0
+    # function executée lorsque le bouton K_STANDBY est relaché 
+    # cette fonction n'est utile que si la fonction myStandbyCallback 
+    # ne met pas la variable out à 0
+    global out
+    print "This is The End, My Friend"
+    say("This is The End, My Friend")
+    out=0
+   
+
+def myK1Callback_released(*args):
+    #function performed when remote K1 button is released
+    print "K1 released"
+    say("K1 released")
+
+def myK_OKCallback_released(*args):
+    #function performed when remote K_OK button is released
+    print "OK released"
+    say("OK released")
+
+def mySTOPCallback_released(*args):
+    #function performed when remote K_STOP button is released
+    print "STOP released"
+    say("STOP released")
+
+def myPREVCallback_released(*args):
+    #function performed when remote K_PREVIOUS button is released
+    print "PREV released"
+    say("PREV released")
+
+def myNEXTCallback_released(*args):
+    #function performed when remote K_NEXT button is released
+    print "NEXT released"
+    say("NEXT released")
+
+def myPAUSECallback_released(*args):
+    #function performed when remote K_PLAYPAUSE button is released
+    print "PLAYPAUSE released"
+    say("PLAYPAUSE released")
+
+def myUPCallback_released(*args):
+    #function performed when remote K_UP button is released
+    print "UP released"
+    say("UP released")
+
+def myDOWNCallback_released(*args):
+    #function performed when remote K_DOWN button is released
+    print "DOWN released"
+    say("DOWN  released")
+
+def myK_HANGUPCallback_released(*args):
+    #function performed when remote K_HANGUP button is released
+    print "K_HANGUP released"
+    say("K_HANGUP released")
+
+def myK_RECEIVECALLCallback_released(*args):
+    #function performed when remote K_RECEIVECALL button is released
+    print "K_RECEIVECALL released"
+    say("K_RECEIVECALL  released")
+
+def myK_REDCallback_released(*args):
+    #function performed when remote K_RED button is released
+    print "K_RED released"
+    say("K_RED  released")
+
+def myK_GREENCallback_released(*args):
+    #function performed when remote K_GREEN button is released
+    print "K_GREEN released"
+    say("K_GREEN  released")
+    
+def myK_BLUECallback_released(*args):
+    #function performed when remote K_BLUE button is released
+    print "K_BLUE released"
+    say("K_BLUE  released")
+
+def myK_YELLOWCallback_released(*args):
+    #function performed when remote K_YELLOW button is released
+    print "K_YELLOW released"
+    say("K_YELLOW  released")
+
+def myK_RIGHTCallback_released(*args):
+    #function performed when remote K_RIGHT button is released
+    print "K_RIGHT released"
+    say("K_RIGHT  released")
+
+def myK_LEFTCallback_released(*args):
+    #function performed when remote K_LEFT button is released
+    print "K_LEFT released"
+    say("K_LEFT  released")
+
+def myK_STARTVOIPCallback_released(*args):
+    #function performed when remote K_STARTVOIP button is released
+    print "K_STARTVOIP released"
+    say("K_STARTVOIP  released")
+
+    
+#--------------------------------------------------------------------------------
+#       HEAD, WINGS
+#-------------------------------------------------------------------------------
+#pressed
+def myHeadCallback(*args):
+    #function performed when head button is pressed
+    print "head pushed"
+    say("HEAD  pushed")
+
+def myLeftWingCallback(*args):
+    #function performed when Left wing button is pressed
+    print "left wing pushed"
+    say("LEFT WING  pushed")
+    
+def myRightWingCallback(*args):
+    #function performed when Right Wing button is pressed
+    print "right wing pushed"
+    say("RIGHT WING pushed")
+
+#released
+def myheadcallback_released(*args):
+    #function performed when head button is released
+    print "head released"
+    say("HEAD  released")
+
+def myLeftWingCallback_released(*args):
+    #function performed when Left wing button is released
+    print "left wing released"
+    say("LEFT WING  released")
+    
+def myRightWingCallback_released(*args):
+    #function performed when Right Wing button is released
+    print "right wing released"
+    say("RIGHT WING released")
+
+#--------------------------------------------------------------
+#                   MAIN PART     
+#--------------------------------------------------------------    
+
+#---------CONNEXION------------
+#replace progSkeleton by your own programm name
+tux = TuxAPI('127.0.0.1', 270)
+tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'progSkeleton', 'NONE')
+tux.server.waitConnected(10.0)
+tux.dongle.waitConnected(10.0)
+tux.radio.waitConnected(10.0)
+
+if tux.access.waitAcquire(10.0, ACCESS_PRIORITY_NORMAL):
+    WakeUp()
+    #here we bind callbacks with events on buttons
+    #ici on relie les callbacks aux evenement sur les boutons
+    
+    # !!!DON'T FORGET TO COMMENT OUT THE LINES YOU DON'T NEED
+    # AND BE AWARE THAT IF YOU BIND A CALLBACK TO AN EVENT 
+    # THE PREVIOUS BEHAVIOR IS REPLACED
+    # (NOT DEFINITLY, DON'T PANIC, ONLY TILL THE END OF THIS PROGRAMM, 
+    # PRESS STANDBY AND BREATHE)
+    # I KNOW I'VE ALREADY SAID THAT A MILLION TIME BUT
+    # JUST DON'T FORGET!
+    # IF YOUR EMAIL ARE NO LONGER CHECKED I WILL REPLY "NOT WY FAULT!"
+
+    # !!!N'OUBLIEZ PAS DE COMMENTER LES LIGNES DONT VOUS N'AVEZ PAS BESOIN
+    # SI VOUS LIEZ UNE CALLBACK A UN EVENEMENT, LE COMPORTEMENT PRECEDENT EST 
REMPLACE
+    # (PAS DEFINITIVEMENT, NE PANIQUEZ PAS, APPUYEZ SUR STANDBY ET RESPIREZ)
+    # SIMPLEMENT N'OUBLIEZ PAS !
+    # SI VOS EMAIL NE SONT PLUS VERIFIES, JE REPONDRAIS "PAS MA FAUTE!"
+
+    
+    #------------REMOTE 
PART---------CALLBACK-----------------------------------------
+    #pressed
+    tux.button.remote.registerEventOnPressed(myStandbyCallback,K_STANDBY)
+    tux.button.remote.registerEventOnPressed(myK1Callback,K_1)
+    tux.button.remote.registerEventOnPressed(myK_OKCallback,K_OK)
+    tux.button.remote.registerEventOnPressed(mySTOPCallback,K_STOP)
+    tux.button.remote.registerEventOnPressed(myPREVCallback,K_PREVIOUS)
+    tux.button.remote.registerEventOnPressed(myNEXTCallback,K_NEXT)
+    tux.button.remote.registerEventOnPressed(myPAUSECallback,K_PLAYPAUSE)
+    tux.button.remote.registerEventOnPressed(myUPCallback,K_UP)
+    tux.button.remote.registerEventOnPressed(myDOWNCallback,K_DOWN)
+    tux.button.remote.registerEventOnPressed(myK_HANGUPCallback,K_HANGUP)
+    
tux.button.remote.registerEventOnPressed(myK_RECEIVECALLCallback,K_RECEIVECALL)
+    tux.button.remote.registerEventOnPressed(myK_REDCallback,K_RED)
+    tux.button.remote.registerEventOnPressed(myK_GREENCallback,K_GREEN)
+    tux.button.remote.registerEventOnPressed(myK_BLUECallback,K_BLUE)
+    tux.button.remote.registerEventOnPressed(myK_YELLOWCallback,K_YELLOW)
+    tux.button.remote.registerEventOnPressed(myK_RIGHTCallback,K_RIGHT)
+    tux.button.remote.registerEventOnPressed(myK_LEFTCallback,K_LEFT)
+    tux.button.remote.registerEventOnPressed(myK_STARTVOIPCallback,K_STARTVOIP)
+
+
+    #-------------------------------------------------------------
+    # released part
+    # 
tux.button.remote.registerEventOnReleased(myStandbyCallback_released,K_STANDBY)
+    # tux.button.remote.registerEventOnReleased(myK1Callback_released,K_1)
+    # tux.button.remote.registerEventOnReleased(myK_OKCallback_released,K_OK)
+    # tux.button.remote.registerEventOnReleased(mySTOPCallback_released,K_STOP)
+    # 
tux.button.remote.registerEventOnReleased(myPREVCallback_released,K_PREVIOUS)
+    # tux.button.remote.registerEventOnReleased(myNEXTCallback_released,K_NEXT)
+    # 
tux.button.remote.registerEventOnReleased(myPAUSECallback_released,K_PLAYPAUSE)
+    # tux.button.remote.registerEventOnReleased(myUPCallback_released,K_UP)
+    # tux.button.remote.registerEventOnReleased(myDOWNCallback_released,K_DOWN)
+    # 
tux.button.remote.registerEventOnReleased(myK_HANGUPCallback_released,K_HANGUP)
+    # 
tux.button.remote.registerEventOnReleased(myK_RECEIVECALLCallback_released,K_RECEIVECALL)
+    # tux.button.remote.registerEventOnReleased(myK_REDCallback_released,K_RED)
+    # 
tux.button.remote.registerEventOnReleased(myK_GREENCallback_released,K_GREEN)
+    # 
tux.button.remote.registerEventOnReleased(myK_BLUECallback_released,K_BLUE)
+    # 
tux.button.remote.registerEventOnReleased(myK_YELLOWCallback_released,K_YELLOW)
+    # 
tux.button.remote.registerEventOnReleased(myK_RIGHTCallback_released,K_RIGHT)
+    # 
tux.button.remote.registerEventOnReleased(myK_LEFTCallback_released,K_LEFT)
+    # 
tux.button.remote.registerEventOnReleased(myK_STARTVOIPCallback_released,K_STARTVOIP)
+    
+    #----HEAD--WINGS-------------CALLBACK------------------------------------
+    # pressed
+    tux.button.head.registerEventOnPressed(myHeadCallback)
+    tux.button.left.registerEventOnPressed(myLeftWingCallback)
+    tux.button.right.registerEventOnPressed(myRightWingCallback)
+
+    # released
+    # tux.button.head.registerEventOnReleased(myHeadCallback_released)
+    # tux.button.left.registerEventOnReleased(myLeftWingCallback_released)
+    # tux.button.right.registerEventOnReleased(myRightWingCallback_released)
+
+    #------WAITING EVENT LOOP------------------------
+    while out == 1:
+        time.sleep(1)
+
+    
+    # END OF THE APPLICATION
+    ShutDown()
+
+#----DISCONNECTION--------------------
+tux.access.release()
+tux.server.disconnect()
+tux.destroy()
+
+#----END-OF THE SCRIPT-------------------


Property changes on: 
software_suite_v2/software/scripts/skeleton/trunk/prog_skeleton_tux.py
___________________________________________________________________
Name: svn:executable
   + *
Name: svn:mime-type
   + text/x-python
Name: svn:keywords
   + Id


------------------------------------------------------------------------------
This SF.net email is sponsored by:
High Quality Requirements in a Collaborative Environment.
Download a free trial of Rational Requirements Composer Now!
http://p.sf.net/sfu/www-ibm-com
_______________________________________________
Tux-droid-svn mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/tux-droid-svn

Reply via email to