CAN overload?

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
lpettipa
Posts: 8
Joined: Mon Jan 11, 2016 6:39 pm

CAN overload?

Post by lpettipa »

Hello, see attached script. I'm reading CAN data off bus 0 and 1, and transmitting on bus 1 as well. Bus 1 works fine, bus 0 not so much. I'm using the filters to only allow 3 CAN ID's thru on bus 0, 0x350, 0x359 and 0x340. Here are the rates these ID's are transmitted from the sources:

0x350 - 50hz - logger 1
0x359 - 50hz - logger 1
0x340 - 200hz - ECU 1

When I remove the 0x340 filter, the 0x350 and 0x359 ID transmit and log very nicely. When I add in the 0x340 ID, the 0x340 data looks great, but the other 2 slow down, and randomly get seen at around 1 sample every 5 seconds.

Any thoughts on what is going on here?

I tried 1000hz tickrate as well. Was a little better for the slower ID's, but not right.


Code: Select all

setTickRate&#40;100&#41;

Id1 = addChannel&#40;"throttle1",100,1&#41; 
Id2 = addChannel&#40;"throttle2", 100,1&#41;
Id3 = addChannel&#40;"rpm",100,1&#41;
Id4 = addChannel&#40;"press1",100,1&#41;
Id5 = addChannel&#40;"counter1",100,1&#41;
Id6 = addChannel&#40;"counter2",100,1&#41;
Id7 = addChannel&#40;"press2",100,1&#41;
Id8 = addChannel&#40;"press3",100,1&#41;
Id9 = addChannel&#40;"angle1",100,1&#41;

setCANfilter&#40;1,0,0,0x301,0x1FF&#41;
setCANfilter&#40;0,0,0,0x359,0x1FF&#41;
setCANfilter&#40;0,1,0,0x350,0x1FF&#41;
setCANfilter&#40;0,2,0,0x340,0x1FF&#41;

function onTick&#40;&#41;

  id, ext, data = rxCAN&#40;1,100&#41;
  if  id==0x301 then
    throttle1=&#40;data&#91;1&#93;*256+data&#91;2&#93;&#41;/10
    setChannel&#40;Id1,throttle1&#41; 
    throttle2=&#40;data&#91;3&#93;*256+data&#91;4&#93;&#41;/10
    setChannel&#40;Id2,throttle2&#41;
    rpm_can=&#40;data&#91;5&#93;*256+data&#91;6&#93;&#41;*6
    setChannel&#40;Id3,rpm_can&#41;
    press1=&#40;data&#91;7&#93;*256+data&#91;8&#93;&#41;
    setChannel&#40;Id4,press1&#41;
  end

  id, ext, data = rxCAN&#40;0, 100&#41;
  if  id==0x350 then
    counter1=data&#91;1&#93;
    setChannel&#40;Id5,counter1&#41;
    counter2=data&#91;2&#93;
    setChannel&#40;Id6,counter2&#41; 
  end
  if  id==0x359 then
    press2=data&#91;1&#93;*256+data&#91;2&#93;
    setChannel&#40;Id7,press2&#41; 
    press3=data&#91;3&#93;*256+data&#91;4&#93;
    setChannel&#40;Id8,press3&#41; 
  end
  if id==0x340 then
    angle1=&#40;data&#91;7&#93;*256+data&#91;8&#93;&#41;/10
    setChannel&#40;Id9,angle&#41; 
  end
 
  local tmp1 = getChannel&#40;7&#41;--low boost counter
  local tmp2 = getChannel&#40;8&#41;--hi boost counter
  local tmp3 = math.floor&#40;&#40;getChannel&#40;9&#41;*100&#41;/256/100&#41;--boost L
  local tmp4 = math.floor&#40;&#40;getChannel&#40;9&#41;*100-tmp3*100*256&#41;/100+.5&#41;
  local tmp5 = math.floor&#40;&#40;getChannel&#40;10&#41;*100&#41;/256/100&#41;--boost R
  local tmp6 = math.floor&#40;&#40;getChannel&#40;10&#41;*100-tmp5*100*256&#41;/100+.5&#41;
  local tmp7,tmp8 = math.floor&#40;&#40;getChannel&#40;11&#41;*100&#41;/256/10&#41;--ign
  local tmp8 = math.floor&#40;&#40;getChannel&#40;11&#41;*100-tmp7*10*256&#41;/10+.5&#41;
  local msg = &#123;tmp1,tmp2,tmp3,tmp4,tmp5,tmp6,tmp7,tmp8&#125;
  txCAN&#40;1, 0x302, 0, msg&#41;

end

lpettipa
Posts: 8
Joined: Mon Jan 11, 2016 6:39 pm

Post by lpettipa »

Ok, answering my own question.

Seems that if I use the BMW example script format https://wiki.autosportlabs.com/BMW_E46_CAN , everything works great. I believe the trick is in the code below, on the line that says until msg bigger than 100.

Can not test for real for a few weeks, but a simulation test using my CAN sniffer to send packages at the correct rates to the RCP, all seems to work.

Code: Select all

function processCAN&#40;chan&#41;
    local msg = 0
    repeat
        local id, e, data = rxCAN&#40;chan, 0&#41;
        if id ~= nil then
            local map = CAN_map&#91;id&#93;
            if map ~= nil then
                map&#40;data&#41;         
            end
        end
        msg = msg + 1
    until id == nil or msg > 100
end

rdoherty
Posts: 215
Joined: Fri Mar 08, 2013 3:32 am

Post by rdoherty »

What is most likely happening here is there is too much data being sent over the CAN bus to RCP for it to handle in any 'good' amount of time. That is why there is the limit of 100 messages being processed per tick, so RCP doesn't get bogged down processing thousands of messages.
Ryan Doherty
Autosports Labs

Post Reply