Protobufs (a brief explanation) - northern-bites/nbites GitHub Wiki

Using Protobufs:

Protobufs are the means by which Python behaviors communicate with the underlying robot architecture written in C++. This message passing interface allows behaviors to access information about the robot as well as send walking and kicking commands.

Protobufs can be found in the src/share/messages directory. Here are a couple examples:

PMotion.proto -- contains various motion protobufs. These are used to send commands for walking and kicking.

Vision.proto -- Used to get vision information (ie. what lines the robot currently sees)

Protobufs are invoked in a variety of ways, for example, walking commands are in the nav module, so to make a robot walk to a locations, the following code would be used: player.brain.nav.walkTo(RelRobotLocation, x, y, tilt), speeds.SPEED_SEVEN) However, the interface is accessed directly, so to reset the odometry of the player, the following code would be used: player.brain.interface.motionRequest.reset_odometry = True //set the command player.brain.interface.motionRequest.timestamp = int(player.brain.time * 1000) //sends the command Usage of most protobufs can be found by looking at the behaviors (src/man/behaviors/players/player_name_here.py)

Message Passing in Protobufs: Protobufs are a way for python to make requests to the C++ code. In every frame, the Behaviors Module (src/man/behaviors/BehaviorsModule.cpp) prepares all of the protobuf messages (BehaviorsModule::prepareMessages()) and then sends them (BehaviorsModule::sendsMessages(). These messages are then picked up by the C++ code and handled. To give an example of this, I will trace a motion command.

(1) The command is issued in the behavior player.brain.nav.walkTo(RelRobotLocation(100,0,0), speeds.SPEED_SEVEN)

(2) Navigator.py contains this function, and in turn calls goToPosition() in NavStates.py which makes calculations and calls setDestination() in NavHelper.py, which packages and issues the command.

After this, the python is done and C++ receives the message.

(3) In src/man/motion/MotionModule.cpp, the message is received in processMotionInput(). The message types are used to send the messages to the correct parts of the player architecture.