Access mapped CAN channels via Lua

Discussion on the RaceCapture App - Windows, Android, OSX and Linux.

Moderators: JeffC, stieg

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

Access mapped CAN channels via Lua

Post by thoraxe »

I have some mapped CAN channels that I'd like to be able to try to transmit on another bus. However, these do not currently appear to be available as virtual channels.

What I am trying to do:

Code: Select all

function onTick()
current_foo = getChannel("Foo") -- foo is a mapped CAN channel via the can mapping section of the app
print(current_rpm)
end
The error:

Code: Select all

[lua] Script error: [string "setTickRate(1)..."]:63.0: Virtual channel not found!
Which makes sense. But how do I access these mapped CAN channels inside a script?

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

Post by brentp »

In the 2.13.0 beta firmware we introduced the ability to get a channel value by name in addition to the virtual channel ID created by addChannel().

https://wiki.autosportlabs.com/RaceCapt ... r_name_.29

However, in 2.13.0 this may fail with a fatal lua error if the sample rate falls on a boundary where the sample does not exist in the stream. e.g. requesting a channel value for a slowly sampled channel (1Hz) where you're requesting it at 50Hz. The work around is to set the source sample rate higher or the same as the polling rate (e.g. 50Hz for both)

In the next firmware release (2.13.2) we changed it so it's not a fatal error, but just returns nil if the channel value is not available. The lua script will need to check for a nil response before processing the value.

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 »

brentp wrote:In the 2.13.0 beta firmware we introduced the ability to get a channel value by name in addition to the virtual channel ID created by addChannel().

https://wiki.autosportlabs.com/RaceCapt ... r_name_.29

However, in 2.13.0 this may fail with a fatal lua error if the sample rate falls on a boundary where the sample does not exist in the stream. e.g. requesting a channel value for a slowly sampled channel (1Hz) where you're requesting it at 50Hz. The work around is to set the source sample rate higher or the same as the polling rate (e.g. 50Hz for both)

In the next firmware release (2.13.2) we changed it so it's not a fatal error, but just returns nil if the channel value is not available. The lua script will need to check for a nil response before processing the value.

Hope this helps,
Happy to try the new firmware.

Is there a way to know what the channel ID is for mapped channels?

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

Post by brentp »

Hi - Yes, that is is documented in the wiki link I previously posted.
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 »

brentp wrote:Hi - Yes, that is is documented in the wiki link I previously posted.
I think we're talking past eachother.

getChannel returns the numerical value of the channel referenced.

addChannel gives you a channel ID to use with getChannel.

I am asking:

Is there a way to know the channel ID for the channels in the mapped CAN area? Do the IDs start at 1 from the order of being listed?

I understand I can try the new firmware, but I am curious to know if there's a way to determine the mapped channel numerical ID.

I hope that makes more sense.

Thanks!

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

Post by brentp »

Thanks for the clarification.

When specifying a numeric ID in getChannel(), this is the ID that is provided by addChannel() in Lua. This part of the virtual channel system that exists only in Lua.

For channels defined outside of Lua (analog, CAN mapping, OBDII, etc) you need to specify the channel by name; there is no numeric ID mapping for those channels - you have to know the name of the channel in advance.

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

Post Reply