Code Monkey home page Code Monkey logo

competition-simulator's Introduction

competition-simulator

Github Actions Github Actions

A simulator to be used for the Student Robotics Virtual Competition

Installation instructions

Take a look at the docs.

Overview

Within the IDE, there are a few different panels:

  • In the centre of your screen is the 3D simulated view of the arena
  • On the left is a tree hierarchy of all elements in this "world"
  • At the bottom is your console
  • At the top are your general controls which include the time controls. Press the centre play button to run the simulation at normal speed.

Important: Changes to the world must happen with the simulation paused at 0:00. If e.g. you move an object at a different time, rewinding back to the start will delete your changes.

On first run, the robot will execute an example program. On first run, this will be copied to the directory competition-simulator is stored in to make updating easier:

.
├── competition-simulator
│   ├── controllers
│   │   ├── example_controller
│   │   └── sr_controller
│   ├── ...
│   └── worlds
└── robot.py

Development

In addition to the basic setup for running the simulator, if you are intending to work on our wrapper API, our controllers or other helper scripts then you should also install the linting requirements:

pip install -r script/linting/requirements.txt
pip install -r script/typing/requirements.txt

You can then run all linting/type checking/tests in one go using script/check.

Running Webots

While the default location that our controllers look for robot.py files is the directory above the repo, that is not particularly convenient for development. Instead you may wish to run Webots having set the ARENA_ROOT environment variable to a suitable location. This is also how run-comp-match configures the arena to use when it runs matches.

For example, you may find it convenient to have a robots directory within the repo and then have a number of code and arena directories within that:

robots
├── arena  # A development arena with a single (symlinked) robot
│   └── robot.py -> ../ultrasounds/robot.py
├── brakes-arena  # A competition style arena with two robots
│   ├── zone-0
│   │   └── robot.py
│   └── zone-1
│       └── robot.py
├── dancer  # Some robot code for a robot which dances
│   └── robot.py
├── single-arena  # A competition style arena with a single (symlinked) robot
│   └── zone-0 -> ../dancer/
└── ultrasounds  # Some robot code for testing ultrasound sensors
    └── robot.py

Given a setup like the above, running Webots such that it picks up on one of the arena directories is possible through setting the ARENA_ROOT to an absolute path when launching the webots process:

$ ARENA_ROOT=$PWD/robots/brakes-arena webots --mode=pause worlds/Arena.wbt

This will launch Webots using our world file, with the simulation paused and the controllers (when started) will use the robots within brakes-arena.

Note: webots has a number of useful command line flags which are quite useful. We won't document them here, though you are encouraged to run webots --help to explore them yourself.

Competition Mode

In Competition Mode the simulation behaves slightly differently:

  • the simulation exits after the game completes
  • an animation recording is made of the simulation
  • a video recording is made of the simulation

If a match is being run, then the log of score-impacting events is also output into the match file.

Competition mode is enabled when a robot_mode.txt marker file is found in the arena directory and that file contains only the text comp:

echo comp > robot_mode.txt

The match file is a separate match.json file, also in the arena directory. This file conforms to the Proton spec and is used to enable integration with SRComp. Primarily this file captures score-relevant data for SRComp, however it also supports some other keys which are useful in development. See the MatchData structure for details.

During an actual competition, matches will be run using the run-comp-match script, which is documented below. Note however that it consumes robot code from a Zip archive rather than a directory. Suitable archives contain a robot.py at their root and thus can be created (for some team ABC) using:

zip ABC.zip robot.py

Doing a release

  1. Merge all the desired changes into main and push

  2. Let CI run, ensure it passes

  3. Create an annotated tag:

    git tag srYYYY.N --annotate

    N is a 1-based number for the revision of the rules. 0 is reserved for a release before the start of the competition year, if there is one. 1 should ideally be the initial release containing the game for the given year. Greater numbers correspond to revisions during the year.

    The tag annotation message should contain a summary of the changes in the revision, typically this can be similar to the revision log within the document itself. See the previous tags for the common format, for example git show sr2024.0 or git show sr2023.5.

  4. Push the tag: git push --tags

  5. Wait for CI to create the GitHub release, build a zip archive and upload it to the release

  6. Update the docs to point to the new archive

  7. Announce the update to teams via Discord and email

