RegisterSearchFAQMemberlistUsergroupsLog in
Reply to topic Page 1 of 1
Hondata Script error - addChannel "Speed"
Author Message
Reply with quote
Post Hondata Script error - addChannel "Speed" 
I copied the Hondata script provide in the wiki which seems to work.

I tried to add a channel to pull speed from the Hondata CAN and I receive an error with the defining the Speed Addchannel command.

---I am receiving the error below.
Startup script error: ([string "..."]:21.0: attempt to call global 'addchannel' (a nil value))
Failure: Failed to load script.

If I omit the spdId definition the script runs with no problems.


Below is the script used, copy from Wiki page, only added the Speed channel variable and callout.




--This example adopted to Hondata KPro4 CAN output

tickRate = 30
--the CAN baud rate
CAN_baud = 250000
--CAN channel to listen on. 0=first CAN channel, 1=second
CAN_chan = 0

--add your virtual channels here
rpmId = addChannel("RPM_", 25, 0, 0, 9000, "RPM")
vltId = addChannel("EcuVolts_", 10, 1, 0, 20, "volts")
iatId = addChannel("IAT_", 1, 0, 0, 100, "F")
ectId = addChannel("EngTemp_", 1, 0, 0, 150, "F")
tpsId = addChannel("TPS_", 10, 0, 0, 100, "%")
mapId = addChannel("MAP_", 10, 2, -15, 25, "PSI")
injId = addChannel("InjPW_", 10, 3, 0, 100, "ms")
ignId = addChannel("Ign_", 10, 0, -20, 20, "D")
lmdId = addChannel("AFR_", 10, 3, 0, 2, "lambda")
knkId = addChannel("Knock_", 1, 0, 0, 15, "count")
camId = addChannel("CamTime_", 10, 0, -20, 20, "D")
spdId = addchannel("Speed_", 25, 0, 0, 200, "kph")

function toF(value)
return value * 1.8 + 32
end

function toAFR(value)
return value * 14.7
end

function toMPH(value)
return value * 0.62137119223733
end

--customize here for CAN channel mapping
--offset/length in bytes?
--format is: [CAN Id] = function(data) map_chan(<channel id>, data, <CAN offset>, <CAN length>, <multiplier>, <adder>)
CAN_map = {
--did not bother logging gear speed and target cam angle
--added Speed to 1632.
[1632] = function(data) map_chan(rpmId, data, 0, 2, 1, 0) map_chan(vltId, data, 5, 1, 0.1, 0) map_chan(spdId, data, 2, 2, 1, 0, toMPH) end,

[1633] = function(data) map_chan(iatId, data, 0, 2, 1, 0, toF) map_chan(ectId, data, 2, 2, 1, 0, toF) end,
[1634] = function(data) map_chan(tpsId, data, 0, 2, 1, 0) map_chan(mapId, data, 2, 2, 0.0145037738, -14.7) end,
[1635] = function(data) map_chan(injId, data, 0, 2, 0.001, 0) map_chan(ignId, data, 2, 2, 1, 0) end,
[1636] = function(data) map_chan(lmdId, data, 0, 2, 0.00003051757, 0, toAFR) end,
[1637] = function(data) map_chan(knkId, data, 0, 2, 1, 0) end,
[1638] = function(data) map_chan(camId, data, 2, 2, 1, 0) end
}

function onTick()
processCAN(CAN_chan)
processLogging()
end

function processLogging()
if getGpio(1) < 1 then
startLogging()
else
stopLogging()
end
end

--===========do not edit below===========
function processCAN(chan)
repeat
local id, e, data = rxCAN(chan)
if id ~= nil then
local map = CAN_map[id]
if map ~= nil then
map(data)
end
end
until id == nil
end

--Map CAN channel, big endian format
function map_chan(cid, data, offset, len, mult, add, filter)
offset = offset + 1
local value = 0
while len > 0 do
value = (value * 256) + data[offset]
offset = offset + 1
len = len - 1
end
local cv = value * mult + add
if filter ~= nil then cv = filter(cv) end
setChannel(cid, cv)
end

initCAN(CAN_chan, CAN_baud)
setTickRate(tickRate)

View user's profile Send private message
Reply with quote
Post  
Look at the addchannel syntax. You added something, and its has one too many.

View user's profile Send private message
Reply with quote
Post  
Actually, you have a lower case 'c' - it should be addChannel.


_________________
Brent Picasso
Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
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