Ejemplo n.º 1
0
def print_config(directory, outdir):
    from reprep import Report

    get_vehicles_config().load(directory)

    def write_report(r):
        out = os.path.join(outdir, '%s.html' % r.nid)
        rd = os.path.join(outdir, 'images')
        logger.info('Writing to %r' % out)
        r.to_html(out, resources_dir=rd)

    worlds = get_conftools_worlds()
    r = Report('worlds')
    create_generic_table(r, 'VehiclesConfig', worlds, ['desc', 'code'])
    write_report(r)

    dynamics = get_conftools_dynamics()
    r = Report('dynamics')
    create_generic_table(r, 'VehiclesConfig', dynamics, ['desc', 'code'])
    write_report(r)

    sensors = get_conftools_sensors()
    r = Report('sensors')
    create_generic_table(r, 'VehiclesConfig', sensors, ['desc', 'code'])
    write_report(r)

    vehicles = get_conftools_vehicles()
    r = Report('vehicles')
    create_generic_table(r, 'VehiclesConfig', vehicles,
                          ['desc', 'dynamics', 'id_dynamics', 'sensors'])
    write_report(r)
Ejemplo n.º 2
0
def print_config(directory, outdir):
    from reprep import Report

    get_vehicles_config().load(directory)

    def write_report(r):
        out = os.path.join(outdir, '%s.html' % r.nid)
        rd = os.path.join(outdir, 'images')
        logger.info('Writing to %r' % out)
        r.to_html(out, resources_dir=rd)

    worlds = get_conftools_worlds()
    r = Report('worlds')
    create_generic_table(r, 'VehiclesConfig', worlds, ['desc', 'code'])
    write_report(r)

    dynamics = get_conftools_dynamics()
    r = Report('dynamics')
    create_generic_table(r, 'VehiclesConfig', dynamics, ['desc', 'code'])
    write_report(r)

    sensors = get_conftools_sensors()
    r = Report('sensors')
    create_generic_table(r, 'VehiclesConfig', sensors, ['desc', 'code'])
    write_report(r)

    vehicles = get_conftools_vehicles()
    r = Report('vehicles')
    create_generic_table(r, 'VehiclesConfig', vehicles,
                         ['desc', 'dynamics', 'id_dynamics', 'sensors'])
    write_report(r)
Ejemplo n.º 3
0
def instance_vehicle_spec(entry):
    from ..simulation import Vehicle
    from ..interfaces import VehicleSensor, Dynamics

    from vehicles.configuration.master import get_conftools_dynamics, \
        get_conftools_sensors


    check_valid_vehicle_config(entry)
    try:
        master = get_conftools_dynamics()
        if 'id_dynamics' in entry:
            id_dynamics = entry['id_dynamics']
            dynamics = master.instance(id_dynamics)
        else:
            id_dynamics = entry['dynamics']['id']
            dynamics = master.instance_spec(entry['dynamics'])

        assert isinstance(dynamics, Dynamics)

        sensors = entry['sensors']
        radius = entry['radius']
        extra = entry.get('extra', {})
        vehicle = Vehicle(radius=radius, extra=extra)
        vehicle.add_dynamics(id_dynamics, dynamics)
        master = get_conftools_sensors()

        for sensor in sensors:
            if 'id_sensor' in sensor:
                id_sensor = sensor['id_sensor']
                sensor_instance = master.instance(id_sensor)
            else:
                id_sensor = sensor['sensor']['id']
                sensor_instance = master.instance_spec(sensor['sensor'])
            assert isinstance(sensor_instance, VehicleSensor)

            # TODO: document this
            x, y, theta_deg = sensor.get('pose', [0, 0, 0])
            theta = np.radians(theta_deg)
            pose = SE2_from_translation_angle([x, y], theta)
            pose = SE3_from_SE2(pose)
            joint = sensor.get('joint', 0)
            extra = sensor.get('extra', {})
            vehicle.add_sensor(id_sensor=id_sensor,
                               sensor=sensor_instance,
                               pose=pose, joint=joint,
                               extra=extra)
        return vehicle
    except:
        logger.error('Error while trying to instantiate vehicle. Entry:\n%s'
                     % (pformat(entry)))
        raise
Ejemplo n.º 4
0
def dereference_vehicle_spec(x):
    ''' substitutes all references; modifies x. '''
    from vehicles.configuration.master import get_conftools_dynamics, \
        get_conftools_sensors

    check_valid_vehicle_config(x)
    if 'id_dynamics' in x:
        id_dynamics = x.pop('id_dynamics')
        x['dynamics'] = deepcopy(get_conftools_dynamics()[id_dynamics])
    for s in x['sensors']:
        if 'id_sensor' in s:
            id_sensor = s.pop('id_sensor')
            s['sensor'] = deepcopy(get_conftools_sensors()[id_sensor])
    check_valid_vehicle_config(x)