Lua script for downshift indication

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

ProtoTim35
Posts: 84
Joined: Fri Jun 22, 2018 2:14 am

Post by ProtoTim35 »

Thanks Brent, that's what I was looking for.

Thanks,

Tim

ProtoTim35
Posts: 84
Joined: Fri Jun 22, 2018 2:14 am

Re: Lua script for downshift indication

Post by ProtoTim35 »

I finally got the opportunity to try the scripting a week or so ago. I tried all scripting recommended to me on this board, and all of those scripts made it so that none of the shift lights worked. I inserted the original scripting, and got the original shift lights working again, but only on referencing RPM - still didn't have the new shift light working. I didn't have a lot of time to mess with it at the event.

When I got back home, I got the new shift light working as well. Immediately below is the scripting that I'm using to have all of the shift lights working (referencing RPM only - stationary in the shop):

Keep in mind this is only for testing, so I set it for low RPM reference:

function onTick()
rpm=getTimerRpm(0) --read RPM
--activate LEDs

if rpm > 1600 then setGpio(2,1) else setGpio(2,0) end
if rpm > 1700 then setGpio(1,1) else setGpio(1,0) end
if rpm > 1800 then setGpio(0,1) else setGpio(0,0) end
end

Above works exactly as I had hoped for when referencing only RPM

Below is what I tried afterwards, in attempt to get them working while also referencing speed and RPM. However, since I was doing it in the shop and stationary, I was using TPS (Throttle Position sensor) reading instead for reference. TPS reading is set as "tpsvolts", so that's what I referenced:

if (rpm > 1700 and tpsvolts > 1) or (rpm > 1900 and tpsvolts > 1.6) or (rpm > 2100 and tpsvolts > 2.2) then setGpio(2,1) else setGpio(2,0) end
if rpm > 1700 then setGpio(1,1) else setGpio(1,0) end
if rpm > 1800 then setGpio(0,1) else setGpio(0,0) end
end

No lights worked. I then realized I didn't give a command to read tpsvolts, so I attempted that with the following:
(keep in mind I have very minimal of any idea of what I'm doing with Lua scripting, so I'm doing some shooting in the dark using some guesswork).

function onTick()
rpm=getTimerRpm(0) --read RPM
tpsvolts=gettpsvolts (0) --read tpsvolts
--activate LEDs

if (rpm > 1600 and tpsvolts > 1) or (rpm > 1900 and tpsvolts > 1.6) or (rpm > 2100 and tpsvolts > 2.2) then setGpio(2,1) else setGpio(2,0) end
if rpm > 1700 then setGpio(1,1) else setGpio(1,0) end
if rpm > 1800 then setGpio(0,1) else setGpio(0,0) end
end

Once again, none of the shift lights work. I'm suspecting there is something in the command somewhere having to do with maybe in the function onTick?

Any help would be appreciated. If you can help, please, also give me the correct command for "speed" in MPH for final reference, in place of tpsvolts.

Thanks.

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

Re: Lua script for downshift indication

Post by brentp »

Two suggestions:

You can use the getChannel(<channel name>) to reference any valid channel in the system. e.g. getChannel("Speed") or getChannel("TPS")

You should sprinkle println("test.1") statements in your code to diagnose your complex boolean logic. Simplify / reduce, verify the basics work, then make it more complex - programming 101 stuff. :)

Good luck, keep us posted on your progress. Maybe you have a local programmer type who can help you on the spot?

ProtoTim35
Posts: 84
Joined: Fri Jun 22, 2018 2:14 am

Re: Lua script for downshift indication

Post by ProtoTim35 »

Brent, thanks for getting back to me. Unfortunately, I don't know anyone local that could help. I've been trying to do what I think you suggested, with negative results so far. I'm not sure of some of what you are saying. for example, what do you mean by "You should sprinkle println("test.1")" That's greek to me. Is there a way you could give some sort of example using the information in my previous post. I suspect what I'm up against is a very simple problem, but not being Lua lingual, I feel like I'm beating my head against a wall looking for the answer.

Maybe a more detailed explanation of what I'm trying to achieve would help.

Let's start with just one shift light - gpio2. Using RPM and speed as the two channels. I'm trying to make it so that the shift light will come on when 2 conditions are met at the same time, and have 3 (or 2) different parameters. parameter one, is for the shift light come on if RPM is above 10600 and speed is below 70 MPH (speed). second parameter is an "or" parameter if rpm is above 10800 RPM and speed is above 70 mph. I feel that if I can get those parameters to work properly, I can likely get everything else put together for what I ultimately want to achieve.

I think the biggest problem I'm running into is the base "search" function having the right coding parameter. I've tried various different variations, and anything I've tried, seem to confuse the data logger and makes it so that none of the shift lights work - even though I haven't changed any parameters on the other shift lights, and regardless of how I have the 3rd shift light set up - or even eliminated.

I think where I'm having the problem is understanding how these commands are put together. If you can break down what each part of the command means, I feel I can likely put it together. The part that I think is holding me back is getTimerRpm(0) --read RPM. More particularly, what is the "Timer" and the "(0)? What do I need for those values with speed and/or TPS? :

function onTick()
rpm=getTimerRpm(0) --read RPM
--activate LEDs

I hope that helps.

ProtoTim35
Posts: 84
Joined: Fri Jun 22, 2018 2:14 am

Re:

Post by ProtoTim35 »

ProtoTim35 wrote: Wed Oct 03, 2018 5:40 pm Thanks Mike. I understand most of that. A related questions to a previous post, and haven't been able to get an answer from anyone else yet, nor find it on the web anywhere:

What do the numbers inside the () represent in the below script?

I'm now trying to modify my script for operating the shift lights.

What is the significance of the numbers in the ()? gearId = addChannel("Gear", 10, 0, 0, 6) Apparently, it represents something important, because when I change the number in an otherwise operating script, that one change renders the entire script dead. If i can understand what the numbers mean/represent, I might be able to get a script working for the shift lights using "speed".

I never was able to get the script you sent to work for me for the camera. I gave up on that. I think part of it was that the camera just doesn't link reliably to the MK3 - or maybe anything. I even tried using a gopro remote specifically for the camera. It would be very unreliable in starting and stopping the recording. Consequently, although it's hard to do, I'm now starting and stopping the camera manually. That way, I know it's operating unless I forget to turn it on, which occasionally happens too.

I have the shift lights operating - strictly off of RPM, but trying to create a script that will make it so that they operate off of RPM and speed.

Thanks for your help.

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

Re: Lua script for downshift indication

Post by brentp »

Here's the reference to addChannel() https://wiki.autosportlabs.com/RaceCapt ... its.5D_.29

(and all of the other Lua functions we support).

You might also want to join our Discord server, there might be others there that can help you with the basic programming topics.
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

Post Reply