Skip to content
This repository has been archived by the owner on Jul 23, 2018. It is now read-only.

Optional Input Nodes #34

Closed
beetleskin opened this issue Jan 17, 2018 · 4 comments
Closed

Optional Input Nodes #34

beetleskin opened this issue Jan 17, 2018 · 4 comments
Milestone

Comments

@beetleskin
Copy link

beetleskin commented Jan 17, 2018

Hi, I got the use-case of an aggregation node that accumulates data from nodes of a certain type. Specifically: I got several nodes producing GeoJson data. Now I want to accumulate those with a Section or Widget. For the section, at least one GeoJson is required, but in general the inputs are optional. I just want to render what's available from the bag, i.e. sometimes some topics are missing and one or another GeoJson node fails. I wonder how to model this situation correctly with Marv:

Either I collect all nodes of a certain type, e.g.:

@marv.node(Section)
@marv.input('geojson_streams', default=[magically collect all GeoJson nodes])
def my_trajectory_section(geojson_streams):
  geojson_streams = marv.pull_all(*geojson_streams)
  if not any(all_geojson_streams):
    # no valid input, nothing to do
    raise marv.Abort()
  for s in geojson_streams:
    geojson = marv.pull(s)
    if geojson is not None:
      # do something with valid s

or I list all nodes explicitly:

@marv.node(Section)
@marv.input('geojson_stream_a', default=geojson_node_a)
@marv.input('geojson_stream_b', default=geojson_node_b)
...
@marv.input('geojson_stream_n', default=geojson_node_n)
def my_trajectory_section(geojson_streams_a, geojson_stream_b):
  geojson_streams = marv.pull_all(geojson_streams_a, geojson_streams_b)
  if not any(geojson_streams):
    # no valid input, nothing to do
    raise marv.Abort()
  for s in geojson_streams:
    geojson = marv.pull(s)
    if geojson is not None:
      # do something with valid s

The first solution does not exist afaik. The second solution fails, since the my_trajectory_section fails resp. is not executed, if any of its inputs are missing.

@chaoflow
Copy link
Member

chaoflow commented Feb 3, 2018

@beetleskin For the moment, the best solution seems to be the second one in combination with using bagmeta as an input and to pull the other inputs depending on which topics are listed on bagmeta, i.e. available. What do you think?

@beetleskin
Copy link
Author

Sounds like a workaround, but how would I do that? How would I pull streams within a node depending on some condition (e.g. whether a topic is available in bagmeta), I thought one needs to declare that with the @marv.input(..) decorator ..?

@chaoflow
Copy link
Member

chaoflow commented Mar 5, 2018

@beetleskin you would declare all that you know can exist, but pull only those that you know exists (from reading bagmeta).

Do your geojson nodes differ in code or do they only consume different topics?

@chaoflow
Copy link
Member

@beetleskin Your first initially described solution is tracked as feature request in https://github.com/ternaris/marv-robotics/issues/38 and optional inputs are now supported. See https://ternaris.com/marv-robotics/docs/patterns.html#optional-inputs.

@chaoflow chaoflow added this to the 3.4 milestone Jul 22, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants