RegisterSearchFAQMemberlistUsergroupsLog in
Reply to topic Page 1 of 1
BUG: nil in Lua script for CAN signal rates < 50Hz
Author Message
Reply with quote
Post BUG: nil in Lua script for CAN signal rates < 50Hz 
Trying to troubleshoot my Lua script I figured out that there is a 'nil' error for CAN signal rates less than 50Hz.

So, when I try to print a variable using the command:
Code:
println('rev: ' ..getChannel("rev"))

It only prints when the CAN signal rate is set to 50Hz.
If I change the rate to 25Hz then I get sporadic nils
Quote:
rev: 0.0
[lua] Script error: [string "batt_u_warn = 11..."]:59.0: attempt to concatenate a nil value
rev: 0.0
rev: 0.0
rev: 0.0
rev: 0.0
[lua] Script error: [string "batt_u_warn = 11..."]:59.0: attempt to concatenate a nil value
rev: 0.0
rev: 0.0
rev: 0.0
rev: 0.0
[lua] Script error: [string "batt_u_warn = 11..."]:59.0: attempt to concatenate a nil value


When I change to 10Hz (or lower) then I get the constant error:

Quote:
[lua] Script error: [string "batt_u_warn = 11..."]:59.0: attempt to concatenate a nil value
[lua] Failure: Runtime Error


TickRate doesn't seem to influence the behavior. I tried with TickRate of 1, thinking maybe it has to be equal to the refresh rate of the lowest CAN signal rate, which was 1Hz (temperatures don't change that quickly....) but that didn't seem to make a difference.

Temporary workaround for my display issue is to set the CAN signal rate to 50Hz for all variables used in the Lua script.

View user's profile Send private message
Reply with quote
Post  
Hi, this is expected behavior - it is not guaranteed to return a current value; you will need to check for nil before using the value.

See the note here: https://wiki.autosportlabs.com/RaceCapturePro_Lua_Scripting#getChannel.28_Channel_ID_or_name_.29


_________________
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Reply with quote
Post  
@brentp thanks for the response. However, this isn't how I expect it should work. CAN works on a buffer principle, last value is inherently held in the buffer until a new value comes in and overwrites the old value. That's how the hardware works. So as long as one single valid value was received, Lua should never return a nil.

I can prove this because the update rate on some of the CAN messages I'm using is 25ms, which is 40Hz. Setting the CAN sampling rate in RCPro to 50Hz means it's inherently sampling a stale value for a small period of time.

Sounds like there is a timing mismatch / module sync bug between CAN and Lua.

Since CAN inherently holds the last value in buffer until a new one comes in I'm hoping this is a relatively simple problem to resolve.

View user's profile Send private message
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum