How to implement the motor encoder function in Microblocks?

Issue #536 open
梁帅 created an issue

Hi John,

I’m Liang Shuai. I am currently adding motor encoder functionality to CoCube.
Two years ago, I asked you how to use encoders in Microblocks, but recently I found it difficult to monitor the motor's speed in real time (how many pulse signals there are within a certain period of time). For example, when the motor is not running, the wait until block will block and the speed cannot be calculated.

https://bitbucket.org/john_maloney/smallvm/issues/319/can-microblocks-support-interrupts

I saw in the VM source code that you added the Signal Capture function in sensorPrims.cpp, but there seems to be no usage case yet.

Is there any good way to achieve the expected functionality?

Thanks!

Comments (4)

  1. John Maloney repo owner

    You're correct, MicroBlocks is not yet using the signal capture primitives in any libraries or projects. That feature is intended to capture a sequence of pulses from sensors such as the DT-11 and DT-22 when heavy Bluetooth and WiFi traffic makes it difficult to measure short pulse times accurately with a MicroBlocks script.

    It's an interesting idea to use that feature for motor decoding.

    One limitation is that the feature currently can only record a pulse sequence from one pin at a time. For a robot, I imagine you'd want to track the speed of two to four motors. To do that, the feature would need to be extended to support multiple pins.

    You might explore using that feature to track a single motor. If that works well, we could look into extending the support to at least two pins.

    How fast are the pulses from your motor encoder at maximum motor speed?

  2. 梁帅 reporter

    The pulses are about 800Hz at maximum motor speed.

    I just tried to migrate the code I previously wrote to the Microblocks program, and it is feasible.

  3. Log in to comment