German Larrain avatar German Larrain committed 9e038b0

robot.sensors: separated 'SignalSensor' in 'BaseSignalSensor' and 'SingleSignalSensor'

Comments (0)

Files changed (1)

ars/model/robot/sensors.py

 		return self._source
 
 
-class SignalSensor:
+class BaseSignalSensor:
+
+	"""Base class for sensors that handle signals with :meth:`on_send`."""
+
 	__metaclass__ = ABCMeta
 	
 	any_sender = dispatcher.Any
 
 	@abstractmethod
-	def __init__(self, signal, sender=any_sender, autotime=False):
-		""" 
-		:param signal: signal to subscribe to
+	def __init__(self, sender=any_sender, autotime=False):
+		"""Constructor.
+
 		:param sender: object that will send the signal; if it is
 			:attr:`any_sender`, subscription will be to any object
 		:param autotime: if True and :meth:`_get_time` is not overriden, every
 			measurement's time will set to the computer time in that instant
 		
 		"""
-		self._signal = signal
 		self._sender = sender
 		self._autotime = autotime
 		
-		# subscribe :meth:`on_send` handler to the signal sent by ``sender``
-		dispatcher.connect(self.on_send, signal=self._signal,
-			sender=self._sender)
 		self.data_queue = SensorDataQueue()
 
 	def on_send(self, sender, *args, **kwargs):
 		return self._sender
 
 
+class SingleSignalSensor(BaseSignalSensor):
+
+	"""Abstract base class for sensors subscribed to one signal."""
+
+	__metaclass__ = ABCMeta
+
+	@abstractmethod
+	def __init__(self, signal, *args, **kwargs):
+		"""Constructor.
+
+		:param signal: signal to subscribe to
+
+		"""
+		super(SingleSignalSensor, self).__init__(*args, **kwargs)
+		self._signal = signal
+
+		# subscribe :meth:`on_send` handler to the signal sent by ``sender``
+		dispatcher.connect(self.on_send, signal=self._signal,
+			sender=self._sender)
+
+
 class BodySensor(Sensor):
 	__metaclass__ = ABCMeta
 
 		return SensorData(**kwargs)
 
 
-class JointTorque(SignalSensor):
+class JointTorque(SingleSignalSensor):
 	
 	signal = signals.JOINT_POST_ADD_TORQUE
 	
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.