full_driver.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 2020 FZI Forschungszentrum Informatik
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 //----------------------------------------------------------------------
29 //----------------------------------------------------------------------
30 
33 
34 #include <iostream>
35 #include <memory>
36 
37 using namespace urcl;
38 
39 // In a real-world example it would be better to get those values from command line parameters / a
40 // better configuration system such as Boost.Program_options
41 const std::string ROBOT_IP = "192.168.56.101";
42 const std::string SCRIPT_FILE = "resources/external_control.urscript";
43 const std::string OUTPUT_RECIPE = "examples/resources/rtde_output_recipe.txt";
44 const std::string INPUT_RECIPE = "examples/resources/rtde_input_recipe.txt";
45 const std::string CALIBRATION_CHECKSUM = "calib_12788084448423163542";
46 
47 std::unique_ptr<UrDriver> g_my_driver;
49 
50 // We need a callback function to register. See UrDriver's parameters for details.
51 void handleRobotProgramState(bool program_running)
52 {
53  // Print the text in green so we see it better
54  std::cout << "\033[1;32mProgram running: " << std::boolalpha << program_running << "\033[0m\n" << std::endl;
55 }
56 
57 int main(int argc, char* argv[])
58 {
59  std::unique_ptr<ToolCommSetup> tool_comm_setup;
61  std::move(tool_comm_setup), CALIBRATION_CHECKSUM));
62  // Once RTDE communication is started, we have to make sure to read from the interface buffer, as
63  // otherwise we will get pipeline overflows. Therefor, do this directly before starting your main
64  // loop.
65  g_my_driver->startRTDECommunication();
66  double increment = 0.01;
67  while (true)
68  {
69  // Read latest RTDE package. This will block for a hard-coded timeout (see UrDriver), so the
70  // robot will effectively be in charge of setting the frequency of this loop.
71  // In a real-world application this thread should be scheduled with real-time priority in order
72  // to ensure that this is called in time.
73  std::unique_ptr<rtde_interface::DataPackage> data_pkg = g_my_driver->getDataPackage();
74  if (data_pkg)
75  {
76  // Read current joint positions from robot data
77  if (!data_pkg->getData("actual_q", g_joint_positions))
78  {
79  // This throwing should never happen unless misconfigured
80  std::string error_msg = "Did not find 'actual_q' in data sent from robot. This should not happen!";
81  throw std::runtime_error(error_msg);
82  }
83 
84  // Simple motion command of last joint
85  if (g_joint_positions[5] > 3)
86  {
87  increment = -3; // this large jump will activate speed scaling
88  }
89  else if (g_joint_positions[5] < -3)
90  {
91  increment = 0.02;
92  }
93  g_joint_positions[5] += increment;
95  std::cout << data_pkg->toString() << std::endl;
96  }
97  else
98  {
99  std::cout << "Could not get fresh data package from robot" << std::endl;
100  }
101  }
102  return 0;
103 }
This is the main class for interfacing the driver.
Definition: ur_driver.h:49
void handleRobotProgramState(bool program_running)
Definition: full_driver.cpp:51
const std::string INPUT_RECIPE
Definition: full_driver.cpp:44
const std::string OUTPUT_RECIPE
Definition: full_driver.cpp:43
const std::string CALIBRATION_CHECKSUM
Definition: full_driver.cpp:45
const std::string SCRIPT_FILE
Definition: full_driver.cpp:42
int main(int argc, char *argv[])
Definition: full_driver.cpp:57
Set when servoj control is active.
vector6d_t g_joint_positions
Definition: full_driver.cpp:48
const std::string ROBOT_IP
Definition: full_driver.cpp:41
std::unique_ptr< UrDriver > g_my_driver
Definition: full_driver.cpp:47
std::array< double, 6 > vector6d_t
Definition: types.h:30


ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Sun May 9 2021 02:16:26