Previous
Parts, Sub-parts, Remotes
When building a smart machine application in the Viam app, a user typically begins by configuring their machine which can consist of one or more parts. Next they will test that it is wired up properly using the Viam app’s Control page. Once they’ve ensured everything is wired up properly, they will build their main application and the business logic for their machine using one of Viam’s language SDKs. This SDK-based application is typically run on either the main part of the machine or a separate computer dedicated to running the business logic for the machine.
Below, we describe the flow of information through a Viam-based multipart machine and then get into the specifics of what backs these connections and communications APIs.
To begin, let’s define our machine’s topology:
This machine is made of two parts and a separate SDK-based application, which we’ll assume is on a third machine, though it could just as easily run on the main part without any changes.
The first and main part, RDK Part 1, consists of a Raspberry Pi and a single USB connected camera called Camera.
The second and final part, RDK Part 2, consists of a Raspberry Pi connected to a robotic arm over ethernet and a gantry over GPIO.
RDK Part 1 will establish a bidirectional gRPC/WebRTC connection to RDK Part 2. RDK Part 1 is considered the controlling peer (client). RDK Part 2 is consider the controlled peer (server).
Let’s suppose our SDK application uses the camera to track the largest object in the scene and instructs the arm to move to that same object.
Since RDK Part 1 is the main part and has access to all other parts, the application will connect to it using the SDK. Once connected, it will take the following series of actions:
The points returned are respective to the reference frame of the camera. This will become important in a moment.
All component and service types in the RDK, and the Viam API for that matter, are represented as Protocol Buffers (protobuf) services. protobuf is a battle tested Interface Description Language (IDL) that allows for specifying services, their methods, and the messages that comprise those methods. Code that uses protobuf is autogenerated and compiles messages into a binary form.
gRPC is responsible for the transport and communication of protobuf messages when calling protobuf methods. It generally works over a TCP, TLS backed HTTP2 connection operating over framing see gRPC’s HTTP2 documentation for more.
The RDK uses protobuf and gRPC to enable access and control to its components and services. That means if there are two arms in a machine configuration, there is only one Arm service that handles the Remote Procedure Calls (RPC) for all arms configured.
In addition to gRPC, the RDK uses WebRTC video and audio streams and data channels to enable peer to peer (P2P) communication between machine parts as well as SDKs and the Remote Control interface.
An outline of how WebRTC is used lives on Go.dev, but in short, an RDK is always waiting on the Viam app (app.viam.com) to inform it of a connection requesting to be made to it whereby it sends details about itself and how to connect on a per connection basis. Once a connection is made, the Viam app is no longer involved in any packet transport and leaves it up to the two peers to communicate with each other.
Was this page helpful?
Glad to hear it! If you have any other feedback please let us know:
We're sorry about that. To help us improve, please tell us what we can do better:
Thank you!