Running competition matches

In order to run competition matches you'll need to:

  1. Install the third party libraries the teams are depending on, into the same Python environment as will be running their code:

    pip install -r libraries.txt

    Note: you can change the version of Python which Webots uses from the UI -- go to "Tools" > "Preferences" > "General" > "Python command".

    We are using Python 3.8, though it shouldn't matter whether it's a system install or a virtual environment.

  2. Launch webots and configure it for recordings:

    • close the robot-camera overlays which appear on top of the main view

    • in "Tools" > "Preferences" > "OpenGL" set:

      • Ambient Occlusion to Disabled,
      • Texture Quality to High,
      • Disable shadows to false, and
      • Disable anti-aliasing to false

    Then close webots.

  3. Run the match:

    competition-simulator/script/run-comp-match <directory containing team code> <match number> <Zone 0 TLA> <Zone 1 TLA>

    Note: use a dash instead of a TLA if a robot is not present.

    This will orchestrate everything to run the match, including running webots and collecting together the logs and recordings. The logs & recordings will be within the directory which contains the team code, as follows:

    • The teams' logs will be in a directory named for their TLA
    • The match file (suitable for SRComp) will be within a matches directory
    • The recordings will be within a recordings directory

    Note: you may see an error like the following regarding the video creation:

    [libx264 @ 0x562cf1ba9840] Error: 2pass curve failed to converge
    [libx264 @ 0x562cf1ba9840] target: 20250.00 kbit/s, expected: 3339.51 kbit/s, avg QP: 0.0252
    [libx264 @ 0x562cf1ba9840] try reducing target bitrate
    

    This warns that we have requested a higher bit-rate from the video than is possible given the images the simulation generates. It does not appear to create any issues with the rendered videos, though you are encouraged to check that your setup is recording the videos correctly.

If webots is not available on PATH (such as on Windows by default) you can pass the full path to the webots executable using the WEBOTS_EXECUTABLE environment variable.

Collecting up logs for the Discord bot

The zip-comp-logs command allows logs to be collated into a zip with certain combinations of match animations. To create the zip file used by the discord bot to distribute the logs use the command:

./script/zip-comp-logs <archive-folder> <output-folder> --with-combined--animations all [--suffix=<zip-name-suffix> ]

Once the the zip files have been generated the zip file beginning "combined" can be used with the discord bot.

competition-simulator's People

Contributors

13ros27 avatar adimote avatar antoinepetty avatar jennylynnfletcher avatar oliverwales avatar peterjclaw avatar prenouf avatar prophile avatar raccube avatar realorangeone avatar sedders123 avatar willb97 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

competition-simulator's Issues

Decide on Ruggeduino initialisation

At the moment there is no initialisation of pins for the ruggeduino in our API. On the real kit you need to set the pinmode before use. Need to decide on which option to go with and either write code or document this change.

Add sounds to simulation

This should help the viewer understand what's happening but there's definitely potential for this to just be annoying

Document device connectivity

Need some sort of documentation (Maybe diagrams) to show how we're modelling the motors/sensors against the SR kit

Rules update

Review and update rules where needed for the virtual competition

Fix Echo's weight distribution

Echo tips quite easily. Not sure what level we consider to be a feature instead of a bug but at the moment it seems to be on the side of bug

Raise arena wall

Currently the distance sensors seem to look over the wall into infinity

Add IDE support

It would be great if we could support competitors continuing to use the IDE for their development if they want to.

For this, we need:

  • a script which can build a suitable archive on exporting from the IDE, which will need access to the content of this repo for inclusion (#87)
  • to configure the IDE (either in the IDE itself or our puppet config) to use that script
  • to configure the IDE to use this API as its reference (just using the code from this repo might work, though that should be tested)
  • to configure the IDE for Python 3 code being developed

For the archive script, it needs to be executable with three positional command line arguments and live inside a git repo. These are the arguments it will be passed:

  • the TLA
  • the directory containing the user code
  • the destination archive to create (will be a .zip)

The user code directory will be a folder called user within a temporary directory that the script can use as it sees fit. All content of the folder (which may include "hidden", i.e: dot prefixed, files) should be included in the archive.

For context, though this should not be relied upon: the script will be checked out also within the temporary directory, as a sibling of the user directory:

/tmp/tmp-ide-checkout  # will actually be a randomised `mktmp` style name
├── ilbRobot
│   ├── ...
│   └── .git
└── user
    ├── robot.py
    ├── ...
    └── .user-rev

The current directory when the script is run is not defined.

Lighting effects

Lighting effects similar to the actual competition.

For example

  • dark before the match starts
  • brightly lit during match
  • dark after match

Relative texture paths

Currently the project has absolute paths to the files. Should be relative to the project directory

Arena markers

Add markers to the arena wall so that the robots can work out where they're pointing

Distribution to teams

Figure out a way to distribute the simulator to teams
It needs to be super simple for them to create and test their code

Arena corner colours

Colour (+number?) corners of arena as we would in reality to show which corner is related to each bot.

You can see the colours and numbers in this photo from last year's competition:
image

At the moment our arena is blank
image

Fix gripper controls

Currently the gripper behaviour with the SR wrapper isn't very logical. Preferably one motor to lift and one motor to open/close.

Grabber

Investigate grabber functionality

Live scoring

Implement a way to score each round automatically (and display this on screen?)

This will involve at least:

  • checking that we can detect cases where an object is "inside" or "touching" another object (at least in the 2D arena sense, possibly as well as implementing the three-corner rule or similar)
  • recording changes to that state, either as a log of change events or as snapshots of the new state on change, or similar so that we can replay the scoring later; likely we'd want match-timestamps here to help line up to the animation

I suggest that we probably want a separate Supervisor to handle the scoring, if Webots supports having more than one.
Note that this scoring Supervisor may need to communicate with the arena Supervisor (see #216), so it may make sense for them to be the same process.

Validate apparent size/distance of token makers

I have a feeling that the vision system may be slightly off in its representation of the size and or distance of the token makers.

The discrepancy originates in the fact that the MarkerInfo.size value should be the size of the marker not the token, the former being smaller than the latter by enough to put tape around the marker for the construction of the token.

However the code currently uses only a single value for both concepts. This means that either:

  • the size of the maker is misreported
  • the size of the token is incorrect

Depending on other interactions, due to the way that the distance to the marker is calculated (relative to the centre of the token), this may also mean that the distance to the marker is misreported.

Fix clipping

Sometimes the robot loses parts of itself or manages to fall through things. We should fix this.

Validate vision of arena wall markers

In the current model, there's a concern that Arena wall markers likely behave weirdly due to the size of a Token (which assumes they are cubes).

We should validate that, when looking sideways at a wall marker, the camera only reports a single face as visible (or none at all if it's only obliquely seen). It doesn't matter what "name" that face has.

Pull out mapping function

sensor_devices.py and motor.py both have a way to convert one range of values to another. This should be pulled out into a common file

Development instructions

It would be great if we could have some instructions on how to setup a development environment :)

Arena markers

We need a way of detecting arena walls and positioning things in the arena.

We need things on the arena walls which look like tokens, but respond to Webots' existing vision (#2).

Automatic Match Stop

After the duration of a match, robots automatically stop. We should have this!

Whether this is implemented as a pause on the simulation, or by killing the robot code doesn't especially matter.

Make material paths relative

image
As highlighted by a team on the forum, the paths to certain textures are Windows-specific. They should work on any platform

Add all Echo bot sensors to API

Echo has a few different sensors. Ideally we will enable all distance/bump sensors through the Ruggeduino part of the API

Aesthetic customisation of robot

Teams could do with a way to customise the way their robot looks. This would need to be easily changeable by the blueshirts running the code though (so they don't need to manually load individual texture files each time that robot competes). Not sure how we could do this.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.