MaxRPM reset button

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
PS14
Posts: 97
Joined: Fri Feb 12, 2016 11:27 pm
Location: NY

MaxRPM reset button

Post by PS14 »

Could someone help me with some code to add to the MaxRPM code. i'd like to use a GPIO channel connected to ground or 5v (whichever's easiest) thru a momentary button that will reset the MaxRPM channel back to zero. like the memory button on a tach. heres my best guess below. thanks, Dave.

setTickRate(10)
maxRpmId = addChannel("MaxRPM", 10)
maxRpm = 0

-- Gpio(0) set to input mode
-- momemtary button connected to 5v

function onTick()
local rpm = getTimerRpm(0)
if rpm > maxRpm then
maxRpm = rpm
setChannel(maxRpmId, maxRpm)
if getGpio(0) = 1 then
setChannel(maxRpmId, 0)
end
end

PS14
Posts: 97
Joined: Fri Feb 12, 2016 11:27 pm
Location: NY

Post by PS14 »

Well, that code failed, so i'm gonna try this next. my scripting abilities suck.

maxRpmId = addChannel("MaxRPM", 10)
maxRpm = 0

function rpmReset()
local rpm = getTimerRpm(0)
local clear = getGpio(0)
if rpm > maxRpm then
maxRpm = rpm
setChannel(maxRpmId, maxRpm)
end
if clear == 0 then
maxRpm = 0
setChannel(maxRpmId, maxRpm)
end
end

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

Post by brentp »

Did this end up working?
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

PS14
Posts: 97
Joined: Fri Feb 12, 2016 11:27 pm
Location: NY

Post by PS14 »

unfortunately no, i'm having issues reading the gpio state. i have gpio(2) connected to mk2 ground through a pushbutton, channel set to output. but on the dash the channel reads zero even if i push the button. none of the gpio channels seem to read "1" when pushbutton held down.

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

Post by brentp »

Hi, try wiring a pullup resistor to Vref so that the input sees a 'high' value when the button is not pressed. a 1K-100K resistor should be fine. Power rating not important.
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

PS14
Posts: 97
Joined: Fri Feb 12, 2016 11:27 pm
Location: NY

Post by PS14 »

that fixed it. now the next problem. when its reset to zero, it wont display a maxrpm until it exceeds that last "maxrpm" value. like it has a memory that needs to be reset. heres the code im using. i have a potentiometer im using to simulate rpm during bench testing.

maxRpmId = addChannel("MaxRPM", 10, 2)
MaxRpm = 0

function rpmReset()
local rpm = getAnalog(6)
if rpm > MaxRpm then
MaxRpm = rpm
setChannel(maxRpmId, MaxRpm)
end
local clear = getGpio(0)
if getGpio(0) == 0 then
setChannel(maxRpmId, 0)
end
end

function onTick()
rpmReset()
end

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

Post by brentp »

You have a local variable called 'clear' that's not being used.

Try proving that the if block is working by putting a println() statement in there that outputs something to the debug window.
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

PS14
Posts: 97
Joined: Fri Feb 12, 2016 11:27 pm
Location: NY

Post by PS14 »

my bad, that was from original (see below). works either way, just does't start over when "reset". dont sweat it, i got until April to sort it out.

local clear = getGpio(0)
if clear == 0 then
maxRpm = 0
setChannel(maxRpmId, maxRpm)
end

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

Post by brentp »

Great, sounds like you're on your way.

This is a cool use of Lua scripting we didn't originally consider, nice job.

Fyi, we just expanded the troubleshooting section here, might be helpful as you go forward:
https://wiki.autosportlabs.com/RaceCapt ... leshooting
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

PS14
Posts: 97
Joined: Fri Feb 12, 2016 11:27 pm
Location: NY

Post by PS14 »

you got me thinking, so i went back to the original script you asked about. slapped it in and it works exactly as planned. when you push reset button, it zeros and instantly reads current value. i don't know how i did it but it works! small miracles. thanks for the support, you and your team rock. happy holidays. Dave in NY.

ill post a video in a few minutes, as well as the code referencing the timer channel for anyone else whom might like to reset maxrpm during a caution lap.

maxRpmId = addChannel("MaxRPM", 10, 2)
maxRpm = 0

function rpmReset()
local rpm = getAnalog(6)
local clear = getGpio(0)
if rpm > maxRpm then
maxRpm = rpm
setChannel(maxRpmId, maxRpm)
end
if clear == 0 then
maxRpm = 0
setChannel(maxRpmId, maxRpm)
end
end

function onTick()
rpmReset()
end

PS14
Posts: 97
Joined: Fri Feb 12, 2016 11:27 pm
Location: NY

Post by PS14 »

Heres a link to my youtube page with a short video of the Rpm Reset button code in action.

https://youtu.be/ernEa37stWs

Heres the code:
maxRpmId = addChannel("MaxRPM", 10)
maxRpm = 0

function rpmReset()
local rpm = getTimerRpm(0)
local clear = getGpio(0)
if rpm > maxRpm then
maxRpm = rpm
setChannel(maxRpmId, maxRpm)
end
if clear == 0 then
maxRpm = 0
setChannel(maxRpmId, maxRpm)

end
end

function onTick()
rpmReset()
end

notes: i had to add a 100K pulldown resistor across the GPIO(0) and 5v inputs.

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

Post by brentp »

Hey, that works great, nice job!

Can we add that to the list of sample Lua scripts?

PS14
Posts: 97
Joined: Fri Feb 12, 2016 11:27 pm
Location: NY

Post by PS14 »

absolutely! Thanks.

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

Post by brentp »

Thanks, added to the wiki and also shared here: https://www.facebook.com/groups/1288770 ... 761425924/
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

Post Reply