Discussion on Emotion encoder implementation: issues with Mockup controller
By looking at the Mockup
controller code, one realises a problem with "perfect" encoders, that is, those with no measured_noise
. The first time the encoder is read the result is properly calculated, storing the result in the internal steps
encoder cache. The readings performed after that will always return the same value, independently of any motor movement.
This is easily demonstrable by modifying the test_encoder_move
sequence in the motors/TestEncoder.py
unittest
, either by reading the encoder position before the movement:
def test_encoder_move(self):
m0 = bliss.get_axis("m0")
self.assertAlmostEquals(m0.position(), m0.encoder.read(), places=4)
m0.move(5)
self.assertAlmostEquals(m0.position(), m0.encoder.read(), places=4)
or by moving the motor twice:
def test_encoder_move(self):
m0 = bliss.get_axis("m0")
m0.move(5)
self.assertAlmostEquals(m0.position(), m0.encoder.read(), places=4)
m0.move(10)
The following unittest
is proposed, including both sequences:
def test_encoder_move(self):
m0 = bliss.get_axis("m0")
self.assertAlmostEquals(m0.position(), m0.encoder.read(), places=4)
m0.move(5)
self.assertAlmostEquals(m0.position(), m0.encoder.read(), places=4)
m0.move(10)
self.assertAlmostEquals(m0.position(), m0.encoder.read(), places=4)
A second problem is identified with the Encoder.set
semantics. The sequence in test_maxee
:
def test_maxee(self):
...
enc.set(2)
m0.move(2)
self.assertEquals(m0.position(), 2)
is not very intuitive. Emotion ignores the encoder position before the movement, assuming that it agrees with the motor position (which is not always true), and only checks its value at the end. If the Mockup
implementation emulates an incremental encoder, the motor should move ~3 units in the negative direction (initial position being ~5), so the encoder should end close to -1, raising an end-of-movement discrepancy
exception. If the Mockup
emulates an absolute encoder, it should rise an exception when set
is called.
Waiting for a more coherent encoder management in Emotion, the Mockup
implementation should rise an exception if the encoder is set to a position outside the vicinity of the current position
defined by the tolerance
parameter.