Pypot Primitves - PositionWatcher

Hello I want to know if someone could tell me how it works this code. That allosws the robot to do something special?

class PositionWatcher(LoopPrimitive):
    def __init__(self, robot, refresh_freq, watched_motors):
        LoopPrimitive.__init__(self, robot, refresh_freq)

        self._pos = defaultdict(list)
        self.watched_motors = watched_motors
        self._duration = 0.

    @property
    def record_positions(self):
        return deepcopy(self._pos)

    def setup(self):
        self._pos.clear()

    def update(self):
        for m in self.watched_motors:
            self._pos[m.name].append(m.present_position)

        self._duration = self.elapsed_time

   def plot(self, ax):
        for m, pos in self._pos.items():
            t = numpy.linspace(0, self._duration, len(pos))
            ax.plot(t, pos)
        ax.set_ylabel('position (in deg)')
        ax.set_xlabel('time (in s)')
        ax.legend(self._pos.keys(), loc='best')

source: https://poppy-project.github.io/pypot/_modules/pypot/primitive/utils.html#PositionWatcher

Thanks !

Seems to be an object loop primitive to record and graph the position of different motors function of time.

Yes that’s exactly why I’ve written this code for.