robotika / osgar

Open Source Garden (Autonomous) Robot
MIT License
13 stars 11 forks source link

driver.replay - register channels #976

Closed tajgr closed 5 months ago

tajgr commented 5 months ago

It allow add channels with ":" in configs for replay driver. E.g.:

"driver": "replay",
        "init": {
          "filename": null,
          "pins":{
            "oak_d.depth": "depth:null"
          }

Moreover, there is improved --parrams flag from osgar.record. It is easier to set string value now. E.g.: --params app.filename=data/logy_23/some.log

m3d commented 5 months ago

Can you add test explaining this change? I am also not sure I understand the improvement, so if evaluation fails it is handled as string? What would be the former command? --params app.filename="data/logy_23/some.log"?

tajgr commented 5 months ago

so if evaluation fails it is handled as string? What would be the former command?

Yes, it is handled as string (it is string already). The former command would be --params app.filename="'data/logy_23/some.log'" which is unintuitive from my point of view.

tajgr commented 5 months ago

The first part is clear?

m3d commented 5 months ago

my today's experience:

(osgar) md@md-ThinkPad-P50:~/git/osgar$ python -m osgar.record config/fr07-go.json --param app.max_speed=02 --note "test venku na snehu"
Traceback (most recent call last):
  File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/home/md/git/osgar/osgar/record.py", line 104, in <module>
    main()
  File "/home/md/git/osgar/osgar/record.py", line 99, in main
    cfg = config_load(*args.config, application=args.application, params=args.params, without=args.without)
  File "/home/md/git/osgar/osgar/lib/config.py", line 53, in config_load
    ret['robot']['modules'][key[0]]['init'][key[1]] = literal_eval(str_value)
  File "/usr/lib/python3.8/ast.py", line 59, in literal_eval
    node_or_string = parse(node_or_string, mode='eval')
  File "/usr/lib/python3.8/ast.py", line 47, in parse
    return compile(source, filename, mode, flags,
  File "<unknown>", line 1
    02
     ^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers

well, up-to-today i did not know that integers could not start with 0 (yes, it was mistake, btw, it should be 0.2) ... and it would be automatically cast as string = dangerous.

osgar) md@md-ThinkPad-P50:~/git/osgar$ python
Python 3.8.10 (default, Nov 22 2023, 10:22:35) 
[GCC 9.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> 02
  File "<stdin>", line 1
    02
     ^
SyntaxError: leading zeros in decimal integer literals are not permitted; use an 0o prefix for octal integers
>>> exit()
m3d commented 5 months ago

The first part is clear?

not really, I am not sure what is the use case? That could test explain??

tajgr commented 5 months ago

would be automatically cast as string = dangerous

Ok. I understand, it should crash during loading rather. This part is just "nice to have". I will replace it by some comment in parrams flag.

tajgr commented 5 months ago

not really, I am not sure what is the use case? That could test explain??

There is an example config:

{
  "version": 2,
  "robot": {
    "modules": {
      "log": {
        "driver": "replay",
        "init": {
          "filename": null,
          "pins":{
            "lidar.scan": "scan:null",
            "gps.position": "position:null",
            "oak_d.depth": "depth:null",
            "oak_d.color": "color:null",
            "oak_1.color": "color_1:null"
          },
          "sleep_channel": ["depth", 0.1]
        }
      },
      "lidar": {
          "driver": "tools.dummy_node:DummyNode",
          "in": ["raw"],
          "out": ["scan"],
          "init": {
            "channels": ["scan"]
          }
      },
      "gps": {
          "driver": "tools.dummy_node:DummyNode",
          "in": ["raw"],
          "out": ["position"],
          "init": {
            "channels": ["position"]
          }
      },
       "oak_d": {
          "driver": "tools.dummy_node:DummyNode",
          "init": {
            "channels": ["depth", "color"]
          }
      },
       "oak_1": {
          "driver": "tools.dummy_node:DummyNode",
          "init": {
            "channels": ["color"]
          }
      },
      "height": {
        "driver": "height_node:HeightNode",
        "init": {
          "plots_map": null
        }
      }
    },
    "links": [
      ["log.scan", "lidar.scan"],
      ["log.scan", "height.scan"],

      ["log.position", "gps.position"],
      ["log.position", "height.position"],

      ["log.depth", "oak_d.depth"],
      ["log.depth", "height.depth"],

      ["log.color", "oak_d.color"],
      ["log.color_1", "oak_1.color"]
    ]
  }
}

I have a very large log (10 GB). I am testing a tool to analyze it and I need to add one stream to the log. So I modified the HeightNode and ran the record with the above mentioned config. Node "replay" reads the log and publishes individual streams. But I need the data to be found in streams with the same name as in the original log. That's why DummyNode is included. These nodes only rename the received streams. If I used the original replay node, the 10 GB log would become a 20 GB log. I need to "replay" more of these logs.

tajgr commented 5 months ago

The DummyNode is in another repo and it is not part of this PR.

tajgr commented 5 months ago

Thanks