Lua logging questions

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
jaytee
Posts: 26
Joined: Mon Jul 10, 2017 1:25 am
Location: Atlanta, GA

Lua logging questions

Post by jaytee »

I'm working through mapping the CAN bus on a Porsche Cayman R (987.2) and have a few questions utilizing a Lua script to log CAN data. Apologies if these are covered elsewhere, or are obvious. Lua is a new scripting language to me....

1) Can you log script output directly to the SD card? It's tough to capture everything in the scripting window, and I think the copy button has a limit on the number of lines it captures. Right now, I don't need other data (GPS, accelerometer, etc.).

2) Can the Action button be used to place a marker in the log? Would make it much easier to synchronize logs with activities since I don't get a GPS fix where my car is parked.

3) Anyway for "print" to not append a decimal point?

For instance, on the RCP3:

Code: Select all

print&#40;10&#41;
Outputs:
10.0
In other Lua environments, including the Lua emulator, it outputs:
10

Thanks!

boggie1688
Posts: 138
Joined: Fri Apr 07, 2017 3:47 pm
Location: Oakland, CA

Post by boggie1688 »

Jay,

I think I can help with 1 and 2.

I assume you are trying to log the raw can data, then trying to use the action button to create markers to help you look inside of the can log.

I use Putty to log the script output. http://www.putty.org/

Advanced: Using a Terminal Program
https://wiki.autosportlabs.com/CAN_Bus_logger

Instead of launch the RCP app, you launch putty, configure it to the correct COM, and set it to log the CMD window. This will produce a session log of whatever happens in the session. IE, all the output from the lua script. You still need the can logger script to be inside the script area.

As for the action button:
https://wiki.autosportlabs.com/RaceCapt ... tton.28.29

You can edit the output script to also monitor the button so that when it value = 0, it println(MARK).


Code: Select all

-- Log messages from CAN bus
-- be sure to set the correct baud rate in the CAN settings

--------------------------------------------------
-- change this to 0 for CAN bus 1, or 1 for CAN bus 2
canBus = 0
--------------------------------------------------

--this function drains all pending CAN messages
--and outputs messages to the log
function outputCAN&#40;&#41;
 repeat 
  id, ext, data = rxCAN&#40;canBus, 1000&#41;
  if id ~= nil then
   print&#40;'&#91;' ..id ..'&#93;&#58; '&#41;
   for i = 1,#data do
    print&#40;data&#91;i&#93; ..', '&#41;
   end
   println&#40;''&#41;
  end
 until id == nil
    println&#40;'Timeout&#58; no CAN data'&#41;
end

function checkButton&#40;&#41;
 i = getButton&#40;&#41;
 if i = 0 then
 println&#40;MARK&#41;
 end
end
 
function onTick&#40;&#41;
 outputCAN&#40;&#41;
 checkButton&#40;&#41;
end

setTickRate&#40;30&#41;

boggie1688
Posts: 138
Joined: Fri Apr 07, 2017 3:47 pm
Location: Oakland, CA

Post by boggie1688 »

Oh...I also think the issue between 10.0 and 10, might be the difference between print() and println().

jaytee
Posts: 26
Joined: Mon Jul 10, 2017 1:25 am
Location: Atlanta, GA

Post by jaytee »

Thanks Boggie!

I've been logging through screen (a terminal emulator) on my Mac and was hoping for a way to log directly to the SD card so I didn't need to tote around any extra hardware.

I implemented some logic to check the button status, similar to your example below, and it doesn't work quite as well as I hoped. I'm using a counter to record the number of presses and sometimes it doesn't register due to (I'm guessing) the tick rate and I end up with a bunch of fragmented logs on the SD card.

boggie1688 wrote:Jay,

I think I can help with 1 and 2.

I assume you are trying to log the raw can data, then trying to use the action button to create markers to help you look inside of the can log.

I use Putty to log the script output. http://www.putty.org/

Advanced: Using a Terminal Program
https://wiki.autosportlabs.com/CAN_Bus_logger

Instead of launch the RCP app, you launch putty, configure it to the correct COM, and set it to log the CMD window. This will produce a session log of whatever happens in the session. IE, all the output from the lua script. You still need the can logger script to be inside the script area.

As for the action button:
https://wiki.autosportlabs.com/RaceCapt ... tton.28.29

You can edit the output script to also monitor the button so that when it value = 0, it println(MARK).


Code: Select all

-- Log messages from CAN bus
-- be sure to set the correct baud rate in the CAN settings

--------------------------------------------------
-- change this to 0 for CAN bus 1, or 1 for CAN bus 2
canBus = 0
--------------------------------------------------

--this function drains all pending CAN messages
--and outputs messages to the log
function outputCAN&#40;&#41;
 repeat 
  id, ext, data = rxCAN&#40;canBus, 1000&#41;
  if id ~= nil then
   print&#40;'&#91;' ..id ..'&#93;&#58; '&#41;
   for i = 1,#data do
    print&#40;data&#91;i&#93; ..', '&#41;
   end
   println&#40;''&#41;
  end
 until id == nil
    println&#40;'Timeout&#58; no CAN data'&#41;
end

function checkButton&#40;&#41;
 i = getButton&#40;&#41;
 if i = 0 then
 println&#40;MARK&#41;
 end
end
 
function onTick&#40;&#41;
 outputCAN&#40;&#41;
 checkButton&#40;&#41;
end

setTickRate&#40;30&#41;

jaytee
Posts: 26
Joined: Mon Jul 10, 2017 1:25 am
Location: Atlanta, GA

Post by jaytee »

boggie1688 wrote:Oh...I also think the issue between 10.0 and 10, might be the difference between print() and println().
println() adds a newline after output and print() doesn't. Same issue with the number format. :(

boggie1688
Posts: 138
Joined: Fri Apr 07, 2017 3:47 pm
Location: Oakland, CA

Post by boggie1688 »

Doh!

That is the extent of my RCP capabilities! Gotta wait for the man himself to respond.

gizmodo
Posts: 138
Joined: Mon Aug 05, 2013 10:22 pm

Post by gizmodo »

Is the decimal point causing a problem? My guess is the reason you're seeing the decimal point is because it is a general formatting decision made in the RaceCapture application. I thought I remember reading that numeric values in the RCP being treated as floats, but I could very well be wrong.

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

Post by brentp »

Hi -

For 1) there currently is not a way to write data to the SD card via Lua scripting, sorry.

2) Yes, you can monitor the state of the action button, but the better way would be to wire up a GPIO with a secondary button, because the front panel button is set to trigger logging. A button connected to GPIO can be used to set a virtual channel to a value (say, "1") if the button is set, or "0" if not. See the lua scripting guide for how the virtual channels work.

3) the decimal point is built into the firmware print(ln) output.
Brent Picasso
CEO and Founder, Autosport Labs
Facebook | Twitter

Post Reply