Connect to services exposed by assets
This guide documents how to connect from an Asset e.g. a Skill to a gRPC service exposed by various Assets, such as robot controllers, within the Intrinsic platform.
It requires that you have a working development environment.
Clients connect to services using ConnectionParams.
Resources are part of the Asset model used by Intrinsic. Robots, cameras and grippers are all examples of resources.
- Python
- C++
The ConnectionParams object takes three parameters.
- The
addressparameter is in the form ofhostname:port. This is typically the ingress endpoint. - The
instance_nameparameter is the name of your Asset (e.g. "robot"). - The
headerparameter is used for routing. Use'x-resource-instance-name'.
The intrinsic::ConnectionParams struct offers multiple static builders.
- [recommended]
ResourceInstance(std::string_view instance_name)uses the cluster internal ingress.instance_nameis the name of your Asset (e.g. "robot"). ResourceInstance(std::string_view instance_name, std::string_view address)allows defining a customingressendpoint. E.g.xfa.lan:17080when connecting via the local network.
Ingress service
The connection is typically routed via an ingress service on the cluster that your solution is deployed on.
By default Assets and skills are running inside the cluster and use the internal ingress.
It is however possible to use the external ingress when connecting via the local network, e.g. for debugging and testing.
Some robot specific connection examples:
- Cluster internal
- Local Network
Skills and Services typically get their connection parameters from the Equipment. Check the example skill for more details.
- Python
- C++
from intrinsic.icon.equipment import equipment_utils
from intrinsic.icon.python import icon_api
from intrinsic.skills.proto import equipment_pb2
ROBOT_EQUIPMENT_SLOT: str = "robot" # The key used for the equipment in the skill manifest.
...
# Get equipment
icon_equipment: equipment_pb2.EquipmentHandle = (
context.resource_handles[ROBOT_EQUIPMENT_SLOT]
)
icon_client = equipment_utils.init_icon_client(icon_equipment)
When not using equipment_utils, use the internal ingress address istio-ingressgateway.app-ingress.svc.cluster.local:80.
#include "intrinsic/icon/cc_client/client.h"
#include "intrinsic/icon/cc_client/client_utils.h"
#include "intrinsic/icon/cc_client/session.h"
#include "intrinsic/icon/equipment/channel_factory.h"
#include "intrinsic/icon/equipment/equipment_utils.h"
...
using ::intrinsic::icon::ConnectToIconEquipment;
using ::intrinsic::icon::DefaultChannelFactory;
using ::intrinsic::icon::IconEquipment;
...
static constexpr std::string_view kRobotSlot[] = "robot"; // The key used for the equipment in the skill manifest.
...
const EquipmentPack equipment_pack = context.equipment();
INTR_ASSIGN_OR_RETURN(const auto equipment, equipment_pack.GetHandle(kRobotSlot));
INTR_ASSIGN_OR_RETURN(IconEquipment icon_equipment,
ConnectToIconEquipment(equipment_pack, kRobotSlot, DefaultChannelFactory()));
IconClient icon_client(icon_equipment.channel);
Example of connecting via the local network.
- Python
- C++
from intrinsic.icon.python import icon_api
from intrinsic.util.grpc import connection
...
icon_client = icon_api.Client.connect_with_params(
connection.ConnectionParams(
'xfa.lan:17080', 'robot', 'x-resource-instance-name'
)
)
#include "intrinsic/icon/cc_client/client.h"
#include "intrinsic/util/grpc/connection_params.h"
...
INTR_ASSIGN_OR_RETURN(auto channel, Channel::Make(ConnectionParams::ResourceInstance(
'robot', 'xfa.lan:17080'));
Client icon_client(channel);