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

Configurable serial ports v2 #10337

Merged
merged 25 commits into from
Sep 25, 2018
Merged

Configurable serial ports v2 #10337

merged 25 commits into from
Sep 25, 2018

Conversation

bkueng
Copy link
Member

@bkueng bkueng commented Aug 27, 2018

Rebased and reworked version of #9615. Differences:

  • per-module serial config parameters instead of per-port as asked for by Daniel
    • added the required port deconfliction in the startup scripts (eventually the user should be notified about the conflict in some way, or prevent a conflicting config in the first place).
  • Added module config files based on YAML

per-module vs. per-port config params

Personally I don't see strong arguments for either way, both have their drawbacks:

per-port (previous PR)

  • more centralized approach (in terms of how modules register a serial command)
  • QGC metadata contains all modules even if not enabled

per-module (this PR)

  • explicit port deconfliction required
  • More parameters (one per service instead of one per port)
  • QGC metadata contains all ports

In any case we have now both versions.

Module Config Files

Modules now need a config file to register a startup command, and configure the parameters. I decided to go for YAML, because:

  • generally wide-spread tooling support
  • benefits over JSON:
    • simpler to read and edit
    • YAML is a superset of JSON
    • we can have comments
    • JSON is targeted more for serialization instead of configuration

Here's an example to register a serial command (see the mavlink config for an example of using multiple instances):

module_name: LeddarOne Rangefinder
serial_config:
    - command: leddar_one start -d ${SERIAL_DEV}
      port_config_param:
        name: SENS_LEDDAR1_CFG
        group: Sensors

These config files can also be used for parameter definitions. MAVLink already uses them to generate multiple instances. These are then translated into the existing C-style parameter definitions. This allows us to transition all files step by step and eventually remove the translation layer.

In addition it allows us to do schema validation, to ensure that the configs will conform to the expectations. I added a script that uses cerberus (see commit 1b42c63). The schema is also a good place to document all possible options.

Once there's consensus, I'll continue here, there's still quite a bit left to do.

@dagar
Copy link
Member

dagar commented Aug 27, 2018

Looking good from what I've seen so far. I'll give it a try later.

To be honest I still think it would be easier and more scalable to have modules directly read their own configuration (parameters per instance), but it looks like you've found a good compromise.

TEL1:/dev/ttyS1
TEL2:/dev/ttyS2)

set(px4_constrained_flash_build 1)
Copy link
Member

Choose a reason for hiding this comment

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

We might want to look at cmake options for this kind of thing.
https://cmake.org/cmake/help/v3.0/command/option.html

@@ -473,8 +475,12 @@ add_custom_target(metadata_airframes
USES_TERMINAL
)

