linorobot / linorobot2_hardware

Apache License 2.0
94 stars 84 forks source link

port to ESP32 #29

Closed hippo5329 closed 1 year ago

hippo5329 commented 1 year ago

This is a port to ESP32.

  1. The i2cdev and mpu imu are synced to upstream i2cdevlib. The ESP32 needs the updates to work.
  2. The pwm and pcnt (pulse counter) modules of ESP32 are used for motors and encoders.
  3. The micro ros wifi transport support is added to config.
  4. The ArduinoOTA support is added to config.
  5. Build on Humble. Tested on an ESP32DEV kit with MPU6050 and BTS7960 like motor driver using both serial and wifi transport.
hi-techno-barrio commented 1 year ago

Did you experience errors in the ESP32 interrupt in handling the detection of encoder pins switching?. I would suggest the use of RP2040 for a more robust and cost-effective solution for this.

Thanks

On Sun, May 21, 2023 at 10:01 AM hippo5329 @.***> wrote:

This is a port to ESP32.

  1. The i2cdev and mpu imu are synced to upstream i2cdevlib. The ESP32 needs the updates to work.
  2. The pwm and pcnt (pulse counter) modules of ESP32 are used for motors and encoders.
  3. The micro ros wifi transport support is added to config.
  4. The ArduinoOTA support is added to config.
  5. Build on Humble. Tested on an ESP32DEV kit with MPU6050 and BTS7960 like motor driver using both serial and wifi transport.

You can view, comment on, or merge this pull request online at:

https://github.com/linorobot/linorobot2_hardware/pull/29 Commit Summary

File Changes

(15 files https://github.com/linorobot/linorobot2_hardware/pull/29/files )

Patch Links:

— Reply to this email directly, view it on GitHub https://github.com/linorobot/linorobot2_hardware/pull/29, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAWGEKF3EVI44L52RCQBBRTXHFZPPANCNFSM6AAAAAAYJCRVR4 . You are receiving this because you are subscribed to this thread.Message ID: @.***>

hippo5329 commented 1 year ago

Hi Christ,

Yes. I experienced interrupt errors with encoder interrupts on ESP32 in my earlier robot projects. So I switched to the hardware PCNT 64 bits pulse counter of ESP32 with the ESP32Encoder library. It works well. No interrupt for encoder is required.

hippo5329 commented 1 year ago
  1. Revised OTA for build error on Teensy. Force git update.
  2. Add serial buadrate to config.
hippo5329 commented 1 year ago

Withdraw WIFI related patches which are not essential for the ESP32 port. Only the i2cdev updates and key ESP32/encoder changes are required. I will put those auxiliary patches on my master branch.

hi-techno-barrio commented 1 year ago

Hi

This is a good initiative, but you may try RP2040 with the original chips. There is no problem with interrupts with the price and the new embedded wifi module makes more sense for a motor with encoder use.

Thanks

On Sun, May 21, 2023 at 9:38 PM hippo5329 @.***> wrote:

Hi Christ,

Yes. I experienced interrupt errors with encoder interrupts on ESP32 in my earlier robot projects. So I switched to the hardware PCNT 64 bits pulse counter of ESP32 with the ESP32Encoder library. It works well. No interrupt for encoder is required.

— Reply to this email directly, view it on GitHub https://github.com/linorobot/linorobot2_hardware/pull/29#issuecomment-1556183043, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAWGEKHHRA36Y4LPXUOEXHDXHILGTANCNFSM6AAAAAAYJCRVR4 . You are receiving this because you commented.Message ID: @.***>

hippo5329 commented 1 year ago

Thanks for the suggestion of RP2040. I will take a look. However, it might depend. With 700+ Hz encoder pulses per wheel with my current cheap motors, it will generate 2800+ interrupts per seconds for 4WD. With the factory lino_base_config 144000 count per rev, it will be 144000 140 / 60 4 = 1344000 interrupts per seconds for 4WD at full speed. That is a very heavy load for CPU. Maybe the Teensy40/41's dual 600MHz M7 can handle? I don't know. But with ESP32's 64 bits pulse counters hardware, it is just a piece of cake. NO interrupt!

hippo5329 commented 1 year ago

There are two outstanding bug fixes from upstream, which are independent of platforms.

(1) The upstream fix of I2Cdev.cpp, "Remove extra begin/endTransmission calls during reads". commit 98a3b4e. https://github.com/jrowberg/i2cdevlib

(2) The upstream fix of the order to destroy executor and node in destroy_entities(), "Update reconnection example". commit commit 561c615. https://github.com/micro-ROS/micro_ros_arduino

hi-techno-barrio commented 1 year ago

Try Teensy 4.0, what I am referring to is the durability of the used microcontroller. Theoretical specs and reliability are something to consider relating to precision and accuracy albeit the fastest pulse counting.

Just a peso cent :)

Thanks

On Wed, May 24, 2023 at 2:36 AM Thomas Chou @.***> wrote:

Thanks for the suggestion of RP2040. I will take a look. However, it might depend. With 700+ Hz encoder pulses per wheel with my current cheap motors, it will generate 2800+ interrupts per seconds for 4WD. With the factory lino_base_config 144000 count per rev, it will be 144000 140 / 60 4 = 1344000 interrupts per seconds for 4WD at full speed. That is a very heavy load for CPU. Maybe the Teensy40/41's dual 600MHz M7 can handle? I don't know. But with ESP32's 64 bits pulse counters hardware, it is just a piece of cake. NO interrupt!

— Reply to this email directly, view it on GitHub https://github.com/linorobot/linorobot2_hardware/pull/29#issuecomment-1559952588, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAWGEKHLWEHIEQSZ6F5BTQLXHT7TJANCNFSM6AAAAAAYJCRVR4 . You are receiving this because you commented.Message ID: @.***>