By analyzing the CANbus of my motorbike, I located the speed data byte (sent by the ABS module).
The message ID 0x268 is sent every 10 ms and the Byte n.2 is the speed, but....
It takes the values 0, 1, 2, 3, .... which correspond to 0, 18, 36, 54, .... [km/h].
Now, the passage from one speed to another value is determined by the frequency of the respective raw data.
Example:
9 km/h (18/2) is obtained by alternating every 10ms the value 0 and 1.
If the 1s increase compared to the 0s, the speed increases and if they are only 1 to reaches 18 (threshold speed for raw data 1).
32 km/h is obtained by alternating more values 2 to the values 1.
Can you help me figure out how to get a formula for correct decoding?
I attach a log file of this message.
Raw speed data starts at about 12,000 milliseconds. I was standing still before.
log1_speed_csv.txt (363.8 KB)
(updated)
Raw data of B2 column
Take the average of the last 10 (or 20) measurements.
This will give a smoother graph of the speed
more points in the running average will result in a higher resolution,
but it will react slower on changes in speed.
(and yes you have to multiply the running average by 18 km/h of course)
As 1 = 18 km per hour,
you need to have a running average buffer of 18 to get a 1km/h resolution..
Hi @robtillaart,
thanks...I'll try your library!
Hi @robtillaart,
i have tested your library. It's perfect for this
.
I have only an issue using it.
Board: ESP32-WROOM-32
run onReceive()
function on Core 1
to receive canbus messages.
when I receive 0x268 (every 10ms), add the value and get average speed:
RunningAverage speedRA(18);
....
....
speedRA.addValue(value * 18.0f);
speed = round(speedRA.getFastAverage());
.....
.....
Completely randomly, the ESP32 resets.
It can happen after 50 seconds or after a few seconds.
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.
Core 1 register dump:
PC : 0x40085e60 PS : 0x00050631 A0 : 0x800ece44 A1 : 0x3ffc10ac
A2 : 0x00000040 A3 : 0x00018040 A4 : 0x000637ff A5 : 0x3ffc108c
A6 : 0x3ffc5998 A7 : 0x3ffc6520 A8 : 0x800984dc A9 : 0x40098252
A10 : 0x3ffdc900 A11 : 0x00000000 A12 : 0x800ece50 A13 : 0x3ffc106c
A14 : 0x3ffc5998 A15 : 0x3ffbfabc SAR : 0x0000000a EXCCAUSE: 0x0000001c
EXCVADDR: 0x800ece50 LBEG : 0x400850fd LEND : 0x40085105 LCOUNT : 0x00000027
Backtrace: 0x40085e5d:0x3ffc10ac |<-CORRUPTED
Unfortunately I can't decode the error because it is corrupted.
I also tried the individual functions but it's the same.
I also slowed down the reading every 100ms, 150ms, 300ms but nothing.
speedRA.addValue(MsgRX[2] * 18.0f);
// speed = round(speedRA.getFastAverage());
Do you have any suggestions ?
Good to hear the library works well (except ...)
Without code it is hard to say what is happening.
One thing, keep your onReceive() function as minimal as possible.
@robtillaart
Solved!
It was a low memory issue for the main task loop()
.
1 Like