RegisterSearchFAQMemberlistUsergroupsLog in
Reply to topic Page 1 of 1
Mapping Virtual AnalogX channels
Author Message
Reply with quote
Post Mapping Virtual AnalogX channels 
Trying to create a script that will take the front and rear brake pressures from AnalogX and create a virtual channel that shows the percentage of rear pressure vs total (f&r) pressure. what I want to see is percent of rear brake bias. I have the frt brake assigned to analog channel 3 input (named F_Brake), and the rear to analog channel 4 input (named R_Brake). does this script look like it will work?

--Create channel: "BrakeBias"
avgId = addChannel("BRAKEBIAS", 10, 0, 0, 100, "%")

function setChannel()
local a1 = F_Brake(4)
local a2 = R_Brake(6)
setChannel(avgId, (a2 / (a1 + a2))
end

function onTick()
setChannel()
end

View user's profile Send private message
Reply with quote
Post  
I'm not really familiar yet with how to get values from CAN channels. What are these "F_Brake(4)" and "R_Brake(6)" calls you're making? I would have thought you'd need some sort of getChannel function to pull those values (or did you do that outside the code you've posted here?).

View user's profile Send private message AIM Address
Reply with quote
Post  
The F_Brake and R_Brake are the channel names is assigned in the CAN mapping section, so I thought maybe I could call them. but didn't work. I tried F_Brake(), F_Brake, getAnalogF_Brake(). then I tried calling the CAN inputs directly, but I don't think I have the setChannles formulas correct in the code (see below). I'm sure its doable, I'm just not a script master.

--Create Virtual Channels:
vfbrakeId = addChannel("vfbrake", 10, 0, 0, 1600, "psi")
vrbrakeId = addChannel("vrbrake", 10, 0, 0, 1600, "psi")
bbsId = addChannel("BrakeBias", 10, 0, 0, 100, "%")

function processCan()
id, ext, data = rxCAN(0)
if id == 935444 then
setChannel(vfbrakeId, data[7], 16, 40, -200)
setChannel(vrbrakeId, data[9], 16, 40, -200)
end

function setChannel()
local a1 = vfbrake()
local a2 = vrbrake()
setChannel(bbsId, (a2 / (a1 + a2)))
end

function onTick()
processCan()
setChannel()
end
end

View user's profile Send private message
Reply with quote
Post  
I think firmware 2.13.0 supports getChannel by name, so if you mapped your channels using the CAN Mapping feature then you should be able to get their current values with a getChannel("NAME"), like getChannel("F_Brake"). You definitely cannot call a channel like a function by its name. So your lines in your first post's code would be:

local a1 = getChannel("F_Brake")
local a2 = getChannel("R_Brake")

View user's profile Send private message AIM Address
Reply with quote
Post  
Thanks, i'll give that a try.

View user's profile Send private message
Reply with quote
Post  
Unfortunately, that didn't work. but i appreciate the suggestion.

--Create channel: "BrakeBias"
avgId = addChannel("BRAKEBIAS", 10, 0, 0, 100, "%")

function setChannel()
local a1 = getChannel("F_Brake")
local a2 = getChannel("R_Brake")
setChannel(avgId, (a2 / (a1 + a2))
end

function onTick()
setChannel()
end

View user's profile Send private message
Reply with quote
Post  
You will need to ensure you're on 2.13.0 so you can use the getChannel() by name function, and you will also need to ensure you do a nil check, as the value may not always be available currently when requested (it's a function of the sample rate).

I would build up your script slowly to verify each step - if you put it all together and it doesn't work, then it's hard to identify where the problem is.

e.g.

function onTick()
local foo = getChannel("FOO")
if x ~= nil then println("got channel FOO " ..foo) end
end

Hope this helps!


_________________
Brent Picasso
Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Reply with quote
Post  
I'm on MK2 w/2.13.0. I have the F_Brake CAN channel on the left gauge and R_Brake CAN channel on the right gauge with the BrakeBias virtual channel in the center (on the three gauge dash). both CAN channels have data. I am sampling the AnalogX at 5hz so I should prob change the addChannel to match. so if I'm following, you suggest this?

--Create channel: "BrakeBias"
avgId = addChannel("BRAKEBIAS", 5, 0, 0, 100, "%")

function setChannel()
local a1 = getChannel("F_Brake")
local a2 = getChannel("R_Brake")
if x ~= nil then println("got channel BRAKEBIAS" ..bbs)
setChannel(avgId, (a2 / (a1 + a2))
end

function onTick()
setChannel()
end

View user's profile Send private message
Reply with quote
Post  
Not quite. x is not defined in your script, nor is bbs.

You want something like this. Note setting the tick rate to 50 at the top, and checking if things are nil.


setTickRate(50)

--Create channel: "BrakeBias"
avgId = addChannel("BRAKEBIAS", 5, 0, 0, 100, "%")

function setChannel()
local a1 = getChannel("F_Brake")
local a2 = getChannel("R_Brake")
if a1 ~= nil then println("got channel a1" ..a1) end
if a2 ~= nil then println("got channel a2" ..a2) end

if a1 ~= nil and a2 ~= nil then setChannel(avgId, (a2 / (a1 + a2)) end
end


function onTick()
setChannel()
end

View user's profile Send private message Send e-mail
Reply with quote
Post  
for some reason it fails with the setTickRate(50) at the beginning. if i remove it or place it lower script runs, here's what i get: (the memory error is intermittent). and i just realized the error is "BrakeBias" but the channel name is "BRAKEBIAS", maybe i need to change that comment line.

got channel a111.600006
got channel a27.600006
got channel a111.600006
got channel a27.600006
got channel a111.600006
got channel a27.600006
[lua] Script error: not enough memory
[lua] Script error: [string "--Create channel: "BrakeBias"..."]:5.0: Channel not found!
[lua] Script error: [string "--Create channel: "BrakeBias"..."]:5.0: Channel not found!
[lua] Failure: Runtime Error

MK2 2.13.0/1.12.1

View user's profile Send private message
Reply with quote
Post  
Correct, the name is case sensitive. Looks like you're getting closer!


_________________
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