[tuxdroid-svn] r4646 - in software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk: execu
Status: Beta
Brought to you by:
ks156
|
From: jerome <c2m...@c2...> - 2009-05-06 15:24:34
|
Author: jerome
Date: 2009-05-06 17:24:20 +0200 (Wed, 06 May 2009)
New Revision: 4646
Modified:
software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk/executables/tuxdroid-gadget-maxlight.py
software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk/resources/gadget.pot
Log:
* improved the light research.
Modified: software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk/executables/tuxdroid-gadget-maxlight.py
===================================================================
--- software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk/executables/tuxdroid-gadget-maxlight.py 2009-05-06 10:33:45 UTC (rev 4645)
+++ software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk/executables/tuxdroid-gadget-maxlight.py 2009-05-06 15:24:20 UTC (rev 4646)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python
# -*- coding: utf-8 -*-
# -----------------------------------------------------------------------------
@@ -33,16 +33,16 @@
- Test if tgp_ip and tgp_port exist
2008/10/03 - version 0.4:
- - Add TTS + Internalization TTS
+ - Add TTS + Internalization TTS
2008/10/03 - version 0.3.1:
- - Add charger test
+ - Add charger test
2008/10/03 - version 0.3:
- - Function stop modified by ks156
+ - Function stop modified by ks156
2008/10/02 - version 0.2:
- - add DEBUG
+ - add DEBUG
2008/10/02 - version 0.1:
- Initial version
@@ -67,44 +67,68 @@
from tuxisalive.api import *
from time import sleep, time
from GadgetHelper import GadgetHelper
-
+import threading
+currentTime = 0;
+
def tuxConnect():
'''
Wait connected
'''
tux.server.autoConnect(CLIENT_LEVEL_RESTRICTED, 'TuxMaxLight', 'tuxdroid-gadget-maxlight')
- tux.server.waitConnected(10.0)
- tux.dongle.waitConnected(10.0)
- tux.radio.waitConnected(10.0)
- return tux.access.waitAcquire(10.0, ACCESS_PRIORITY_NORMAL)
+ tux.server.waitConnected(5.0)
+ tux.dongle.waitConnected(5.0)
+ tux.radio.waitConnected(5.0)
+ return tux.access.waitAcquire(5.0, ACCESS_PRIORITY_NORMAL)
+
+def startSpinning():
+ '''
+ Start tux spinning.
+ '''
+ tux.spinning.leftOn(4.0, speed = SPV_SLOW);
+
def search():
- '''
+ '''
Search maximum light
'''
- l_max = 0 # Light Max
- tux.spinning.leftOnAsync(2.0, speed = SPV_NORMAL)
-
- # Turn on left 2 turns, asynchrone mode
- sleep(1) # wait Tux began to turn
-
- while tux.spinning.getLeftMovingState():
- # While tux spins
- lum = float(tux.status.requestOne('light_level')[0]) # Light
-
- if lum > l_max: # Light Max ?
- l_max = lum // 1
-
- return l_max # Return Light Max
+ l_max = 0 # Light Max
+
+ # Turn on left 2 turns, asynchrone mode
+ thread = threading.Thread(target = startSpinning, args = [])
+ thread.start()
+
+ # wait Tux began to turn
+ sleep(1.0)
+
+ isTurning = tux.status.requestOne(ST_NAME_SPIN_LEFT_MOTOR_ON)[0]
+
+ mutex = threading.Lock()
+
+ while isTurning == "True":
+
+ mutex.acquire()
+ isTurning = tux.status.requestOne(ST_NAME_SPIN_LEFT_MOTOR_ON)[0]
+
+ lum = float(tux.status.requestOne('light_level')[0]) # Light
+
+ sleep(0.25)
+
+ if lum > l_max: # Light Max ?
+ l_max = lum // 1
+
+ sleep(0.25)
+ mutex.release()
+
+ return l_max # Return Light Max
+
-
-def stop(l_stop):
+def stop(l_stop, currentTime):
'''
Tux stop when it finds light up Modified by ks156 who wrote light
monitor gadget for TuxDroid V1 Tux turn a little, wait and turn while light < light max
@@ -113,21 +137,26 @@
sleep(1)
while 1:
- print(time())
+
tux.spinning.leftOnDuring(0.1, speed=1)
sleep(0.3)
lum = float(tux.status.requestOne('light_level')[0])
-
+
if lum >= l_stop:
tux.spinning.off()
break
+ #if (int(time()) - currentTime) >= 15:
+ #break;
+
+ currentTime = int(time())
+
GadgetHelper.throwMessage("I think most of the light is coming from this direction.")
tgp_language = "en"
tgp_ip = "127.0.0.1"
-tgp_port = 270
+tgp_port = 270
if "tgp_language" in os.environ:
@@ -155,7 +184,8 @@
tux.eyes.open()
tux.flippers.up()
light = search() # search light up
- stop(light) # stop
+ currentTime = int(time())
+ stop(light, currentTime) # stop
tux.flippers.down()
tux.access.release()
Modified: software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk/resources/gadget.pot
===================================================================
--- software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk/resources/gadget.pot 2009-05-06 10:33:45 UTC (rev 4645)
+++ software_suite_v2/software/gadgets/tuxdroid-gadget-maxlight/trunk/resources/gadget.pot 2009-05-06 15:24:20 UTC (rev 4646)
@@ -11,6 +11,7 @@
msgstr ""
msgid "I can't find my fish. Please, make sure I'm connected."
+msgstr ""
msgid "Looking for the brightest light source"
msgstr ""
|