getAccel function not working mk2 v2.7.8

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
JMcDonough
Posts: 70
Joined: Tue Mar 10, 2015 3:31 pm
Location: Detroit, MI

getAccel function not working mk2 v2.7.8

Post by JMcDonough »

I've been trying to learn how the lua scripting works, so I thought I'd try to start the logger based on an accel threshold.

I copied and pasted the example code:

Code: Select all

setTickRate&#40;30&#41;

function onTick&#40;&#41;
 local arm = getGpio&#40;0&#41;
 local g = getAccel&#40;1&#41;
 if arm == 0 then
   stopLogging&#40;&#41;
 end
 if arm == 1 and g < 0.1 then
   startLogging&#40;&#41;
 end
end
Then deleted the "arm" stuff and changed the threshold to g > 0.5

I then tipped the unit around to exceed the threshold, but did not see the logger come on.

Next I started using the print command to check other functions. getAnalog(7) will give me battery voltage and print it, but getAccel(0) will not return anything. I tried all four getAccel channels with no success.

Ideas?

Also, after pushing changes to the RCP, I have to reset it (pull usb power in this case) to get it to run the updated lua script. Is this normal?

Thanks!

Josh

Copper280z
Posts: 30
Joined: Sun Mar 15, 2015 3:03 am
Location: United States

Post by Copper280z »

Your conditionals are not going to work like that, you are never changing the state of arm and you never set it to 1, which you require to start logging. EDIT: I think I misunderstood what you were asking, can you post some of the code you were using that didn't do what you wanted?

Take a look at this, I think that should do what you want, I'm still learning the lua syntax as well.

Code: Select all

setTickRate&#40;30&#41; 

function onTick&#40;&#41; 
 local arm = false --getGPIO grabs the state of an input pin, which I don't think you want, unless you have a physical arming switch?
 local g = getAccel&#40;1&#41; 
 if arm == true and g < .3 then --if you are currently logging AND less than .3 G, then stop logging
   stopLogging&#40;&#41; 
 end 
 if arm == false and g > .5 then --if you are currently not logging AND greater than .5G, then start logging
   startLogging&#40;&#41; 
 end 
end

JMcDonough
Posts: 70
Joined: Tue Mar 10, 2015 3:31 pm
Location: Detroit, MI

Post by JMcDonough »

To clarify, here's what I actually tried:

Code: Select all

setTickRate&#40;30&#41; 

function onTick&#40;&#41; 
 local g = getAccel&#40;1&#41; 
 if g > 0.5 then 
   startLogging&#40;&#41; 
 end 
end
After failing to get it to start logging, I tried to simply print the current accel value. No luck there either. Next was to try to print another variable, battery voltage. That worked and leads me to believe something is wrong with the getAccel function. Unless there's something wrong with the above code, my next step is to re-write the firmware and see if that fixes it.

JMcDonough
Posts: 70
Joined: Tue Mar 10, 2015 3:31 pm
Location: Detroit, MI

Post by JMcDonough »

Tried re-flashing the firmware. Tried v2.7.6 then 2.7.8 again. No success. The function seems to stop at the g = getAccel(1) line. It will print text to the logfile portion of the screen prior to that line, but nothing after.

Any suggestions?
Josh

Copper280z
Posts: 30
Joined: Sun Mar 15, 2015 3:03 am
Location: United States

Post by Copper280z »

hmm, I'm not getting anything out of getAccel, getAccelRaw, or getGPIO, but I do get the expected value out of getButton.

JMcDonough
Posts: 70
Joined: Tue Mar 10, 2015 3:31 pm
Location: Detroit, MI

Post by JMcDonough »

Glad to know it's not just me. Thanks for checking.

getAnalog(7) does return the battery voltage for me.

Anyone w/ a mk2 on v2.7.8 firmware using getAccel(channel) successfully?
Josh

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

Post by brentp »

Hi all,

we'll double check this in the latest firmware and post a sample script for you to try. Sorry for the hassle!
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

rdoherty
Posts: 215
Joined: Fri Mar 08, 2013 3:32 am

Post by rdoherty »

Tested on 2.7.9, getAccel() doesn't return anything for me either.
Ryan Doherty
Autosports Labs

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

Post by brentp »

Well, poop. With the MK2 and V2 firmware we changed it to getImu() and getImuRaw() and forgot to update the docs. This was to reflect the true nature of the device - not just an accelerometer.

This script should work for you:

Code: Select all

setTickRate&#40;10&#41;

function onTick&#40;&#41;
for i =0,5 do print&#40;getImu&#40;i&#41; ..' '&#41; end
println&#40;''&#41;
end
Apologies for the confusion! Let us know how it works for you.
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

Post Reply