Tutorial: How Anki Vector communicates? Part 3

Part 3: Remote Procedure Calls (RPCs)

In the previous tutorials of this series taht describes the technologies that Anki Vector uses to communicate, we got an introduction to protocol buffers (Part 1), and maintaining secure connections (Part 2). In this article we discuss how Remote Procedure Calls (rpcs) are defined in Anki Vector.

What is a Remote Procedure Call (RPC)?

In layman terms, a Remote Procedure Call (RPC) is a service which can be called remotely. Once an RPC is defined and advertised, clients can make use of this service over a secure network connection by using a mutually understood message format. In the case of gRPC, this mutually understood format is the protocol buffer. This article is a good reference that explains how RPCs are defined in gRPC.

What kind of RPCs does Anki Vector define?

The RPCs supported by Vector are defined in this file. Let us briefly discuss the different kinds of RPCs supported by Vector.

  1. Unary RPCs. Unary RPCs are like remote function calls. Here is an example of the definition of an unary RPC from Anki Vector.

    // Moves Vector's lift.   
    rpc MoveLift(MoveLiftRequest) returns (MoveLiftResponse)   

    MoveLiftRequest and MoveLiftResponse protocol buffers which encapsulate the format in which the request and response parameters to move Vector’s lift (aka arms).

    In the case of a unary RPC, the client issues MoveLift() with a MoveLiftRequest and can wait till a MoveLiftResponse is received. All underlying communications are handled by gRPC.

  2. Server streaming RPCs: In server steaming RPCs, the client sends a request to the server and gets a stream to read a sequence of messages back from the server. The client can keep reading messages till the stream is closed. Here is an example of the definition of an server streaming RPC from Anki Vector.

    // Request an audio feed from the robot.                       rpc AudioFeed(AudioFeedRequest) returns (stream AudioFeedResponse) 
       option (google.api.http) = {                             
          post: "/v1/audio_feed",                             
          body: "*"

    In this case, the client requests Vector for the audio feed. Vector opens a stream using which the audio feed can be read.

  3. Bidirectional streaming: In bidirectional streaming, both sides send a sequence of messages to each other using a read-write stream. Here is an example of the definition of a bidirectional streaming RPC from Anki Vector.

    // Integrate with and acquire control of Vector's AI system.                       
    rpc BehaviorControl(stream BehaviorControlRequest) returns (stream BehaviorControlResponse) {                       

    In this case, the Behavior Control RPC allows the client to stream behavior control requests (which basically describe the degree to which the client wishes to override Vector’s default behavior). The client receives a stream of responses from Vector with information on how the behavior control requests were handled.

  4. Client streaming: In client streaming RPCs, the client writes a sequence of messages and sends them to the server. Once the request is complete, the client gets a response from the server.

    Anki Vector does not currently implement client steaming RPCs.

    Hope you are enjoying this series so far. In the next part, we will discuss how the Anki Vector SDK puts everything together with a demo program in which all the different types of RPCs are employed.

    Share Programmable Robots Newsletter