Exemple #1
0
from interface import Gazebo
import scenic.syntax.translator as translator
"""
Calls on a file and writes the generated scenario to an sdf file
"""

# Input and output file name
fileName = "examples/gazebo/uuv.sc"
worldName = "empty_underwater"
outFile = "examples/gazebo/outputs/uuv_sim.world"

# Load scenario from file
print('Beginning scenario construction...')
startTime = time.time()
scenario = translator.scenarioFromFile(fileName)
totalTime = time.time() - startTime
print(f'Scenario constructed in {totalTime:.2f} seconds.')

Gazebo.write(scenario)


def generateScene():
    startTime = time.time()
    scene, iterations = scenario.generate(verbosity=3)
    totalTime = time.time() - startTime
    print(
        f'  Generated scene in {iterations} iterations, {totalTime:.4g} seconds.'
    )
    return scene, iterations
Exemple #2
0
import time
from scenic.simulators.gazebo.interface import Gazebo
import scenic.syntax.translator as translator
"""
Calls on a file and writes the generated scenario to an sdf file
"""

# Input and output file name
scenarioFile = "examples/gazebo/uuv.sc"
outFile = "examples/gazebo/outputs/uuv_sim.world"
worldName = "empty_underwater"

# Load scenario from file
print('Beginning scenario construction...')
startTime = time.time()
scenario = translator.scenarioFromFile(scenarioFile)
totalTime = time.time() - startTime
print(f'Scenario constructed in {totalTime:.2f} seconds.')

# Generate a scene from scenario file, then fill out a gazebo world file from scene
startTime = time.time()
scene, iterations = scenario.generate(verbosity=3)
totalTime = time.time() - startTime
print(
    f'  Generated scene in {iterations} iterations, {totalTime:.4g} seconds.')
output = Gazebo.fill_world(scene, worldName)

# Write generated world to file
with open(outFile, 'w+') as fileObj:
    fileObj.write(output)
Exemple #3
0
# Parse arguments and set up configuration
args = parser.parse_args()
delay = args.delay
translator.showInternalBacktrace = args.full_backtrace
translator.dumpTranslatedPython = args.dump_python
translator.dumpFinalAST = args.dump_ast
translator.verbosity = args.verbosity
translator.usePruning = not args.no_pruning
if args.seed is not None:
    print(f'Using random seed = {args.seed}')
    random.seed(args.seed)

# Load scenario from file
print('Beginning scenario construction...')
startTime = time.time()
scenario = translator.scenarioFromFile(args.scenario)
totalTime = time.time() - startTime
print(f'Scenario constructed in {totalTime:.2f} seconds.')


def generateScene():
    startTime = time.time()
    scene, iterations = scenario.generate(verbosity=args.verbosity)
    if args.verbosity >= 1:
        totalTime = time.time() - startTime
        print(
            f'  Generated scene in {iterations} iterations, {totalTime:.4g} seconds.'
        )
    return scene, iterations

Exemple #4
0
translator.dumpTranslatedPython = args.dump_initial_python
translator.dumpFinalAST = args.dump_ast
translator.dumpASTPython = args.dump_python
translator.verbosity = args.verbosity
translator.usePruning = not args.no_pruning
if args.seed is not None and args.verbosity >= 1:
    print(f'Using random seed = {args.seed}')
    random.seed(args.seed)

# Load scenario from file
if args.verbosity >= 1:
    print('Beginning scenario construction...')
startTime = time.time()
scenario = errors.callBeginningScenicTrace(
    lambda: translator.scenarioFromFile(args.scenicFile,
                                        params=dict(args.param),
                                        model=args.model,
                                        scenario=args.scenario))
totalTime = time.time() - startTime
if args.verbosity >= 1:
    print(f'Scenario constructed in {totalTime:.2f} seconds.')

if args.simulate:
    simulator = errors.callBeginningScenicTrace(scenario.getSimulator)


def generateScene():
    startTime = time.time()
    scene, iterations = errors.callBeginningScenicTrace(
        lambda: scenario.generate(verbosity=args.verbosity))
    if args.verbosity >= 1:
        totalTime = time.time() - startTime
