arduino-RaceChrono icon indicating copy to clipboard operation
arduino-RaceChrono copied to clipboard

Include support for ESP32 boards

Open jawillis opened this issue 2 years ago • 10 comments

Added support for ESP32 boards. Tested using a RejsaCAN ESP32 v2.3. Only one line needs to be changed in RaceChronoDiyBleDevice which refers directly to the bluefruit library. The only testing performed has been rudimentary, so this PR is mainly for comments while I prove it further.

jawillis avatar Jul 10 '22 04:07 jawillis

Just a quick note on throughput. I played with the updateRateDivider today and got roughly 5x the message rate I was able to get with the ItsyBitsy nRF52840. The best I could do with the ItsyBitsy was ~10Hz as reported by RaceChrono for 4 CAN ID's. I was able to crank the ESP32 up to 50-70Hz for 5 CAN ID's.
I have an idea for a method to define aggregate messages in the vehicle-specific header files to get the most out of the available bandwidth, but that will come much later.

jawillis avatar Jul 11 '22 05:07 jawillis

Awesome news, thanks!

I also was thinking about a way to define an "aggregate" message, let me know if you prefer me to just bite the bullet and do it, or you can't wait to take care of it yourself.

timurrrr avatar Jul 11 '22 05:07 timurrrr

I also was thinking about a way to define an "aggregate" message, let me know if you prefer me to just bite the bullet and do it, or you can't wait to take care of it yourself.

I don't have a burning desire to implement aggregate messages, but I'm willing to take a stab at it. The next item on my list of "wants" is analog input support using an ADS1115 or similar. The ESP32 ADCs are 3.2V only and non-linear.

jawillis avatar Jul 11 '22 06:07 jawillis

Gotcha! I suggest you focus on the analog inputs, and I hope to get to tinker with aggregate messages in the next few weeks. The data from my GR86 has an ever so slightly lower refresh rate than I want, so this was something I wanted to do anyways.

timurrrr avatar Jul 11 '22 06:07 timurrrr

Gotcha! I suggest you focus on the analog inputs, and I hope to get to tinker with aggregate messages in the next few weeks. The data from my GR86 has an ever so slightly lower refresh rate than I want, so this was something I wanted to do anyways.

You could always load this build up on one of those boards Magnus sent you ;)

jawillis avatar Jul 11 '22 06:07 jawillis

During testing I encountered a bug where RaceChrono showed low rates and an incomplete channel list when starting a session with the car already running.
Disconnecting/reconnecting the CANbus (or turning the car off/on) without stopping the session remedied the issue and RaceChrono started showing all channels at expected rate.
Do you have any ideas what might be going on? Serial output is below:

Connected.
Connecting to the CAN bus...
Success!
Command: DENY ALL PIDS.
Current state of the PID map:
  No PIDs are allowed.

Command: ALLOW PID 496 (0x1F0), requested update interval: 50 ms.
Current state of the PID map:
  496 (0x1F0), sending 1 out of 2 messages.

Command: ALLOW PID 339 (0x153), requested update interval: 50 ms.
Current state of the PID map:
  339 (0x153), sending 1 out of 2 messages.
  496 (0x1F0), sending 1 out of 2 messages.

Command: ALLOW PID 1555 (0x613), requested update interval: 50 ms.
Current state of the PID map:
  339 (0x153), sending 1 out of 2 messages.
  496 (0x1F0), sending 1 out of 2 messages.
  1555 (0x613), sending 1 out of 5 messages.

Command: ALLOW PID 501 (0x1F5), requested update interval: 50 ms.
Current state of the PID map:
  339 (0x153), sending 1 out of 2 messages.
  496 (0x1F0), sending 1 out of 2 messages.
  501 (0x1F5), sending 1 out of 2 messages.
  1555 (0x613), sending 1 out of 5 messages.

WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
Command: ALLOW PID 1557 (0x615), requested update interval: 50 ms.WARNING: Receive buffer overflow, dropping one message.

WARNING: Receive buffer overflow, dropping one message.
Current state of the PID map:
  339 (0x153), sending 1 out of 2 messages.
  496 (0x1F0), sending 1 out of 2 messages.
  501 (0x1F5), sending 1 out of 2 messages.
  1555 (0x613), sending 1 out of 5 messages.
  1557 (0x615), sending 1 out of 5 messages.

WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
Command: ALLOW PID 1349 (0x545), requested update interval: 50 ms.
Current state of the PID map:
  339 (0x153), sending 1 out of 2 messages.
  496 (0x1F0), sending 1 out of 2 messages.
  501 (0x1F5), sending 1 out of 2 messages.
  1349 (0x545), sending 1 out of 100 messages.
  1555 (0x613), sending 1 out of 5 messages.
  1557 (0x615), sending 1 out of 5 messages.

WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
Command: ALLOW PID 790 (0x316), requested update interval: 50 ms.
WARNING: Receive buffer overflow, dropping one message.
Current state of the PID map:
  339 (0x153), sending 1 out of 2 messages.
  496 (0x1F0), sending 1 out of 2 messages.
  501 (0x1F5), sending 1 out of 2 messages.
  790 (0x316), sending 1 out of 2 messages.
  1349 (0x545), sending 1 out of 100 messages.
  1555 (0x613), sending 1 out of 5 messages.
  1557 (0x615), sending 1 out of 5 messages.

WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
Command: ALLOW PID 809 (0x329), requested update interval: 50 ms.
WARNING: Receive buffer overflow, dropping one message.
Current state of the PID map:
  339 (0x153), sending 1 out of 2 messages.
  496 (0x1F0), sending 1 out of 2 messages.
  501 (0x1F5), sending 1 out of WARNING: Receive buffer overflow, dropping one message.
2 messages.
  790 (0x316), sending 1 out of 2 messages.
  809 (0x329), sending 1 out of 2 messages.
  1349 (0x545), sending 1 out of 100 messages.
  1555 (0x613), sending 1 out of 5 messages.
  1557 (0x615), sending 1 out of 5 messages.

WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.
WARNING: Receive buffer overflow, dropping one message.

jawillis avatar Jul 11 '22 06:07 jawillis

You could always load this build up on one of those boards Magnus sent you ;)

Totally, but I also want to squeeze every bit of performance from nRF if I can :)

RaceChrono showed low rates and an incomplete channel list when starting a session with the car already running.

Not off the top of my head. Might be a bug in how requested channels got initialized, or might even be a RaceChrono bug...

timurrrr avatar Jul 11 '22 07:07 timurrrr

I'm pretty stumped with the refactor. C++ is not my main language, so it's been fairly slow going. I think I'm almost there, I'm just having an issue with the handler function. I'm hesitant to check it in to this PR, so I've put it in a different branch here

jawillis avatar Jul 19 '22 05:07 jawillis

I did a quick scan, looks promising!

If it makes your life easier, you can start by keeping the ESP32-related additions local, and start the PR with nRF52-only refactoring. You can start by:

  1. Creating src/RaceChronoNRF52.h by copying (git cp) the old src/RaceChrono.h
  2. Adding a bunch of virtual <...> = 0; to src/RaceChrono.h and removing the definitions of class fields
  3. Renaming src/RaceChrono.cpp to src/RaceChronoNRF52.cpp

That should work?

timurrrr avatar Jul 26 '22 07:07 timurrrr

Apologies for the delayed reviews, I was traveling last couple of weekends, and was swamped with tasks (at work and otherwise) when I came back.

timurrrr avatar Jul 26 '22 07:07 timurrrr

Sorry I haven't been responsive here. I've been poking at the refactor here and there but I keep getting frustrated with declaring the CAN handler. I'll get there. On the plus side, I have implemented OTA updates over wifi in the main app (for esp32).

jawillis avatar Aug 10 '22 22:08 jawillis

I ended up doing some refactor myself in aedc9b41c73e99dbd4f05292e5dbf4154d9f0bf0, please take a look. Hopefully it is a good example of how ESP32 support could work.

In fact, now that I've started, maybe I'll find some time to do add ESP32 support this weekend myself.

timurrrr avatar Aug 14 '22 05:08 timurrrr

That looks great! I can try to work from there if you like (assuming you didn't get it done over the weekend), or just let you take the reins.

jawillis avatar Aug 15 '22 23:08 jawillis

Sorry, I had some issues with my ESP32 hardware on the weekend (turned out my two RejsaCAN boards were dead on arrival!), but I was still able to make some progress.

Check out d5f397a31e7364a99c4e2596e7702bb475f2ac66! I've only done some basic tests, so it most likely has bugs. I'm going to close this PR, but please please give this new version a try and send me new PRs with fixes for whatever bugs you'll find!

timurrrr avatar Aug 16 '22 06:08 timurrrr

And again thanks a lot for your help figuring out how to add this support!

timurrrr avatar Aug 16 '22 06:08 timurrrr

Ah sorry I've meant 7899d636d83533257843dbb6307e143217a8a7ac

timurrrr avatar Aug 16 '22 06:08 timurrrr

I'll load this build this weekend and give it a try!

jawillis avatar Aug 16 '22 06:08 jawillis