BB2B with networking (Python)

Compared to the original BB2B script we created for Python, the difference is small: we only need to add one line and update another.

The participant

When we want to have communication between robots and/or sites we need to add a participant to each application. Participants can join a collaboration and take care of all network communication.

In this example we already have created a Unity participant: the site server is a special type of participant which provides an environment in which multiple roboid participants can collaborate. We created this with the default communication port 7681.

Now we need to add a participant to our BB2B roboid which connects to this site server. For this we need to add the following line:

participant = ParticipantUDP(ip_address="127.0.0.1", port=7681, local_port=7682)

As we assume that the Unity site server and Python script run on the same machine, we need to connect to the site on the local host which has address "127.0.0.1". If you run the Unity site server on a different computer, you need to enter the IP address of that computer here. The Unity Site Server was running on the default port 7681, so we specify port 7681 here. We could have left this out, because it is the default value, but we include it here for clarity.

As we are running the Python BB2B roboid and the Unity Site Server on the same machine we cannot have both the BB2B application and the Site Server both use the same port, so we need to specifiy a different port for the Python application. We set it to 7682 by assigning this value to the local_port parameter.

Using the participant

Now we need to connect the roboid to this new participant which will ensure that the state of the roboid will be synchronized across the network. This is done by specifying the participant for the root thing of the roboid.

The root thing is the thing which does not have the parent. In our case this is the bb2b Differential Drive. The Touch Sensors and the model all have a parent: the bb2b Differential Drive. So we specify the participant as follows:

bb2b = DifferentialDrive(participant)

And that's all we have to change!

Running the setup

If we now start the Site Server, it will wait for other participants to join the site. Then we can start the python script as if everything goes well, you should see the BB2B roboid appearing in the Unity scene, diving around and colliding with the walls as a proper BB2B roboid should: