pybricks / support

Pybricks support and general discussion
MIT License
107 stars 6 forks source link

Add motor calibration feature. #343

Open dlech opened 3 years ago

dlech commented 3 years ago

Is your feature request related to a problem? Please describe. Some LEGO Powered Up motors need to have the zero position calibrated. The LEGO MINDSTORMS app can do this, but other apps for other hubs don't have this feature yet.

Describe the solution you'd like It would be nice if we had a script that we could copy and paste into Pybricks Code to to the calibration.

Describe alternatives you've considered For people with a MINDSTORMS or SPIKE hub, they can just use the MINDSTORMS app.

Additional context Related thread: https://github.com/pybricks/support/discussions/334#discussioncomment-760049

JorgePe commented 3 years ago

For people with a MINDSTORMS or SPIKE hub, they can just use the MINDSTORMS app.

Currently, the MINDSTORMS App does not recognize Large Angular Motors (either SPIKE white/blue or Technic grey) as motors that support calibration.

dlech commented 3 years ago

Here is a capture of the calibration procedure from the MINDSTORMS software. The motor is "reset" by stopping UART comms, then it is allowed to come up at 2400 baud rather than doing the initial 115200 baud setting. Then the baud rate is changed to 4800 baud. The the interesting stuff happens at 4800 baud. After the last write at 4800 baud, the hub switches back to 2400 baud but it takes the motor a while to reset again.

The attached data just contains the messages during the 4800 baud portion. I haven't really looked at it yet, so if someone wants to have some fun decoding the write messages, go for it.

Mode 4 is the CALIB mode. According to info reported by the sensor the DATA messages in this mode are supposed to be 2 16-bit integers. After a a certain WRITE command though the DATA changes to a 32-byte payload.

motor-calibration.csv

dlech commented 3 years ago

It looks like it goes something like this:

Finally, stop sending NACKs to allow motor to resync at higher baud rate.

dlech commented 3 years ago

So there appear to be 5 different "commands"

Reading and writing DATA probably reads/writes starting at the address specified in the 0x02 command.

dlech commented 3 years ago

Same CSV with additional columns for DATA messages:

motor-calibration.csv