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

Parameter migration: code cleanup, migration script, and land_detector trial #19489

Open
wants to merge 15 commits into
base: main
Choose a base branch
from

Conversation

coderkalyan
Copy link
Contributor

Describe problem solved by this pull request
As discussed on Slack, legacy c parameter files can/should be migrated to the newer YAML module definitions.

Describe your solution
This PR:

  • Performs some minor code cleanup on the parameter parsing and validation code in favor of new Python3 idioms
  • Adds a python script that uses this parsing code to autogenerate yaml module definitions
  • Uses the above script to migrate land_detector to YAML definitions.

Test data / coverage
Not flight tested. Build completes successfully locally, so uploading this to run on CI.

@coderkalyan coderkalyan force-pushed the master branch 4 times, most recently from c6b3373 to ae29f90 Compare April 15, 2022 02:24
@coderkalyan
Copy link
Contributor Author

@dagar Could you take a look at this please?

The only issue I can see so far is MAVROS which is running a bionic container with Python 3.6. I will file a PR to upgrade that to 3.7 or 3.8 as long as there no other side effects of doing so.

Also should do a rebase and pass clang tidy, but functionally I think this is complete. If this looks good to you I can continue the work on the other modules.

@coderkalyan
Copy link
Contributor Author

As per slack, we're going to go aggressive on this and just migrate the entire codebase + scrap the old junk. In the meantime a sample (land_detector) is pushed.

@coderkalyan
Copy link
Contributor Author

coderkalyan commented Jul 13, 2022

  • land_detector
  • airspeed_selector
  • angular_velocity_controller
  • attitude_estimator_q
  • battery_status
  • commander
  • commander/failure_detector
  • dataman
  • ekf2
  • events
  • flight_mode_manager
  • gimbal
  • gyro_calibration
  • gyro_fft
  • landing_target_estimator
  • load_mon
  • local_position_estimator
  • logger
  • mag_bias_estimator
  • manual_control
  • mavlink
  • mc_hover_thrust_estimator
  • navigator
  • rc_update
  • *_control
  • sensors
  • sih
  • simulator
  • temperature_compensation
  • verify no change to parameters.xml
  • remove parser for old parameter definitions
  • remove script middle steps
  • scripting/tooling upgrades

@coderkalyan coderkalyan force-pushed the master branch 2 times, most recently from ecb7465 to 21c6777 Compare July 14, 2022 07:47
@coderkalyan
Copy link
Contributor Author

@dagar All of modules and drivers has been migrated. diffing parameters.xml shows no technical changes, only a couple formatting irregularities and a couple strange parameters i had to update (especially the rc_update module). Nonetheless it would be good to get a second eye on it.

