innovationOUtside / nbev3devsim

Ev3DevSim ipywidget in Jupyter notebooks
Apache License 2.0
5 stars 0 forks source link

World definition #61

Open psychemedia opened 4 years ago

psychemedia commented 4 years ago

When we load a background into the simulator, we can also set obstacles, robotSpecs and arobotState` values. For example:

if (map == 'WRO 2019 Regular Junior') {
    sim.loadBackground(imagepath + 'WRO-2019-Regular-Junior.jpg');
    sim.clearObstacles();
    sim.clearObstaclesLayer();

    // Set original robot position via robotState
    setPos(2215, 150, 90, true);

  } else if (map == 'Radial grey') {
    //Load background
    sim.loadBackground(imagepath + '_radial_grey.png');
    sim.clearObstacles();
    sim.clearObstaclesLayer();

    //Update robot config
    sim.robotSpecs.sensor1.x = -60;
    sim.robotSpecs.sensor2.x = 60;
    sim.loadRobot(sim.robotSpecs);
    sim.drawAll();

    //Set initial location
    setPos(100, 400, 0, true);

  } else if (map == 'Obstacles Test') {
    sim.loadBackground(imagepath + 'Obstacles_Test.png');
    setPos(121, 125, 90, true);
    sim.clearObstacles();
    sim.clearObstaclesLayer();
    sim.loadObstacles([
      [46, 388, 150, 150],
      [479, 704, 150, 150],
      [852, 388, 150, 150],
      [1374, 388, 150, 150],
      [1758, 900, 150, 150],
      [2126, 388, 150, 150]
    ]);

It would be useful to define a simple configuration format that can be passed to a world configuration when a background is loaded.

The simplest approach might be to have paired image and configuration files (my_world.png and my_world.js or my_world.json). Another approach might be to try to bake the metadata into the image, eg text metadata within the PNG file.

See also: