Page 1 of 1

I seem to have disabled all channels

Posted: Tue Feb 24, 2015 10:26 pm
by zandr
In the course of writing some Lua to map CAN data to virtual channels, I seem to have disabled all data. I don't even see battery voltage in the dashboard now. I'm sure this is something simple that I've done, but I don't see it.

Here's the code:

Code: Select all

setTickRate(30)

function c2f (c)
  return (c*1.8)+32
end

function k2m (k)
  return (k*0.62137)
end

initCAN(0,500000)

coolantId = addChannel("Coolant", 10)
oilId = addChannel("OilTemp", 10)
throttleId = addChannel("TPS", 10) 
brakeId = addChannel("Brake", 10) 
wheelId = addChannel("Wheel", 10)
wheel1Id = addChannel("Wheel1", 10)
wheel2Id = addChannel("Wheel2", 10)
wheel3Id = addChannel("Wheel3", 10)
wheel4Id = addChannel("Wheel4", 10)
rpmId = addChannel("RPM", 10)
clutchId = addChannel("Clutch", 10)
fuelId = addChannel("FuelLevel", 10)
steerId = addChannel("Steering", 10)


CANIds = {
  [339] = function (data)
    vss = (((data[3])*256)+(data[2]%16))/8
    mph = k2m(vss)
    setChannel(wheelId, mph)
  end,    
  [496] = function (data) end,
  [499] = function (data) end,
  [501] = function (data) 
    if data[2] > 127 then
      steer = -1*(((data[2]-128)*256)+data[1])
    else
      steer = (data[2]*256)+data[1]
    end
    setChannel(steerId, steer)
  end,
  [790] = function (data)
    rpm = (data[4]*256)+data[3]
    setChannel(rpmId, rpm)
  end,
  [809] = function (data)
    tempC = (data[2] * 0.75) - 48
    tempF = c2f(tempC)
    setChannel(coolantId, tempF)

    throttle = data[6]/256
    setChannel(throttleId, throttle)

    clutch = data[4]
    setChannel(clutchId, clutch)

    brake = data[7]
    setChannel(brakeId, brake)
  end,
  [1349] = function (data)
    tempC = data[5] - 48
    tempF = c2f(tempC)
    setChannel(oilId, tempF)
  end,
  [1552] = function (data) end,
  [1555] = function (data)
    fuel = (data[3]%128)/58
    setChannel(fuelId, fuel)
  end,
  [1557] = function (data) end
}

function onTick()
  repeat
    id, ext, data = rxCAN(0)
    CANIds[id](data)
  until id == nil
end

Posted: Tue Feb 24, 2015 10:29 pm
by brentp
Thanks -

Basic troubleshooting: I would recommend removing the script to prove basic functionality is restored, then re-incorporate your script gradually until you see something not work.

I'd help more if I had that CAN datastream to work with too. :)