cvra / robot-software

CVRA monorepo - All software running on our bots lives here
MIT License
44 stars 21 forks source link

Export config from PID plotter #182

Closed Lu-ni closed 5 years ago

Lu-ni commented 5 years ago

Print the YAML config in the terminal.

ex:

    demo:
        control:
           mode: 0
            current:
                i_limit: 42.0
                kd: 12.0
                ki: 42.0
                kp: 42.0
            position:
                i_limit: inf
                kd: 32.0
                ki: 3.0
                kp: 0.0
            velocity:
                i_limit: inf
                kd: 0.0
                ki: 0.0
                kp: 0.0
           torque_limit: inf
           velocity_limit: 3.4028234663852886e+38
           acceleration_limit: inf
           low_batt_th: -1.0000303983688354
        motor:
           torque_cst: 1.0
        encoders:
            primary:
                p: 2
                q: 1
                ticks_per_rev: 1024
            secondary:
                p: 3
                q: 1
                ticks_per_rev: 1024
        potentiometer:
           gain: 1.0
           zero: 0.0
        rpm:
           phase: 0.0
        thermal:
           Cth: inf
           Rth: 1.0
           current_gain: 1.0
           max_temp: inf
        streams:
           current: 0.0
           velocity: 10.0
           position: 10.0
           index: 10.0
           enc_pos: 0.0
           motor_pos: 10.0
           motor_torque: 10.0

Ready to bake

antoinealb commented 5 years ago

Note sure what this is for, but your print_param function does not correctly handle many nested levels. Use yaml.dump instead.

Example:

import yaml

params = {
    'pid': {
        'kp': 12.,
        'ki': 8,
        'kd': 42,
        'foo': 'bar',
        'baz': {
            'lol': 21
        }
    }
}

print(yaml.dump(params, default_flow_style=False))
SyrianSpock commented 5 years ago

This is the last improvement listed in #136

SyrianSpock commented 5 years ago

@antoinealb won't work because params are stored as a NestedDict, a custom class I defined as datamodel that makes it easier to deal with hierarchies. @Lu-ni would need to implement a NestedDict to dict converter to use PyYaml :cry:

SyrianSpock commented 5 years ago

@antoinealb won't work because params are stored as a NestedDict, a custom class I defined as datamodel that makes it easier to deal with hierarchies. @Lu-ni would need to implement a NestedDict to dict converter to use PyYaml cry

which it turns out is straightforward. NestedDict derives from defaultdict (from collections) that converts to dict :tada: