Source code for sic_framework.devices.common_naoqi.pepper_top_tactile_sensor

from sic_framework import SICComponentManager, SICConfMessage, SICMessage, utils
from sic_framework.core.component_python2 import SICComponent
from sic_framework.core.connector import SICConnector

if utils.PYTHON_VERSION_IS_2:
    import qi
# 

[docs] class PepperTactileSensorMessage(SICMessage):
[docs] def __init__(self, value): """ Contains a value of 1, indicating tactile was touched. http://doc.aldebaran.com/2-5/naoqi/sensors/altouch-api.html?highlight=middletactiltouched#MiddleTactilTouched """ super(PepperTactileSensorMessage, self).__init__() self.value = value
[docs] class PepperTopTactileSensor(SICComponent): """ PepperTopTactileSensor is a sensor that reads the robot's physical button and touch values from the ALMemory module. """
[docs] def __init__(self, *args, **kwargs): super(PepperTopTactileSensor, self).__init__(*args, **kwargs) self.session = qi.Session() self.session.connect("tcp://127.0.0.1:9559") # Connect to AL proxies self.memory_service = self.session.service("ALMemory") self.ids = []
[docs] @staticmethod def get_conf(): return SICConfMessage()
[docs] @staticmethod def get_inputs(): return []
[docs] @staticmethod def get_output(): return PepperTactileSensorMessage
[docs] def onTouchChanged(self, value): self.output_message(PepperTactileSensorMessage(value))
[docs] def start(self): super(PepperTopTactileSensor, self).start() self.touch = self.memory_service.subscriber('MiddleTactilTouched') id = self.touch.signal.connect(self.onTouchChanged) self.ids.append(id)
[docs] def stop(self, *args): """ Stop the Pepper top tactile sensor. """ for id in self.ids: self.touch.signal.disconnect(id) self.session.close() self._stopped.set() super(PepperTopTactileSensor, self).stop()
[docs] class PepperTopTactile(SICConnector): component_class = PepperTopTactileSensor
if __name__ == "__main__": SICComponentManager([PepperTopTactileSensor])