Does anyone have a script for damper velocity? I have damper position, but im a bit lost when it comes to using lua for a differential function.
Just guessing in theory. (Current pos - Previous position)/.01 (assuming 100hz logging)
But how do I get/pull the previously logged position?
Script for damper velocity?
-
- Posts: 69
- Joined: Mon Jan 29, 2018 11:20 pm
Here is my code for damper position. I scaled full rebound as 0% and full bump as 100% based on my voltage for the shock pots which I mapped in the analog channels. This script takes those % and translates them into actual shock position in mm. Also makes it really easy to rezero for ride height changes by changing the static height values in the script rather than revealing the voltages.
Still trying to digest the ways of calling a past value. Apparently you can create a table. Although I dont know the best way to go about it.
Code: Select all
setTickRate(100)
local lrpos = getChannel("LRSusp")
local rrpos = getChannel("RRSusp")
local lrstatic = 0.515
Local rrstatic = 0.515
function shockMath()
lrshktrvlId = addChannel("LRHeight", 100, 3, -50, 100, "mm")
setChannel(lrshktrvlId, 80 * (lrpos - lrstatic))
rrshktrvlId = addChannel("RRHeight", 100, 3, -50, 100, "mm")
setChannel(lrshktrvlId, 80 * (rrpos - rrstatic))
end
function onTick()
shockMath()
end
Â
-
- Posts: 69
- Joined: Mon Jan 29, 2018 11:20 pm
So, theoretically.... everything in the script is done in the order it is written. So the last thing in the code is to set the variable p to the current height. As long as it's possible to store variables in this way, it should work except for the first time it runs which p will be nil. So the if then statement is there to fix that.
What do you all think? Are there obvious errors?
What do you all think? Are there obvious errors?
Code: Select all
lrshkvelId = addChannel("LRVel", 100, 3, -400, 400, "mm/s")
function shockvel()
pastlrheight = p
if p = nil then p = 0
local lrHeight = getChannel("LRHeight")
local lrvel = (lrHeight - pastlrheight) / 0.01
setChannel(lrshkvelId, lrvel)
p = lrHeight
end
Function onTick()
shockvel()
end
-
- Posts: 69
- Joined: Mon Jan 29, 2018 11:20 pm
Thanks. I should be able to test this weekend.brentp wrote:Looks ok to me at first blush. Note if your lua script gets any more complex, it may not complete the onTick() loop within 0.01sec, throwing off your readings.
Let us know how it works!
1) does the if then statement need another end, at the end of that line?
2) any way to tell if the loop doesnt complete in time? The goal would be to have it display all 4.
-
- Posts: 69
- Joined: Mon Jan 29, 2018 11:20 pm
Well... I see why this isnt done. 100hz, is really the bear minimum for looking at suspension movement. 500hz is more realistic. Right now even at .08mm resolution in travel at 100hz means the smallest increment in velocity that can be calculated is 8mm/s. Not enough really.
Anyway back to the script becuase I think it could be useful anyway.
I had to change
To
And move that expression above the functions. Then it worked! However, I did noticed that my calculated values for suspension height vs racecapture calculated values are different. Can you shed some light on why? They seem more accurate when the calc are done in lua vs excel?
Working code
Another mistake I just noticed is the velocityID second one should be rrshkvelId.
Anyway, this code opens up a whole lot of possibilities! Like the derivative of throttle or steering allowing a racer to see how quickly they are coming on or off throttle. Sure you can see it in the data but over a whole lap it's really enlightening. Same with the steering trace. It shows stuff like the difference between the pros making micro adjustments and the noobs yanking at the wheel. (Aim has some webinars about it)
Any chance we could get shock histograms in the next podium update? Like if LRHeight is present then have it do the calculations in podium while making the histogram?
Anyway back to the script becuase I think it could be useful anyway.
I had to change
Code: Select all
if p = nil then p= 0 end
Code: Select all
if p == nil then p= 0 end
Working code
Code: Select all
setTickRate(100)
--Virutal Channels
lrshkvelId = addChannel("LRVel", 100, 3, -400, 400, "mm/s")
lrshkvelId = addChannel("RRVel", 100, 3, -400, 400, "mm/s")
rrshktrvlId = addChannel("RRHeight", 100, 3, -50, 100, "mm")
lrshktrvlId = addChannel("LRHeight", 100, 3, -50, 100, "mm")
if p == nil then p = 0 end
function shockMath()
local lrpos = getChannel("LRSusp")
local rrpos = getChannel("RRSusp")
setChannel(lrshktrvlId, 80 * (lrpos - 0.500))
-- LRSusp is mapped from 0 at full droop to 1 at full compression
-- 0.500 is the value when at rest on the ground
-- this is done becuase it's easy to rezero after ride height changes
setChannel(rrshktrvlId, 80 * (rrpos - 0.477))
end
function shockVel()
pastlrheight = p
local lrHeight = getChannel("LRHeight")
setChannel(lrshkvelId, (lrHeight - pastlrheight) / 0.01)
p = lrHeight
end
function onTick()
shockMath()
shockVel()
end
Anyway, this code opens up a whole lot of possibilities! Like the derivative of throttle or steering allowing a racer to see how quickly they are coming on or off throttle. Sure you can see it in the data but over a whole lap it's really enlightening. Same with the steering trace. It shows stuff like the difference between the pros making micro adjustments and the noobs yanking at the wheel. (Aim has some webinars about it)
Any chance we could get shock histograms in the next podium update? Like if LRHeight is present then have it do the calculations in podium while making the histogram?
Last edited by Canyonfive on Sat Aug 08, 2020 10:51 pm, edited 1 time in total.
-
- Posts: 69
- Joined: Mon Jan 29, 2018 11:20 pm
My logs and excel if anyone wants to check my maths.
My log 706KB https://drive.google.com/file/d/1gh3iSl ... sp=sharing
My excel https://drive.google.com/file/d/1m71tmz ... sp=sharing
My log 706KB https://drive.google.com/file/d/1gh3iSl ... sp=sharing
My excel https://drive.google.com/file/d/1m71tmz ... sp=sharing