dashboard_example.cpp
Go to the documentation of this file.
1 // this is for emacs file handling -*- mode: c++; indent-tabs-mode: nil -*-
2 
3 // -- BEGIN LICENSE BLOCK ----------------------------------------------
4 // Copyright 2022 Universal Robots A/S
5 //
6 // Licensed under the Apache License, Version 2.0 (the "License");
7 // you may not use this file except in compliance with the License.
8 // You may obtain a copy of the License at
9 //
10 // http://www.apache.org/licenses/LICENSE-2.0
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
18 // -- END LICENSE BLOCK ------------------------------------------------
19 
20 #include <ur_client_library/log.h>
22 
23 #include <iostream>
24 #include <memory>
25 #include <thread>
26 
27 using namespace urcl;
28 
29 // In a real-world example it would be better to get those values from command line parameters / a
30 // better configuration system such as Boost.Program_options
31 const std::string DEFAULT_ROBOT_IP = "192.168.56.101";
32 
33 // We need a callback function to register. See UrDriver's parameters for details.
34 
35 int main(int argc, char* argv[])
36 {
38 
39  // Parse the ip arguments if given
40  std::string robot_ip = DEFAULT_ROBOT_IP;
41  if (argc > 1)
42  {
43  robot_ip = std::string(argv[1]);
44  }
45 
46  // Making the robot ready for the program by:
47  // Connect the the robot Dashboard
48  std::unique_ptr<DashboardClient> my_dashboard;
49  my_dashboard.reset(new DashboardClient(robot_ip));
50  if (!my_dashboard->connect())
51  {
52  URCL_LOG_ERROR("Could not connect to dashboard");
53  return 1;
54  }
55 
56  if (!my_dashboard->commandPowerOff())
57  {
58  URCL_LOG_ERROR("Could not send power off");
59  return 1;
60  }
61 
62  my_dashboard->commandCloseSafetyPopup();
63 
64  // Power it on
65  if (!my_dashboard->commandPowerOn())
66  {
67  URCL_LOG_ERROR("Could not send Power on command");
68  return 1;
69  }
70 
71  // Release the brakes
72  if (!my_dashboard->commandBrakeRelease())
73  {
74  URCL_LOG_ERROR("Could not send BrakeRelease command");
75  return 1;
76  }
77 
78  // Load existing program
79  const std::string program_file_name_to_be_loaded("wait_program.urp");
80  if (!my_dashboard->commandLoadProgram(program_file_name_to_be_loaded))
81  {
82  URCL_LOG_ERROR("Could not load %s program", program_file_name_to_be_loaded.c_str());
83  return 1;
84  }
85 
86  // Play loaded program
87  if (!my_dashboard->commandPlay())
88  {
89  URCL_LOG_ERROR("Could not play program");
90  return 1;
91  }
92 
93  // Pause running program
94  if (!my_dashboard->commandPause())
95  {
96  URCL_LOG_ERROR("Could not pause program");
97  return 1;
98  }
99 
100  // Play loaded program
101  if (!my_dashboard->commandPlay())
102  {
103  URCL_LOG_ERROR("Could not play program");
104  return 1;
105  }
106 
107  // Stop program
108  if (!my_dashboard->commandStop())
109  {
110  URCL_LOG_ERROR("Could not stop program");
111  return 1;
112  }
113 
114  // Power it off
115  if (!my_dashboard->commandPowerOff())
116  {
117  URCL_LOG_ERROR("Could not send Power off command");
118  return 1;
119  }
120 
121  // Flush the log
122  if (!my_dashboard->commandSaveLog())
123  {
124  URCL_LOG_ERROR("Could not send the save log command");
125  return 1;
126  }
127 
128  // Now the robot is ready to receive a program
129 
130  return 0;
131 }
#define URCL_LOG_ERROR(...)
Definition: log.h:26
void setLogLevel(LogLevel level)
Set log level this will disable messages with lower log level.
Definition: log.cpp:101
int main(int argc, char *argv[])
const std::string DEFAULT_ROBOT_IP
This class is a wrapper around the dashboard server.


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Tue Jul 4 2023 02:09:47