Exemple #5
0
def main():
    args = setup_arg_parser()
    setup_logging(args.verbose)

    delay = args.delay
    errors.showInternalBacktrace = args.full_backtrace
    if args.pdb:
        errors.postMortemDebugging = True
        errors.showInternalBacktrace = True
    translator.dumpTranslatedPython = args.dump_initial_python
    translator.dumpFinalAST = args.dump_ast
    translator.dumpASTPython = args.dump_python
    translator.verbosity = 3 if args.verbose else 1
    translator.usePruning = not args.no_pruning
    if args.seed is not None:
        logger.info(f'Using random seed = {args.seed}')
        random.seed(args.seed)

    with open(args.input, 'r') as f:
        input_objects = yaml.load(f)
    input_dir = os.path.dirname(args.input)
    models_dir = input_objects.get('models_dir', '')

    if not args.load:
        load_module('gzscenic/base.scenic')
        if args.dump:
            with open(args.dump, 'w') as f:
                f.write('from gzscenic.base import *\n\n')
        for obj in input_objects['models']:
            print(generate_model(obj, input_dir, models_dir, args.dump))
    else:
        if args.load.rpartition('.')[-1] not in ['sc', 'scenic']:
            raise Exception('The file to be loaded needs to be .sc or .scenic')
        load_module(args.load)

    # Load scenario from file
    logger.info('Beginning scenario construction...')
    startTime = time.time()
    scenario = errors.callBeginningScenicTrace(
        lambda: translator.scenarioFromFile(args.scenicFile,
                                            params=dict(args.param),
                                            model=args.model,
                                            scenario=args.scenario))
    totalTime = time.time() - startTime
    logger.info(f'Scenario constructed in {totalTime:.2f} seconds.')

    if not args.noplt:
        import matplotlib.pyplot as plt
    success_count = 0
    while not args.scenes_num or success_count < args.scenes_num:
        scene, _ = generateScene(scenario, args)
        if not args.noplt:
            if delay is None:
                scene.show(zoom=args.zoom)
            else:
                scene.show(zoom=args.zoom, block=False)
                plt.pause(delay)
                plt.clf()

        scene_to_sdf(scene, input_dir, input_objects['world'], models_dir,
                     args.outputPath)
        success_count += 1
    "sim/weather/runway_friction", "sim/weather/wind_direction_degt[0]",
    "sim/weather/wind_speed_kt[0]"
]


def run_sampler(sampler, xp_client, samples=10):

    for _ in range(samples):
        scene, _ = sampler.generate()
        params = scene.params

        wind_speed = scene.params['wind_speed']
        wind_direction = scene.params['wind_direction']
        friction = scene.params['friction']
        print(wind_speed, wind_direction, friction)
        xp_client.sendDREFs(condition_drefs,
                            [friction, wind_direction, wind_speed])
        time.sleep(5)


if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument('-s',
                        '--scenario',
                        help='Scenic scenario to run',
                        default='conditions.sc')
    args = parser.parse_args()
    sampler = translator.scenarioFromFile(args.scenario)
    client = XPlaneConnect()
    run_sampler(sampler, client, samples=10)
Exemple #7
0
            pass
    params[name] = value
translator.dumpTranslatedPython = args.dump_initial_python
translator.dumpFinalAST = args.dump_ast
translator.dumpASTPython = args.dump_python
translator.verbosity = args.verbosity
translator.usePruning = not args.no_pruning
if args.seed is not None and args.verbosity >= 1:
    print(f'Using random seed = {args.seed}')
    random.seed(args.seed)

# Load scenario from file
if args.verbosity >= 1:
    print('Beginning scenario construction...')
startTime = time.time()
scenario = errors.callBeginningScenicTrace(lambda: translator.scenarioFromFile(
    args.scenicFile, params=params, model=args.model, scenario=args.scenario))
totalTime = time.time() - startTime
if args.verbosity >= 1:
    print(f'Scenario constructed in {totalTime:.2f} seconds.')

if args.simulate:
    simulator = errors.callBeginningScenicTrace(scenario.getSimulator)


def generateScene():
    startTime = time.time()
    scene, iterations = errors.callBeginningScenicTrace(
        lambda: scenario.generate(verbosity=args.verbosity))
    if args.verbosity >= 1:
        totalTime = time.time() - startTime
        print(