RegisterSearchFAQMemberlistUsergroupsLog in
Reply to topic Page 1 of 1
Unable to see virtual channels inside Race Capture?
Author Message
Reply with quote
Post Unable to see virtual channels inside Race Capture? 
Howdy.

I suspect I have a conceptual block but I'm working on a LUA script that creates several virtual channels. When I upload this to my Race Capture Pro unit I'm not able to configure any of the dashboard gages to report out on the virutal channels. They're not appearing on my list of available channels.

Any idea what I'm doing wrong?

Code follows:

-- Revision Log -
-- Version Date Description
-- 1 April 17 Road America - first Race
-- 2 August 17 Gingerman Race
-- Removed piggy back gages
-- Added brake sensor
-- Adding CAN bus functionalty to OBDII
-- Adding shift light sensor
-- 8-15 added can Sniffer
-- brake light script
-- 3 October 18, Road America 2nd Race

--Udder Chaos Lua Script File
--Reference:
-- AN1 = OIL PRESSURE
-- AN2 = TRANS TEMP
-- AN3 = OIL TEMP
-- AN4 = H20 TEMP
-- AN5 = FUEL
-- AN6 = 02
-- AN7 = MAP
-- RPM1 = TACH

-- Constants used by the function that determines what gear we are in
local _1stGear = 3.54
local _2ndGear = 2.13
local _3rdGear = 1.36
local _4thGear = 1.03
local _5thGear = .81
local FinalDrive = 3.94
--diameter in inches
local TireDia = 23.0 -- need to double check this!
--allowable error of gear ratio to allow for measurement variation
local gearErr = 0.1
local rpmSpeedRatio = 0
--initialized
local gearPos = 0 --this is the gear channel variable


-- set up virtual channels
-- uses the form: addChannel( name, sampleRate, [precision], [min], [max], [units] )

brake_pressed = addChannel("Brake_Pressed", 10, 0, 0,1) -- add a virtual channel for monitoring brake
fuel_damped = addChannel("FuelLevel", 10, 1, 0,12.6,"Gal") -- add a virtual channel for the damped fuel
gearId = addChannel("Gear",5) -- add a virtual channel for each gear

--change this to make a bigger averaging window
maxAvg = 1000

--300 = 10 seconds averaging at 30Hz tick rate
--do not change

fuelAvg={} -- define fuelAvg as a LUA array
fuel_damped_Index = 1

function updateFuelAvg(value)
local i
if #fuelAvg == 0 then
--initialize averaging table
for i = 1, maxAvg do fuelAvg[i]=0 end
end
fuelAvg[fuel_damped_Index] = value
fuel_damped_Index = fuel_damped_Index + 1
if fuel_damped_Index > maxAvg then fuel_damped_Index = 1 end
local sum = 0
for i = 1, #fuelAvg do
sum = sum + fuelAvg[i]
end
setChannel(fuel_damped, sum / maxAvg)
end


-- Log messages from CAN bus
--------------------------------------------------
canBus = 0 -- this is CAN bus 1
--------------------------------------------------

--this function drains all pending CAN messages
--and outputs messages to the log
function outputCAN()
repeat
id, ext, data = rxCAN(canBus, 1000)
if id ~= nil then
print('[' ..id ..']: ')
for i = 1,#data do
print(data[i] ..', ')
end
println('')
end
until id == nil
println('Timeout: no CAN data')
end


function check_gear() --updates gear position every tick
--assumes Pulse Input channel one is for the RPM signal and speed in MPH
local speed = getGpsSpeed()
local rpm = getTimerRpm(0)
if speed > 10 then
--makes sure your rolling so as not to divide by 0
rpmSpeedRatio = (rpm/speed)/(FinalDrive*1056/(TireDia*3.14159))
if ((_1stGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 1 end
if ((_2ndGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 2 end
if ((_3rdGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 3 end
if ((_4thGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 4 end
if ((_5thGear - rpmSpeedRatio)^2) < (gearErr^2) then gearPos = 5 end
else gearPos = 0 end
setChannel(gearId, gearPos) --outputs to virtual channel
end


setTickRate(30) -- Set the refresh rate to 30 hz

function onTick()
updateFuelAvg(getAnalog(4)) -- pass the contents of Analog 4 (fuel) to the update fuel average routine)
check_gear() -- call the function that determines what gear we are in


-- begin logging only if the car is moving faster than 10mph. Otherwise stop logging.
if getGpsSpeed() > 10 then
startLogging()
else
stopLogging()
end
end

if getGpio(1) == 0 then -- if the brake is pressed
setChannel(brake_pressed,1) -- set the virtual channel to 1
-- println("Brake is not pressed")
else
-- println("Brake is pressed")
setChannel(brake_pressed,0)
end

println("you are in gear " ..gearPos)
println("rpm = " ..getTimerRpm(0))
println("speed = " ..getGpsSpeed())
println("Air Fuel =" ..getAnalog(6))
println("MAP = "..getAnalog(7))
println("Brake Status = "..brake_pressed)
end

View user's profile Send private message
Reply with quote
Post  
For starters, you aren't running some of your functions:

Code:
function onTick()
updateFuelAvg(getAnalog(4)) -- pass the contents of Analog 4 (fuel) to the update fuel average routine)
check_gear() -- call the function that determines what gear we are in


-- begin logging only if the car is moving faster than 10mph. Otherwise stop logging.
if getGpsSpeed() > 10 then
startLogging()
else
stopLogging()
end
end  --<<<<<<<<<<<<<<THIS END HERE


That second End that I point to there ends your onTick functions, so anything after it isn't getting run.

Second

Code:
updateFuelAvg(getAnalog(4))


I'm not sure about putting a number in that function... I typically just put

Code:
updateFuelAvg()


Then under your function header, just put

Code:
function updateFuelAvg()


Third

You have a function for outputCAN(), but you don't actually call it out under the onTick function.

Fourth

Is 30 times a second a little high? I run all of my functions at 10hz, that's every tenth of a second


When I put this script into my RaceCapture, I get an error... Do you?

View user's profile Send private message Visit poster's website
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