CAN-Bus data logging (was: Custom OBD-II channnels for Miata ND2)

cckcck
edited January 21 in RaceChrono for Android
Hi. I am a new user. I have just started using RCP with an OBDLink LX in my 2019 Miata. I would like to be able to include current gear and brake position in my video overlays. I did some searching but no luck. I found the following, I don't know if it is relevant.

https://docs.google.com/spreadsheets/d/1uqwIMof9DdaEv0EkWHXe70XNGt0FGeDxpbMAgfKbbdk/edit?usp=sharing

Comments

  • The linked document is not custom OBD-II PIDs, but it is CAN-Bus.

    There is a "beta" feature in RaceChrono that will allow you to log data from CAN-Bus messages, using an OBDLink brand reader. It is a bit hidden as it's not properly tested and documented. But I guess there's no reason not to try it as you already have the hardware and reverse engineered CAN-Bus messages. Also this thread could act as draft documentation for the feature, and when complete will be moved to the support section.

    Background

    CAN-Bus is not OBD-II.

    The CAN-Bus is a communication bus in your car, used for electronic controller units (ECU) communicating with each other. Such as RPM value from engine ECU to the gauge cluster, or accelerator pedal position to engine ECU. Most new vehicles have CAN-Bus, it's been used in cars since early(ish) 2000's, and nowadays in motorbikes too.

    For the CAN-Bus messages to be useful, they can be reverse engineered with right tools (not RaceChrono at the moment), or you might find them already reverse engineered by others. Searching the brand specific internet discussion forums are usually good bet. You will need to know the vehicle specific PID numbers, and the message structures such as byte offset and byte length of the piece of data you're after. Also data scale is helpful when creating the equation.

    OBD-II is a diagnostic standard required by law (Europe and USA), used originally for emissions tests. OBD-II can be implemented on top of CAN-Bus or "K-line Bus" for example. Cars sold in Europe and USA since 2001 implement OBD-II, also even some earlier models that were prepared to be sold after 2001. OBD-II is also implemented in motorbikes that meet the EURO5 emissions standard (some other bikes too, but it's kind of rare).

    Setup for CAN-Bus logging using OBDLink reader

    1) Enable "RaceChrono > Settings > Expert settings > Experimental devices"
    2) Add "OBDLink LX/MX/MX+ Bluetooth (CAN-Bus)" from "RaceChrono > Settings > Add other device". Notice do not add it from "Add OBD-II reader", as it will just add an OBD-II reader that will not be used for CAN-Bus.
    3) Now a hidden feature is revealed, you can add CAN-Bus channels in "RaceChrono > Settings > Vehicle profile" screen.

    Adding CAN-Bus channels

    Go to "RaceChrono > Settings > Vehicle profile" and add new CAN-Bus channel. Then fill the fields and save the channel. Then you're ready to test it!

    For example the speed channel from your spreadsheet:
    1) Channel: Speed
    2) PID: 514 (or 0x202)
    3) Equation: In the spreadsheet it says scale 1/160 for MPH. So equation "bytesToUint(raw, 2, 2) / 160.0" would get you MPH. But RaceChrono needs meters per second (m/s), and the original value seems to be (kph with 1/100 scale), so working equation will be "bytesToUint(raw, 2, 2) / 360.0".

    Tutorial on creating these equations: https://racechrono.com/support/equations
  • Thanks. I will give this a try soon.
  • Hi. I finally started to look at this. So far I am getting some data, I'm working on gear. The info in the spreadsheet seems correct, raw values follow the described scheme.

    However it leads to a pretty good test of my binary logic to express it as a formula to map the raw values to actual gear. I think I have it, but maybe there is a bug in rcp parsing, it says 'brackets mismatch' but I don't see how. Here is my gear formula:

    ((G&16)>>4)*1+((G&8)>>3)*2+((((G&16)>>4)^1)&0x1)*((((G&8)>>3)^1)&1)*min(3,max(6,(10-(G&7))))
  • @cck yeah it's a bug in balancing the parentheses. For now use something less complex, I will fix this for the next major version :)
  • I think I found a variation for gear that doesn't trigger the bug.

    On a separate note, brake pressure isn't working at all. Maybe the PID has changed, my car is a 2019 and the spreadsheet is pre-2019 I believe.

Sign In or Register to comment.