Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_Scripting: add support for dataflash logging #13315

Merged
merged 5 commits into from
May 18, 2020

Conversation

IamPete1
Copy link
Member

@IamPete1 IamPete1 commented Jan 17, 2020

This add support for writing to dataflash logs from scripting. This also adds a example writing to both dataflash logs and a file on the SD card. There is also a second example that reads in data over serial and writes to dataflash closing #12801. The examples use find_baudrate() and tabel.concat from #13268. Tested both in SITL and on real hardware.

This generally works OK, not all the the formats are supported for lua so I added a helper to auto fill the timestamp for a 'Q' character in the format string.

Is there a nicer way to give the binding access to AP_logger? I had to make a couple of functions public to get this working. Possibly we may have also bypassed some checking that gets done by logger before logging.

Many thanks to @WickedShell for helping me out when I got stuck (more than once)

@IamPete1
Copy link
Member Author

F405-Wing is over flowing flash, apart from that seems to have passed everything

@IamPete1
Copy link
Member Author

rebased to get F405-wing passing thanks to #13314

}

// ask for a mesage type
struct AP_Logger::log_write_fmt *f = AP_logger->msg_fmt_for_name(name, labels, nullptr, nullptr, fmt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is name as a pointer stable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is stable during this call, but as soon as it's not on the stack it's not anymore, which can lead to future issues. If msg_fmt_for_name actually copied aside the name we'd be okay, but it doesn't, it just copies the pointer. We'd probably need to allocate our own store space/track it in the C++ code for duplicates before allocating a new one, and pass that down to the logger.

@tridge
Copy link
Contributor

tridge commented Jan 20, 2020

should be tested in autotest, checking for good results

@tridge
Copy link
Contributor

tridge commented Jan 20, 2020

need to only send FMT msg once

libraries/AP_Scripting/examples/logging.lua Show resolved Hide resolved
libraries/AP_Scripting/examples/logging.lua Outdated Show resolved Hide resolved
libraries/AP_Scripting/examples/logging.lua Outdated Show resolved Hide resolved
libraries/AP_Scripting/examples/logging.lua Outdated Show resolved Hide resolved
}

// ask for a mesage type
struct AP_Logger::log_write_fmt *f = AP_logger->msg_fmt_for_name(name, labels, nullptr, nullptr, fmt);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name is stable during this call, but as soon as it's not on the stack it's not anymore, which can lead to future issues. If msg_fmt_for_name actually copied aside the name we'd be okay, but it doesn't, it just copies the pointer. We'd probably need to allocate our own store space/track it in the C++ code for duplicates before allocating a new one, and pass that down to the logger.

libraries/AP_Scripting/lua_bindings.cpp Outdated Show resolved Hide resolved
libraries/AP_Scripting/lua_bindings.cpp Outdated Show resolved Hide resolved
libraries/AP_Scripting/lua_bindings.cpp Outdated Show resolved Hide resolved
libraries/AP_Scripting/lua_bindings.cpp Outdated Show resolved Hide resolved
libraries/AP_Scripting/lua_scripts.h Outdated Show resolved Hide resolved
@IamPete1
Copy link
Member Author

IamPete1 commented Feb 2, 2020

fixed a few things and rebased

-- format characters specify the type of variable to be logged, see AP_Logger/README.md
-- not all format types are supported by scripting only: i, L, e, f, n, M, B, I, E, and N
-- lua automatically adds a timestamp in micro seconds
logger.write('SCR','roll(deg),pitch(deg),yaw(deg)','fff',table.unpack(interesting_data))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The units comment was more I think about exposing the units argument to scripting? (I think?) I don't see how we can do that without always requiring it though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could do logger write_units or something, imho without units is more useful for most than with, could probably do both with some changes tho, cant use the same function name i don't think tho.

libraries/AP_Scripting/lua_bindings.cpp Outdated Show resolved Hide resolved
libraries/AP_Scripting/lua_bindings.cpp Show resolved Hide resolved
libraries/AP_Scripting/lua_bindings.cpp Outdated Show resolved Hide resolved
libraries/AP_Scripting/lua_bindings.cpp Show resolved Hide resolved
libraries/AP_Scripting/lua_bindings.cpp Outdated Show resolved Hide resolved
libraries/AP_Scripting/lua_bindings.cpp Outdated Show resolved Hide resolved
@IamPete1
Copy link
Member Author

IamPete1 commented Feb 4, 2020

fixed a few more low hanging review issues

@IamPete1 IamPete1 force-pushed the scripting-logging3 branch 2 times, most recently from 57e8c9a to d16dd6a Compare February 9, 2020 13:45
@IamPete1
Copy link
Member Author

IamPete1 commented Feb 9, 2020

@peterbarker if you could have a look over this that would be great. (I still have to fix the buffer heap stuff, but apart from that i think its ready)

@IamPete1
Copy link
Member Author

I think it should be possible to include units and multipliers by checking the length of the format string against the number of arguments, might be better to get this basic functionally in first.

@@ -738,6 +738,18 @@ void AP_Logger::Write_Rally()
FOR_EACH_BACKEND(Write_Rally());
}

void AP_Logger::Safe_Write_Emit_FMT(log_write_fmt *f)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a comment!
need to reset sent_mask on new log?

@IamPete1
Copy link
Member Author

check that we only get one format message, and that it resets if disarmed and re-armed

@IamPete1 IamPete1 force-pushed the scripting-logging3 branch 3 times, most recently from 43f0443 to ba8c895 Compare May 1, 2020 15:26
@tridge
Copy link
Contributor

tridge commented May 10, 2020

I tested this today and it worked well.

@IamPete1
Copy link
Member Author

to be rebasesd and improve example readability

@IamPete1
Copy link
Member Author

Rebased and Re-tested under Valgrind

@tridge tridge merged commit 97f3353 into ArduPilot:master May 18, 2020
@tridge
Copy link
Contributor

tridge commented May 18, 2020

merged after dev call discussion

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants