handlight_command.py
Go to the documentation of this file.
1 #!/usr/bin/env python
2 
3 # Software License Agreement (BSD License)
4 #
5 # Copyright (c) 2013, Tokyo Opensource Robotics Kyokai Association
6 # All rights reserved.
7 #
8 # Redistribution and use in source and binary forms, with or without
9 # modification, are permitted provided that the following conditions
10 # are met:
11 #
12 # * Redistributions of source code must retain the above copyright
13 # notice, this list of conditions and the following disclaimer.
14 # * Redistributions in binary form must reproduce the above
15 # copyright notice, this list of conditions and the following
16 # disclaimer in the documentation and/or other materials provided
17 # with the distribution.
18 # * Neither the name of Tokyo Opensource Robotics Kyokai Association. nor the
19 # names of its contributors may be used to endorse or promote products
20 # derived from this software without specific prior written permission.
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 # POSSIBILITY OF SUCH DAMAGE.
34 #
35 # Author: Isaac Isao Saito
36 
37 from abs_hand_command import AbsractHandCommand
38 
39 
40 class HandlightCommand(AbsractHandCommand):
41  '''
42  Following Command design pattern, this class represents commands
43  for turning hand lights.
44  '''
45  # TODO: Unittest is needed!!
46 
47  HANDLIGHT_ON = True
48  HANDLIGHT_OFF = False
49 
50  def __init__(self, hands, hand, dio_pins):
51  super(HandlightCommand, self).__init__(hands, hand, dio_pins)
52 
53  def _assign_dio_names(self, dio_pins):
54  '''
55  @see abs_hand_command.AbsractHandCommand._assign_dio_names
56  '''
57  self._DIO_LHAND = dio_pins[0]
58  self._DIO_RHAND = dio_pins[1]
59 
60  def execute(self, operation):
61  '''
62  @see abs_hand_command.AbsractHandCommand.execute
63 
64  @param operation: param type:
65  - 'True': Turn the light on.
66  - 'False': Turn the light off.
67  @rtype: bool
68  @return: True if digital out was writable to the register.
69  False otherwise.
70  '''
71  dout = []
72  mask = []
73  if self.HANDLIGHT_ON == operation:
74  if self._hands.HAND_R == self._hand:
75  dout = mask = [self._DIO_RHAND]
76  elif self._hands.HAND_L == self._hand:
77  dout = mask = [self._DIO_LHAND]
78  elif not self._hand: # Both hands
79  dout = mask = [self._DIO_RHAND, self._DIO_LHAND]
80  else: # Turn off the light.
81  if self._hands.HAND_R == self._hand:
82  mask = [self._DIO_RHAND]
83  elif self._hands.HAND_L == self._hand:
84  mask = [self._DIO_LHAND]
85  elif not self._hand:
86  mask = [self._DIO_RHAND, self._DIO_LHAND]
87  return self._hands._dio_writer(dout, mask)
88 
89  def turn_handlight(self, hand=None, on=True):
90  '''
91  @param hand: Both hands if None.
92  @type on: bool
93  @param on: Despite its type, it's handled as str in this method.
94  @rtype: bool
95  @return: True if the lights turned. False otherwise.
96  '''
97  _result = True
98  if self._hands.HAND_L == hand:
99 # _result = self.execute(on)
100  self.execute(on)
101  _result = False
102  elif self._hands.HAND_R == hand:
103  _result = self.execute(on)
104  elif not hand: # both hands
105  _result = self.turn_handlight(self._hands.HAND_L)
106  _result = self.turn_handlight(self._hands.HAND_R) and _result
107  return _result


nextage_ros_bridge
Author(s): Isaac Isao Saito , Akio Ochiai
autogenerated on Wed Jun 17 2020 04:14:47