Script for damper velocity?

Discussion on the Lua Scripting capabilities for RaceCapture/Pro. Also see the <a href="http://autosportlabs.net/RaceCapturePro_Lua_Scripting">Lua Scripting Guide</a>

Moderators: JeffC, stieg

Post Reply
Canyonfive
Posts: 69
Joined: Mon Jan 29, 2018 11:20 pm

Script for damper velocity?

Post by Canyonfive »

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?

Canyonfive
Posts: 69
Joined: Mon Jan 29, 2018 11:20 pm

Post by Canyonfive »

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.

Code: Select all

setTickRate&#40;100&#41;
local lrpos = getChannel&#40;"LRSusp"&#41;
local rrpos = getChannel&#40;"RRSusp"&#41;
local lrstatic = 0.515
Local rrstatic = 0.515

function shockMath&#40;&#41;
lrshktrvlId = addChannel&#40;"LRHeight", 100, 3, -50, 100, "mm"&#41;
setChannel&#40;lrshktrvlId, 80 * &#40;lrpos - lrstatic&#41;&#41;
rrshktrvlId = addChannel&#40;"RRHeight", 100, 3, -50, 100, "mm"&#41;
setChannel&#40;lrshktrvlId, 80 * &#40;rrpos - rrstatic&#41;&#41;
end 

function onTick&#40;&#41;
shockMath&#40;&#41;
end
 
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.

Canyonfive
Posts: 69
Joined: Mon Jan 29, 2018 11:20 pm

Post by Canyonfive »

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?

Code: Select all

lrshkvelId = addChannel&#40;"LRVel", 100, 3, -400, 400, "mm/s"&#41;

function shockvel&#40;&#41;
pastlrheight = p
if p = nil then p = 0

local lrHeight = getChannel&#40;"LRHeight"&#41;
local lrvel = &#40;lrHeight - pastlrheight&#41; / 0.01
setChannel&#40;lrshkvelId, lrvel&#41;
p = lrHeight

end

Function onTick&#40;&#41;
shockvel&#40;&#41;
end 

brentp
Site Admin
Posts: 5956
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

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!
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

Canyonfive
Posts: 69
Joined: Mon Jan 29, 2018 11:20 pm

Post by Canyonfive »

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!
Thanks. I should be able to test this weekend.

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.

brentp
Site Admin
Posts: 5956
Joined: Wed Jan 24, 2007 6:36 am

Post by brentp »

if p = nil then p = 0 end

yes, you need an end for that if statement.
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

Canyonfive
Posts: 69
Joined: Mon Jan 29, 2018 11:20 pm

Post by Canyonfive »

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

Code: Select all

 if p = nil then p= 0 end 
To

Code: Select all

 if p == nil then p= 0 end 
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

Code: Select all


setTickRate&#40;100&#41;
--Virutal Channels
lrshkvelId = addChannel&#40;"LRVel", 100, 3, -400, 400, "mm/s"&#41;
lrshkvelId = addChannel&#40;"RRVel", 100, 3, -400, 400, "mm/s"&#41;
rrshktrvlId = addChannel&#40;"RRHeight", 100, 3, -50, 100, "mm"&#41;
lrshktrvlId = addChannel&#40;"LRHeight", 100, 3, -50, 100, "mm"&#41;

if p == nil then p = 0 end

function shockMath&#40;&#41;
local lrpos = getChannel&#40;"LRSusp"&#41;
local rrpos = getChannel&#40;"RRSusp"&#41;
setChannel&#40;lrshktrvlId, 80 * &#40;lrpos - 0.500&#41;&#41;
-- 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&#40;rrshktrvlId, 80 * &#40;rrpos - 0.477&#41;&#41;
end 

function shockVel&#40;&#41;
pastlrheight = p

local lrHeight = getChannel&#40;"LRHeight"&#41; 
setChannel&#40;lrshkvelId, &#40;lrHeight - pastlrheight&#41; / 0.01&#41;
p = lrHeight

end

function onTick&#40;&#41;
shockMath&#40;&#41;
shockVel&#40;&#41;
end 
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?
Last edited by Canyonfive on Sat Aug 08, 2020 10:51 pm, edited 1 time in total.

Canyonfive
Posts: 69
Joined: Mon Jan 29, 2018 11:20 pm

Post by Canyonfive »

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

Post Reply