[SOLVED] drain CAN bus for specific time period

Discussion on the Lua Scripting capabilities for RaceCapture/Pro. Also see the <a href="http://autosportlabs.net/RaceCapturePro_Lua_Scripting">Lua Scripting Guide</a>

Moderators: JeffC, stieg

Post Reply
thoraxe
Posts: 47
Joined: Wed Dec 14, 2016 2:29 am
Location: Atlanta, GA
Contact:

[SOLVED] drain CAN bus for specific time period

Post by thoraxe »

I've got a number of posts on this topic or related to this topic, so just check my profile.

Background:
Haltech ECU + WBo2
AEM CD7 dashboard
RCP Mk2, firmware 2.13.0

I have a number of the important CAN channels from my ECU mapped in the RCP for logging purposes.

Here's my current script:

https://gist.github.com/thoraxe/8405bcb ... edce87311b

The problem:
If I move the sendGPS/IMU function calls out of the drain (repeat/until) loop, it seems like they basically never happen. My dashboard doesn't seem to ever get GPS data from the RCP. With them inside the loop (as pictured), it seems like some of the channel data ends up getting transmitted very, very slowly. I think because it's actually transmitting GPS data for every single channel it pulled off the buffer.

What I really want:
I want to retransmit a specific subset of CAN channels/messages without having to essentially rebuild the CAN mapping again. In other words, I know that I want to retransmit channel 864, 865, and several others. I've already mapped this data in the RaceCapture app.

I don't want to have to basically re-map it in Lua just to be able to transmit it.

Is there some way to do the following (pseudocode):

Code: Select all

function onTick&#40;&#41;
txcan &#40; rxcan&#40;some specific can message / channel&#41; &#41;
txcan &#40; rxcan&#40;some other specific message / channel&#41; &#41;
sendGPS&#40;&#41;
sendIMU&#40;&#41;
end
I know I can grab mapped channels virtually (getChannel), but my dash is looking for Haltech formatted messages already, so I'd actually have to re-un-format the mapped channel into the Haltech data format, assemble a message from the mapped channels, and then transmit it.

That seems like an atrocious amount of work.

My other and uglier and more physically intensive option is to abandon using the RCP for retransmit and just homerun another CAN cable from the ECU all the way to the dash's other CAN channel. So basically I'd only be sending GPS data from the RCP to the AEM CD7, and the CD7 would pick up all of the other vehicle data directly from the CAN bus.

Thoughts?
Last edited by thoraxe on Fri Mar 16, 2018 7:16 pm, edited 1 time in total.

brentp
Site Admin
Posts: 6274
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

What seems to be happening is that you're receiving data faster than the rxCAN loop can process it, not allowing it to drop into the txGPS / txIMU portion.

What I would do is have it break out of the rxCAN() loop if a certain amount of time has elapsed, so the txGPS and txIMU messages can be handled, then let the onTick() function exit, and let the system call onTick() again, later, to start the process again.

In the past a simple way was to just let rxCAN() drop through if more than N number of messages was received.

If you want to do a time based timeout, you can use the getUptime() function to figure out the timeout:
https://wiki.autosportlabs.com/RaceCapt ... time.28.29

Hope this helps,
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

thoraxe
Posts: 47
Joined: Wed Dec 14, 2016 2:29 am
Location: Atlanta, GA
Contact:

Post by thoraxe »

Yes, this did help.

https://gist.github.com/thoraxe/8405bcb ... edce87311b

This includes a revised version of the script using the uptime to drain for a specific time period.

Later I made a small edit to add a configuration variable (drain_period) and then changed the exit to be dependent on the time period defined.

Ideally I'd like to make this a function of the tickrate (to ensure a fixed drain window). I'll post separately for that.

brentp
Site Admin
Posts: 6274
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

Glad the suggestion worked for you!
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

Post Reply