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
61  auto my_dashboard = std::make_unique<DashboardClient>(robot_ip);
62  if (!my_dashboard->connect())
63  {
64    URCL_LOG_ERROR("Could not connect to dashboard");
65    return 1;
66  }
67
68  if (!my_dashboard->commandPowerOff())
69  {
70    URCL_LOG_ERROR("Could not send power off");
71    return 1;
72  }
73
74  // Get the PolyScope version
75  std::string version;
76  my_dashboard->commandPolyscopeVersion(version);
77  URCL_LOG_INFO(version.c_str());
78
79  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
74  // Get the PolyScope version
75  std::string version;
76  my_dashboard->commandPolyscopeVersion(version);
77  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
81  // Power it on
82  if (!my_dashboard->commandPowerOn())
83  {
84    URCL_LOG_ERROR("Could not send Power on command");
85    return 1;
86  }
87
88  // Release the brakes
89  if (!my_dashboard->commandBrakeRelease())
90  {
91    URCL_LOG_ERROR("Could not send BrakeRelease command");
92    return 1;
93  }
94
95  // 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
147  // Make a raw request and save the response
148  std::string program_state = my_dashboard->sendAndReceive("programState");
149  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
151  // The response can be checked with a regular expression
152  bool success = my_dashboard->sendRequest("power off", "Powering off");
153  URCL_LOG_INFO("Power off command success: %d", success);