[tuxdroid-svn] r843 - api/python/trunk
Status: Beta
Brought to you by:
ks156
From: Paul_R <c2m...@c2...> - 2008-01-11 13:06:56
|
Author: Paul_R Date: 2008-01-11 14:06:55 +0100 (Fri, 11 Jan 2008) New Revision: 843 Modified: api/python/trunk/tuxapi_class.py api/python/trunk/tuxapi_const.py Log: * Added a new command : tux.cmd.move - Created constants on tuxapi_const.py Modified: api/python/trunk/tuxapi_class.py =================================================================== --- api/python/trunk/tuxapi_class.py 2008-01-11 13:03:00 UTC (rev 842) +++ api/python/trunk/tuxapi_class.py 2008-01-11 13:06:55 UTC (rev 843) @@ -1756,6 +1756,7 @@ tux.cmd.mouth_on tux.cmd.mouth_on_free tux.cmd.mouth_open + tux.cmd.move tux.cmd.ping tux.cmd.raw tux.cmd.sleep_off @@ -1892,7 +1893,99 @@ return 2 else: return self.cmd_ack() + + #-------------------------------------------------------------------------- + # Send a command to make move Tux. + #-------------------------------------------------------------------------- + def move(self, movement, counter=0, timeout=0, speed=5, final_state=0, refresh=0): + """ + General command to move Tux. + With this command, you can configure, for each type of movements, the + number of movements to do, or the duration of the movement. + You can also specify the final state to reach. + + Parameters : + "movement" as enum : Specify which movement must be configured + - 0 / EYES + - 1 / MOUTH + - 2 / FLIPPERS + - 3 / SPIN_L + - 4 / SPIN_R + "counter" as integer : Specify the number of movements. + To execute an infinite movement, this value + must be equal to 0. The timeout must also be + null, and the final state must stay undefined. + + To execute a single movement, count must be + null and a final state must be defined. + + value range : 0 ... 255 (0x00 ... 0xFF) + + "timeout" as float : Specify the duration of the movement (sec.) + This value has priority on counter. It means + that if counter and timeout are both defined, + the counter's value will be ignored. + + The minimal value is 0.01 (10 ms). + + If the value is lower than 0.3 (300 ms), the + final state will be ignored. Else, the final + state will be applied, so the time can be a + little bit greater than specified. + + "speed" as enum : This value specify the movement speed. + This parameter is only applicable for the + flippers and the spinning. + + - 1 / VERYLOW + - 2 / LOW + - 3 / MEDIUM + - 4 / MIDHIGH + - 5 / HIGH + + If speed is not defined, the default speed + (HIGH) will be used. + + "final_state" as enum : Specify the final state. + + - 0 / UNDEFINED + - 1 / OPEN / UP + - 2 / CLOSE / DOWN + + "refresh" as bool : Change speed only. + If this flag is set, only the speed will be + changed. This allow to change the speed during + a movement, without changing the number of + movements, or the timeout. + + Examples : + + Blink the eyes 7 time, and finish with the eyes open : + >>> tux.cmd.move(0, 7, 0, 0, 1, 0) + or + >>> tux.cmd.move(movement = EYES, counter = 7, final_state = 1) + + Move wings for 150ms with the maximum speed: + >>> tux.cmd.move(2, 0, 0.15, 5, 0, 0) + or + >>> tux.cmd.move(movement = FLIPPERS, timeout = 0.15, speed = 5) + + Infinite spinning, and change the speed : + >>> tux.cmd.move(3, 0, 0, 5, 0, False) + >>> tux.cmd.move(3, 0, 0, 2, 0, True) + or + >>> tux.cmd.move(movement = SPIN_L, speed = HIGH) + >>> tux.cmd.move(movement = SPIN_L, speed = LOW, refresh = True) + """ + if timeout: + if timeout <= 1.0/100.0: + timeout = 1.0/100.0 + timeout = timeout * 100.0 + + self.last_ack=self.estructured(TUX_CMD_STRUCT_MOTORS, movement, counter, \ + (int(timeout) & 0xFF00)>>8, (int(timeout) & 0xFF), speed, \ + final_state, int(refresh)) #-------------------------------------------------------------------------- # Send a command to tux for moving the eyes #-------------------------------------------------------------------------- Modified: api/python/trunk/tuxapi_const.py =================================================================== --- api/python/trunk/tuxapi_const.py 2008-01-11 13:03:00 UTC (rev 842) +++ api/python/trunk/tuxapi_const.py 2008-01-11 13:06:55 UTC (rev 843) @@ -297,6 +297,7 @@ TUX_CMD_STRUCT_PING = 0x0B TUX_CMD_STRUCT_SLEEP = 0x0C TUX_CMD_STRUCT_AUDIO_CHANNEL = 0x0D +TUX_CMD_STRUCT_MOTORS = 0x0E # Tux structured sub commands TUX_CMD_STRUCT_SUB_ON = 0x01 TUX_CMD_STRUCT_SUB_OFF = 0x02 @@ -316,6 +317,7 @@ TUX_CMD_STRUCT_SUB_ERASE = 0x0E TUX_CMD_STRUCT_SUB_SET = 0x0F TUX_CMD_STRUCT_SUB_PULSE = 0x10 +TUX_CMD_STRUCT_SUB_CONFIG = 0x11 # Tux request information TUX_REQ_INFO_VERSION = 0x01 @@ -457,6 +459,25 @@ NONE_BT =0 NULL_BT =0xFF +## tux.cmd.move function constant +EYES = 0 +MOUTH = 1 +FLIPPERS = 2 +SPIN_L = 3 +SPIN_R = 4 + +UNDEFINED = 0 +OPEN = 1 +UP = 1 +CLOSE = 2 +DOWN = 2 + +VERYLOW = 1 +LOW = 2 +MEDIUM = 3 +MIDHIGH = 4 +HIGH = 5 + HEAD_BUTTON_PUSHED =1 HEAD_BUTTON_RELEASED =2 LEFT_WING_PUSHED =3 |