neurogears / vestibular-vr

Closed-loop VR setup for Rancz Lab
2 stars 0 forks source link

Conversion between encoder HARP data and real units #80

Open RoboDoig opened 1 month ago

RoboDoig commented 1 month ago

Need to understand how the encoder value from HARP H2 can be converted to a real-world angle.

RoboDoig commented 1 month ago

Some references here for the conversion: The motor and encoder: https://www.omc-stepperonline.com/nema-23-closed-loop-stepper-motor-3-0nm-424oz-in-encoder-1000ppr-4000cpr-23hs45-4204d-e1000 The driver: https://www.ebay.co.uk/itm/203328514020?chn=ps&_ul=GB&_trkparms=ispr%3D1&amdata=enc%3A1cFLpOBQ0S3SeFd65lPxyRA15&norover=1&mkevt=1&mkrid=710-134428-41853-0&mkcid=2&mkscid=101&itemid=203328514020&targetid=2425733423477&device=c&mktype=pla_with_promotion&googleloc=9045997&poi=&campaignid=21697391927&mkgroupid=162558106770&rlsatarget=pla-2425733423477&abcId=10027104&merchantid=6995734&gad_source=1&gclid=Cj0KCQjwr9m3BhDHARIsANut04Yqzr46MGG2AlwQP8V43PSc80ZSB8CLXb9xzI55z6gSlySU2LqunjAaAh_XEALw_wcB The encoder decoding approach: https://ww1.microchip.com/downloads/en/AppNotes/00002434A.pdf

RoboDoig commented 1 month ago

Application note for the specific chip on H2: https://ww1.microchip.com/downloads/aemDocuments/documents/OTH/ApplicationNotes/ApplicationNotes/doc8109.pdf

RoboDoig commented 1 month ago

Confirmed with @EleonoraAmbrad today, the signal from H2 comes from the decoded quadrature counts from the chip's integrated decoder. Datasheet for the encoder says 4000 counts per revolution, confirmed that the main shaft turns a complete revolution for every 4000 units in Bonsai.

To convert this to main platform angle we need to know effective gear ratio between main shaft and platform.

RoboDoig commented 1 month ago

Hi @ederancz, @EleonoraAmbrad - following our conversation on Monday, can I mark this issue as closed?

To clarify the main points from Monday:

  1. We have established that the gear ratio between the motor drive and the platform is 6:1
  2. We have established based on the encoder data sheet and a practical test that the encoder reports its values in counts, and there are 4000 counts per revolution.
  3. The motor driver is set to 6400 pulses per revolution. We established, by using the H2 feature that allows us to set an absolute pulse count, that 64006 (drive PPR gear ration) pulses produces a full rotation of the platform.
  4. In closed loop mode we are writing immediate pulses (instantaneous pulse period) rather than an absolute count of pulses. One can estimate the pulse count (and therefore angle turn command) in postprocessing by analyzing the timestamped HARP write command on immediate pulses, and the time period between these write commands.
ederancz commented 1 month ago

Hi @EleonoraAmbrad , can you please get Iakov to check the encoder counts and motor pulses from the recording? If memory serves, there was 1 full motor rotation (6400 pulses) followed by 2x1 full platform rotation (38400 pulses). So the encoder reading should be 4000 and 24000. If it adds up (±0.1%), you can close the issue.

ikharitonov commented 1 month ago

Hi @RoboDoig , has this recording been saved? We could not locate it with Nora

RoboDoig commented 1 month ago

Ah sorry I didn't fully parse the last message from @ederancz .

We did the test on a minimal debug workflow with no logging so nothing was recorded, we were just monitoring the visualizers.

RoboDoig commented 1 month ago

The workflow we used is called DirectPulsesTest.bonsai. It just writes the desired pulses (6400) to the motor driver on a key press. If you want to record you could just dump the H2 events to a binary file with MatrixWriter. Interpreting the encoder value should be straightforward. For the motor pulses, you will get a HARP timestamped event when the number of pulses is written (register 33) though you already know how many pulses were written as it's set in that workflow directly.

EleonoraAmbrad commented 1 month ago

I will do that on Monday together with the motion cloud test!

RoboDoig commented 2 weeks ago

@EleonoraAmbrad I updated DirectPulsesTest.bonsai to log data - in the ae-dev branch