There are a few remaining files in the libraries and other directories. Will the module.yaml work there as well? (I'll try it tomorrow).

Multiple small bugs in the parameter pipeline have been found and fixed. Once we're completely free of C source I'll start simplifying the scripts.

Update: something wrong with simulator/battery_simulator, probably because I testing for the fmu-v5x target. Will explore tomorrow.

@coderkalyan coderkalyan force-pushed the master branch 7 times, most recently from 14773db to bf19ac7 Compare July 15, 2022 23:35
@coderkalyan
Copy link
Contributor Author

Everything is now successful except for a new dependency (dataclasses to be backwards compatible with older Python versions). Updated in this PR: PX4/PX4-containers#318

@dagar This is ready when you want to take a look.

@coderkalyan
Copy link
Contributor Author

Hopefully we can get this in soon to minimize merge conflicts. The tooling will be moved to a separate PR.

@coderkalyan coderkalyan force-pushed the master branch 2 times, most recently from e513654 to 98808e8 Compare July 16, 2022 18:45
@coderkalyan
Copy link
Contributor Author

sitl.diff.txt
fmu-v5x.diff.txt

@dagar Here are the diffs

@coderkalyan coderkalyan force-pushed the master branch 2 times, most recently from e1a0de6 to 88dfc98 Compare July 18, 2022 23:29
Copy link
Member

@bkueng bkueng left a comment

Choose a reason for hiding this comment

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

Thanks for going through this.

Comment on lines -9 to -27
try:
import yaml
except ImportError as e:
print("Failed to import yaml: " + str(e))
print("")
print("You may need to install it using:")
print(" pip3 install --user pyyaml")
print("")
sys.exit(1)

try:
import cerberus
except ImportError as e:
print("Failed to import cerberus: " + str(e))
print("")
print("You may need to install it using:")
print(" pip3 install --user cerberus")
print("")
sys.exit(1)
Copy link
Member

Choose a reason for hiding this comment

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

Can you keep these?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, to be honest I find them to be a bit clunky and not super useful. The import statement raises an error if it can't find it and that's pretty readable. Also, pip3 is not the only way to install a package, i.e. system package managers. I feel like its better to just maintain a requirements.txt in the tree that we point to in documentation. What do you think?

@dagar thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

I know, advanced users will know what to do. We added them when adding new external requirements, for people who updated their branch and it didn't compile anymore.

Tools/validate_json.py Show resolved Hide resolved
Tools/validate.py Outdated Show resolved Hide resolved
Tools/validate.py Outdated Show resolved Hide resolved
src/lib/parameters/px4params/jsonout.py Outdated Show resolved Hide resolved
src/lib/parameters/px4params/jsonout.py Outdated Show resolved Hide resolved
validation/module_schema.yaml Show resolved Hide resolved
@coderkalyan coderkalyan force-pushed the master branch 3 times, most recently from 0d77f38 to 8f4807f Compare July 21, 2022 17:51
A little bit of code cleanup in preparation for using srcparser to
migrate the c parameter files to yaml definitions.

* dataclasses
* PEP 8-ish
TODO: not completed, edit commit when finished

Migrates all modules to use the new yaml parameter definitions instead
of C.
This python script uses the existing parameter build infrastructure to
parse c parameter files and generate yaml module definitions.
Fixes a bug where any boolean tag that exists, whether or not the value
is actually true, is recorded as true in parameter generation.
Copy link
Member

@bkueng bkueng left a comment

Choose a reason for hiding this comment

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

A couple more details, generally looks good, but I haven't looked at the param diff.

  • can you squash the wip commit ( src/modules: parameter format migration (WIP))?
  • for all the generated commits, can you add the exact shell command(s) to the commit message? This will help for people having merge conflicts.



def main():
parser = argparse.ArgumentParser(description='Validate YAML or JSON file(s) against a schema')
Copy link
Member

Choose a reason for hiding this comment

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

Where is json being handled?

@@ -0,0 +1,24 @@
argparse
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I didn't see that. I'll fix.

@@ -17,5 +17,8 @@ jobs:
with:
token: ${{secrets.ACCESS_TOKEN}}

- name: install dependencies
run: pip3 install dataclasses
Copy link
Member

Choose a reason for hiding this comment

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

Where is this required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

px4params/scrparser.py. When I wrote that I was targeting Python 3.7 compatibility since that's the oldest "supported" Python but I then realized we use 3.6 in some places. This is backwards compatibility for 3.6, dataclasses are built into 3.7+

Daniel and I decided to add it directly here because the bionic docker containers aren't behaving (unrelated to my changes) and I couldn't build a new one.

Copy link
Member

Choose a reason for hiding this comment

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

IMO worth adding a comment in the file or commit message, so we can remove it later on.

@@ -269,7 +269,7 @@ def parse_yaml_serial_config(yaml_config):
else:
default_port_str = port_config['default']

if default_port_str != "":
if default_port_str != "" and default_port_str != 0:
Copy link
Member

Choose a reason for hiding this comment

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

When is this a number?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Daniel had used that as a "null" default for the sagetech transponder driver. However I see that just two days back he fixed that. I no longer need this, I'll remove it.

@coderkalyan
Copy link
Contributor Author

Thanks @bkueng for the review, I will implement your changes in the morning, and squash the WIP commit. If you have time, could you please check the XML and json/md diff on main? The diffs I posted are probably out of date, and I've checked but I'd like another eye on it if you are able to.

@bkueng
Copy link
Member

bkueng commented Jul 26, 2022

I looked at the diff you provided and it looks good. Might be worth checking if QGC doesn't have a problem with the scientific float notation (3.0e-3), and the case change of reboot_required.

@mcsauder
Copy link
Contributor

Hi @coderkalyan , would it help get this PR moving again if we started creating a few smaller *_param.c file to *.yaml file PRs?
I'd be happy to help with a few of those.

@coderkalyan
Copy link
Contributor Author

Hi @mcsauder thanks for pitching in. There are two parts to this PR:

  • multiple bug fixes and feature improvements of the parameter build system
  • the actual migration, facilitated by tools/migrate_c_params.py with some amount of manual editing and merging.

I was talking with the dev team and I am going to try to pull the build system improvements into a separate PR. Merging that will unblock this PR. The main issue with migrating everything here is that we start spending hours on rebasing the generated files all the time.

I'm going to additionally split drivers into a new PR, since they don't get updated nearly as often. I think I can get both of those merged soon. Could you please take a couple modules at a time and rebase/create new PRs? I think if you start off with all the *_control modules that would be a good chunk done and we can touch base after that.

Please keep in mind that some of the bug fixes I made are required for the system to accept all the new yaml files. If you find any errors building or missing parameters in the generated output, double check with this PR or rebase with my new tooling PR once I push that. Thanks!

@mcsauder
Copy link
Contributor

mcsauder commented Sep 8, 2022

Hi @coderkalyan , just checking in. I'm chipping away on branches to further this PR, but waiting now on #20108 and #20172. I will continue work to get this across the finish line after those PRs.

@coderkalyan
Copy link
Contributor Author

coderkalyan commented Oct 9, 2022

Sorry all for the absence. I'm pulling the python tooling updates into a separate PR right now. I'll get this all wrapped up within the next few days.

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.

4 participants