NUbots/NUWebots

Communications between Webots and the NUbots container

KipHamiltons opened this issue · 6 comments

In today's meeting, we went fairly deep into the details of what needs to be done to fully implement networking so that our codebase can compete at robocup. The gist (as I understand it) is that the TCP word in NUClear only implements the server side of things for TCP, whereas what we need for Webots is a working client side.

Some details from today's meeting are:

  • We need to sort out what we need to send to Webots - how do we need to modify ServoTarget messages to comply with what they're expecting, etc.
  • The packets containing protobuf messages might cut them into pieces, which we need to deal with
  • We need to monitor the receiving buffer consistently and know when to flush it
  • More stuff going into details that I can't remember

This issue serves to document those details so that the many people we have enlisted to get things rolling for Robocup have something concrete to go off. We have people ready to contribute, but we don't really know how to get started.

The only bit I captured in addition to that from today's meeting was that the general idea is to pass the the file descriptor you get from opening a TCP socket to the on_io keyword in NUClear (no idea what that means in its own context, but that's what I heard)

@CMurtagh-LGTM 's draft PR#394 in NUbots/NUbots is the foundation of the client side of networking.
It is unfinished, with work specifically to be done in webots.cpp on lines 101 to 129, 140, 171 to 178 and 186. Some of these lines have comments indicating we need to do a conversion from our ServoTarget messages to webots' ActuatorRequests.

Update to where it's at as of right now:

  • There are a few compiler errors left. These are mostly to do with use of fancy neutron methods, which have to be sorted out.
  • The actual conversion between message types hasn't been touched yet. That's the stuff from lines 132-160 of webots.cpp in this commit. This is probably the easiest contribution left for that PR (for people other than Cameron).
  • I'm not sure how we tested the communication code from #1, but we will need some (hopefully similar) way to test the connection capabilities of the NUbots communications PR too.
ysims commented

The most basic form of testing the basic TCP communications is to add the RobotControl.proto to NUbots and get the NUbots webots module to do the same thing that the test program does, starting about here, which is after it connects to the server.

Things to do for the devday:

  • Checkout cmurtagh/webots_communication on NUbots and build the webots role (see NUbook for how to build a role). This role, in addition to webots_keyboard, includes the webots module, which handles the communication. Difference between the two roles:
    • webots: connect only, with a simple message being sent
    • webots_keyboard: attempts to make keyboard walk work with the simulated robot in Webots, doesn't work at the moment
  • Checkout sims/communication on NUwebots
  • Compile the nugus_controller:
    • mkdir build && cd build
    • cmake ..
    • make -j$(nproc)
  • Run Webots and open the kid.wbt world from the NUwebots folder. Once loaded, run the simulation (click play in the toolbar). This will run the controller and start the TCP server to wait for the NUbots side to connect.
  • Run the built webots role in NUbots: ./b run webots. This will connect to Webots and attempt to send ActuatorRequests and receive Sensors. The current webots controller code crashes after it receives the initial actuator request. This is what needs investigation to start.

After fixing the crash and checking that the ActuatorRequest -> Sensors loop works:

  • Bandwidth limiting (make sure we don't send too much stuff to Webots, or the Robocup controller will disconnect us)
  • Get webots_keyboard working over comms in webots
  • Check images received from webots to see if they're good (perhaps dump received image bytes to file and open in an image viewer)
  • Update webots module in NUbots to get the TCP server hostname and port from an ENV variable, instead of from the config, for Robocup.

image

Communications work with NUbots.
For future reference: Make sure that your game.json in the webots repo has the correct IPs, the udp filter is set properly in webots.yaml in the NUbots repo, and that the UDP filter is set properly via environment variable when running webots, although these details should be in NUbook