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
75  auto my_dashboard = std::make_unique<DashboardClient>(robot_ip);
76  if (!my_dashboard->connect())
77  {
78    URCL_LOG_ERROR("Could not connect to dashboard");
79    return 1;
80  }
81
82  if (!my_dashboard->commandPowerOff())
83  {
84    URCL_LOG_ERROR("Could not send power off");
85    return 1;
86  }
87
88  // Get the PolyScope version
89  std::string version;
90  my_dashboard->commandPolyscopeVersion(version);
91  URCL_LOG_INFO(version.c_str());
92
93  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
88  // Get the PolyScope version
89  std::string version;
90  my_dashboard->commandPolyscopeVersion(version);
91  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
 95  // Power it on
 96  if (!my_dashboard->commandPowerOn())
 97  {
 98    URCL_LOG_ERROR("Could not send Power on command");
 99    return 1;
100  }
101
102  // Release the brakes
103  if (!my_dashboard->commandBrakeRelease())
104  {
105    URCL_LOG_ERROR("Could not send BrakeRelease command");
106    return 1;
107  }
108
109  // 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
161  // Make a raw request and save the response
162  std::string program_state = my_dashboard->sendAndReceive("programState");
163  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
165  // The response can be checked with a regular expression
166  bool success = my_dashboard->sendRequest("power off", "Powering off");
167  URCL_LOG_INFO("Power off command success: %d", success);