file(GLOB_RECURSE yaml_config_files ${PX4_SOURCE_DIR}/src/modules/*.yaml
Copy link
Member

Choose a reason for hiding this comment

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

It's worth getting rid of all cmake globbing to avoid possible surprises with incremental builds.

Copy link
Member Author

Choose a reason for hiding this comment

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

Absolutely. This was just the quickest way to achieve it. Essentially I want to tell cmake 'give me all module configs for all possible modules'. And adding a new config with all modules does not seem right for that.

@dagar dagar added this to the Release v2.0.0 milestone Aug 27, 2018
@dagar
Copy link
Member

dagar commented Aug 27, 2018

Just curious, but did you consider toml (vs json vs yaml)?

@LorenzMeier
Copy link
Member

Very cool! I need to quickly go with you through it, but it looks very scalable and per-airframe accurate now.

"index": 6,
"default_baudrate": 57600,
},
"URT3": { # for Omnibus
Copy link
Member

Choose a reason for hiding this comment

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

I think we'll end up needing the full range of generic names (especially for the linux boards).

@bkueng
Copy link
Member Author

bkueng commented Aug 27, 2018

Just curious, but did you consider toml (vs json vs yaml)?

Yes briefly. It's a valid alternative, but it's just not as wide-spread used (yet), also in terms of tooling. And nested structures seem to be better supported in YAML.

--xml ${parameters_xml}
--inject-xml ${CMAKE_CURRENT_SOURCE_DIR}/parameters_injected.xml
--overrides ${PARAM_DEFAULT_OVERRIDES}
--board ${BOARD}
#--verbose
DEPENDS
${param_src_files}
${generated_params_dir}/serial_params.c
Copy link
Member

Choose a reason for hiding this comment

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

Use the same variable as the custom command OUTPUT - ${generated_serial_params_file}


# make sure all baudrates are marked as used
param touch
{%- for serial_device in serial_devices %} SER_{{ serial_device.tag }}_BAUD
Copy link
Member

Choose a reason for hiding this comment

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

This could be skipped so that it's only visible to the user when on an appropriate config.
For example frsky telem, iridum, syslink, etc shouldn't present a configurable baudrate.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a per-port setting, e.g. SER_TEL1_BAUD. It will make it a bit easier to use.

Copy link
Member

Choose a reason for hiding this comment

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

Yes and they'll still be there if you have anything (Mavlink, GPS, etc) enabled on that port. In the cases where it's not used we can hide it, skip the sync, and close one more little hole where users are able to try doing something that doesn't make any sense. Since all of these parameters set via command line are reboot_required I don't really see the problem (set mavlink, reboot, serial mavlink baudrate param available).

This is a case where handling the param in the module itself could actually be a lot better as it would enable runtime changes.

bkueng added a commit to PX4/PX4-containers that referenced this pull request Sep 4, 2018
@bkueng bkueng force-pushed the configurable_serial_ports_v2 branch from 1b42c63 to b8a7080 Compare September 5, 2018 15:20
@bkueng bkueng changed the title [WIP] Configurable serial ports v2 Configurable serial ports v2 Sep 5, 2018
@bkueng
Copy link
Member Author

bkueng commented Sep 5, 2018

This is now in a working state, ready for review and CI tests.

Testing

I tested these boards:

  • Pixhawk (v2) (the SERIAL 4 port can now be used as well)
  • Pixhawk 3 Pro (v4pro)
  • Pixracer (v4)
  • Pixhawk 4 (v5)
  • Intel Aero (aerofc-v1)
  • Omnibus-f4sd

Compatibility

SYS_COMPANION is deprecated and can be removed after the next release. I added code that automatically maps existing SYS_COMPANION settings to the new parameters. So users who have SYS_COMPANION set should not notice a difference (though I did not add the translation for less common configs like frsky telemetry).

Breaking Changes

  • Telem 2 is disabled by default to reduce RAM usage
  • SENS_EN* parameters for serial distance sensors got replaced with the generic serial config params, and a user needs to update.

Depends on PX4/PX4-containers#133

@hamishwillee
Copy link
Contributor

@bkueng There will probably result in quite a lot of docs updates. I'm thinking about

  • everywhere we suggest setting SYS_COMPANION
  • how to enable various sensors etc.
  • How others can create config params and where. Probably best for you to write the docs on this one and me to review - I assume based on your info above.

Lets talk them through when this gets accepted.

Is TELEM2 disabled by default on everything or just FMUv2?

dagar pushed a commit to PX4/PX4-containers that referenced this pull request Sep 6, 2018
param set MAV_1_CONFIG 2
param set MAV_1_RATE 1000
param set MAV_1_MODE 3
param set SER_TEL2_BAUD 57600
Copy link
Member

Choose a reason for hiding this comment

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

In my opinion this should be dropped. There's nothing about a TBS caipirinha that requires a specific telemetry 2 configuration. The airframe can easily be kept generic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Agreed, dropped.

"index": 6,
"default_baudrate": 0,
},
"URT6": { # for Omnibus
Copy link
Member

Choose a reason for hiding this comment

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

There are boards that just have a range of generic uarts. Should we add them here now?

Copy link
Member Author

Choose a reason for hiding this comment

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

I'd add them as needed.

Copy link
Member

Choose a reason for hiding this comment

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

It includes boards we already have in tree (navio2, av-x, nucleos, etc). If we add the full range initially we can keep the index simple and consistent.

Copy link
Member Author

Choose a reason for hiding this comment

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

Ok feel free to add them and push to the branch.

@bkueng bkueng force-pushed the configurable_serial_ports_v2 branch from b8a7080 to a84fea5 Compare September 6, 2018 09:34
dagar pushed a commit to PX4/PX4-containers that referenced this pull request Sep 6, 2018
@bkueng
Copy link
Member Author

bkueng commented Sep 6, 2018

@hamishwillee yes all of these need to be updated.
TELEM2 is disabled by default on all boards. This is a port that needs to be configured according to a users use-case, so I think leaving it disabled makes sense. But if others feel different I'd like to hear it.

@hamishwillee
Copy link
Contributor

TELEM2 is disabled by default on all boards. This is a port that needs to be configured according to a users use-case, so I think leaving it disabled makes sense. But if others feel different I'd like to hear it.

Completely agree - part of the problem with SYS_COMPANION was that it always had to be disabled or set in order to use the port. What I don't understand yet is how the user would enable it. I think from the discussion this would be done using per-module (?) parameter(s) appropriate to that port. I guess that is what your docs will answer :-)

@bkueng
Copy link
Member Author

bkueng commented Sep 7, 2018

I think from the discussion this would be done using per-module (?) parameter(s) appropriate to that port. I guess that is what your docs will answer :-)

Yes there's a per-module param. For example for FrSky telemetry there's a parameter TEL_FRSKY_CONFIG that provides a drop-down list with the Ports where you would select Telem2.

bkueng and others added 8 commits September 22, 2018 09:06
Replaced with the more general serial config params.
Replaced with the more generic serial config params.

rc.mavlink contains automatic transition support that can be removed after
the next release.
Can be reverted if needed later on...
This is because NuttX uses a different assignment for variables.
@bkueng bkueng force-pushed the configurable_serial_ports_v2 branch from 92b459c to 69b098b Compare September 22, 2018 07:08
@@ -681,6 +682,11 @@ int Mavlink::mavlink_open_uart(int baud, const char *uart_name, bool force_flow_
case 1500000: speed = B1500000; break;
#endif

#ifdef B2000000
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 missing?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think not all Linux/Posix systems have it.

@dagar
Copy link
Member

dagar commented Sep 23, 2018

Looks good to me.

Let's regroup after this settles in master and note what's still needed.

  • How to handle QGC side configuration
  • missing board configurations and posix handling
  • px4 side changes to prevent conflicts and provide actionable error messages
  • path forward for module yaml files and parameters
    • let's not have 2 levels of code generation long term
  • QGC metadata update ([WIP] Configurable serial ports #9615 (comment))

@bkueng
Copy link
Member Author

bkueng commented Sep 24, 2018

Thanks for the review @dagar.

@PX4/testflights can you test this? You don't need to fly, just make sure all UARTs are working as expected on different boards: telemetry link, gps, serial sensors etc.

@Avysuarez
Copy link

Avysuarez commented Sep 24, 2018

I tested on pixhawk 4 and pixhawk 2.1 the two FC works properly.

@santiago3dr
Copy link

looks to be working on the pixracer
...only port that doesn't is telem2 which was disabled with this pr so no surprises

@bkueng
Copy link
Member Author

bkueng commented Sep 25, 2018

Thanks @Avysuarez and @santiago3dr. Let's merge.

@bkueng bkueng merged commit 525531f into master Sep 25, 2018
@bkueng bkueng deleted the configurable_serial_ports_v2 branch September 25, 2018 05:53
@DonLakeFlyer
Copy link
Contributor

Anything QGC needs to do here?

@dagar
Copy link
Member

dagar commented Sep 25, 2018

@DonLakeFlyer short term getting the metadata to auto update would be a helpful improvement. #9615 (comment)

It doesn't need to happen immediately, but I'd also like to get a QGC configure screen for the serial ports (per board metadata) that pulls together all the possible options for each port. We should probably discuss this on a call.

@DonLakeFlyer
Copy link
Contributor

@dagar Can you start QGC issue for the serial port page and a separate one for parameter meta data auto-update?

@dagar
Copy link
Member

dagar commented Oct 1, 2018

@dagar Can you start QGC issue for the serial port page and a separate one for parameter meta data auto-update?

Serial port configuration page - mavlink/qgroundcontrol#6905
Parameter metadata autoupdate - mavlink/qgroundcontrol#6906

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.

9 participants