RegisterSearchFAQMemberlistUsergroupsLog in
Reply to topic Page 1 of 1
Lua logging questions
Author Message
Reply with quote
Post Lua logging questions 
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:
print(10)


Outputs:

Quote:
10.0


In other Lua environments, including the Lua emulator, it outputs:

Quote:
10



Thanks!

View user's profile Send private message
Reply with quote
Post  
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/RaceCapturePro_Lua_Scripting#getButton.28.29

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



Code:
-- 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()
 repeat
  id, ext, data = rxCAN(canBus, 1000)
  if id ~= nil then
   print('[' ..id ..']: ')
   for i = 1,#data do
    print(data[i] ..', ')
   end
   println('')
  end
 until id == nil
    println('Timeout: no CAN data')
end

function checkButton()
 i = getButton()
 if i = 0 then
 println(MARK)
 end
end
 
function onTick()
 outputCAN()
 checkButton()
end

setTickRate(30)


View user's profile Send private message
Reply with quote
Post  
Oh...I also think the issue between 10.0 and 10, might be the difference between print() and println().

View user's profile Send private message
Reply with quote
Post  
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/RaceCapturePro_Lua_Scripting#getButton.28.29

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



Code:
-- 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()
 repeat
  id, ext, data = rxCAN(canBus, 1000)
  if id ~= nil then
   print('[' ..id ..']: ')
   for i = 1,#data do
    print(data[i] ..', ')
   end
   println('')
  end
 until id == nil
    println('Timeout: no CAN data')
end

function checkButton()
 i = getButton()
 if i = 0 then
 println(MARK)
 end
end
 
function onTick()
 outputCAN()
 checkButton()
end

setTickRate(30)


View user's profile Send private message
Reply with quote
Post  
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. Sad

View user's profile Send private message
Reply with quote
Post  
Doh!

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

View user's profile Send private message
Reply with quote
Post  
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.

View user's profile Send private message
Reply with quote
Post  
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
Founder, Autosport Labs
Facebook | Twitter
View user's profile Send private message Send e-mail
Display posts from previous:
Reply to topic Page 1 of 1
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum