Dashboard client example

This example shows how to use the builtin Dashboard server to communicate with a robot.

Note

The Dashboard Server is only available on CB3 and e-Series robots. It is not available on PolyScope X.

The dashboard_example.cpp shows how to use this class:

Note

For the following example to work on an e-Series (PolyScope 5) robot, the robot has to be in remote control mode.

Listing 4 examples/dashboard_example.cpp
59  auto my_dashboard = std::make_unique<DashboardClient>(robot_ip);
60  if (!my_dashboard->connect())
61  {
62    URCL_LOG_ERROR("Could not connect to dashboard");
63    return 1;
64  }
65
66  if (!my_dashboard->commandPowerOff())
67  {
68    URCL_LOG_ERROR("Could not send power off");
69    return 1;
70  }
71
72  // Get the PolyScope version
73  std::string version;
74  my_dashboard->commandPolyscopeVersion(version);
75  URCL_LOG_INFO(version.c_str());
76
77  my_dashboard->commandCloseSafetyPopup();

At first, a DashboardClient object is created with the IP address of the robot. Then, the client is connected to the robot. After that, the client sends a command to the robot and receives the answer.

Some commands support getting the response from the robot. For example, the commandPolyScopeVersion() function:

Listing 5 examples/dashboard_example.cpp
72  // Get the PolyScope version
73  std::string version;
74  my_dashboard->commandPolyscopeVersion(version);
75  URCL_LOG_INFO(version.c_str());

The DashboardClient can easily be used to cycle through the robot’s states, for example for initialization:

Listing 6 examples/dashboard_example.cpp
79  // Power it on
80  if (!my_dashboard->commandPowerOn())
81  {
82    URCL_LOG_ERROR("Could not send Power on command");
83    return 1;
84  }
85
86  // Release the brakes
87  if (!my_dashboard->commandBrakeRelease())
88  {
89    URCL_LOG_ERROR("Could not send BrakeRelease command");
90    return 1;
91  }
92
93  // Load existing program

All commands are blocking and will wait for the necessary action being done. The dashboard server’s response will be compared with an expected response. For example, when calling commandPowerOn(timeout), it is checked that the dashboard server is answering "Powering on" and then it is queried until the robot reports "Robotmode: IDLE" or until the timeout is reached. The example contains more commands that follow the same scheme.

If you want to send a query / command to the dashboard server and only want to receive the response, you can use the sendAndReceive() function:

Listing 7 examples/dashboard_example.cpp
145  // Make a raw request and save the response
146  std::string program_state = my_dashboard->sendAndReceive("programState");
147  URCL_LOG_INFO("Program state: %s", program_state.c_str());

For checking the response against an expected regular expression use sendRequest():

Listing 8 examples/dashboard_example.cpp
149  // The response can be checked with a regular expression
150  bool success = my_dashboard->sendRequest("power off", "Powering off");
151  URCL_LOG_INFO("Power off command success: %d", success);