Skip to content

Commit 7a75157

Browse files
committed
Add CI step for running the examples
The default behavior is to find a run all the examples For this it was needed to change the examples to not run forever
1 parent db5a2d0 commit 7a75157

File tree

5 files changed

+126
-15
lines changed

5 files changed

+126
-15
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ jobs:
3939
run: cmake --build build --config Debug
4040
- name: test
4141
run: cd build && ctest --output-on-failure
42+
- name: run examples
43+
run: run-parts -v --exit-on-error -a "192.168.56.101" -a "1" ./build/examples
4244
- name: install gcovr
4345
run: sudo apt-get install -y gcovr
4446
- name: gcovr
@@ -69,4 +71,3 @@ jobs:
6971
steps:
7072
- uses: actions/checkout@v1
7173
- uses: ./.github/actions/rosdoc_lite_action
72-

examples/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,8 @@ add_executable(rtde_client_example
2929
rtde_client.cpp)
3030
target_compile_options(rtde_client_example PUBLIC ${CXX17_FLAG})
3131
target_link_libraries(rtde_client_example ur_client_library::urcl)
32+
33+
add_executable(dashboard_example
34+
dashboard_example.cpp)
35+
target_compile_options(dashboard_example PUBLIC ${CXX17_FLAG})
36+
target_link_libraries(dashboard_example ur_client_library::urcl)

examples/full_driver.cpp

Lines changed: 72 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
*/
2929
//----------------------------------------------------------------------
3030

31+
#include <ur_client_library/ur/dashboard_client.h>
3132
#include <ur_client_library/ur/ur_driver.h>
3233
#include <ur_client_library/types.h>
3334

@@ -38,13 +39,14 @@ using namespace urcl;
3839

3940
// In a real-world example it would be better to get those values from command line parameters / a
4041
// better configuration system such as Boost.Program_options
41-
const std::string ROBOT_IP = "192.168.56.101";
42+
const std::string DEFAULT_ROBOT_IP = "127.0.0.1";
4243
const std::string SCRIPT_FILE = "resources/external_control.urscript";
4344
const std::string OUTPUT_RECIPE = "examples/resources/rtde_output_recipe.txt";
4445
const std::string INPUT_RECIPE = "examples/resources/rtde_input_recipe.txt";
4546
const std::string CALIBRATION_CHECKSUM = "calib_12788084448423163542";
4647

4748
std::unique_ptr<UrDriver> g_my_driver;
49+
std::unique_ptr<DashboardClient> my_dashboard;
4850
vector6d_t g_joint_positions;
4951

5052
// We need a callback function to register. See UrDriver's parameters for details.
@@ -56,15 +58,71 @@ void handleRobotProgramState(bool program_running)
5658

5759
int main(int argc, char* argv[])
5860
{
61+
urcl::setLogLevel(urcl::LogLevel::INFO);
62+
63+
// Parse the ip arguments if given
64+
std::string robot_ip = DEFAULT_ROBOT_IP;
65+
if (argc > 1)
66+
{
67+
robot_ip = std::string(argv[1]);
68+
}
69+
70+
// Making the robot ready for the program by:
71+
// Connect the the robot Dashboard
72+
my_dashboard.reset(new DashboardClient(robot_ip));
73+
if (!my_dashboard->connect())
74+
{
75+
URCL_LOG_ERROR("Could not connect to dashboard");
76+
return 1;
77+
}
78+
79+
// Stop program, if there is one running
80+
if (!my_dashboard->commandStop())
81+
{
82+
URCL_LOG_ERROR("Could not send stop program command");
83+
return 1;
84+
}
85+
86+
// Power it on
87+
if (!my_dashboard->commandPowerOff())
88+
{
89+
URCL_LOG_ERROR("Could not send Power off command");
90+
return 1;
91+
}
92+
93+
// Power it on
94+
if (!my_dashboard->commandPowerOn())
95+
{
96+
URCL_LOG_ERROR("Could not send Power on command");
97+
return 1;
98+
}
99+
100+
// Release the brakes
101+
if (!my_dashboard->commandBreakeRelease())
102+
{
103+
URCL_LOG_ERROR("Could not send BreakeRelease command");
104+
return 1;
105+
}
106+
107+
// Now the robot is ready to receive a program
108+
59109
std::unique_ptr<ToolCommSetup> tool_comm_setup;
60-
g_my_driver.reset(new UrDriver(ROBOT_IP, SCRIPT_FILE, OUTPUT_RECIPE, INPUT_RECIPE, &handleRobotProgramState, false,
110+
const bool HEADLESS = true;
111+
g_my_driver.reset(new UrDriver(robot_ip, SCRIPT_FILE, OUTPUT_RECIPE, INPUT_RECIPE, &handleRobotProgramState, HEADLESS,
61112
std::move(tool_comm_setup), CALIBRATION_CHECKSUM));
113+
62114
// Once RTDE communication is started, we have to make sure to read from the interface buffer, as
63115
// otherwise we will get pipeline overflows. Therefor, do this directly before starting your main
64116
// loop.
117+
65118
g_my_driver->startRTDECommunication();
119+
66120
double increment = 0.01;
67-
while (true)
121+
122+
bool passed_slow_part = false;
123+
bool passed_fast_part = false;
124+
URCL_LOG_INFO("Start moving the robot");
125+
while (!(passed_slow_part && passed_fast_part))
68126
{
69127
// Read latest RTDE package. This will block for a hard-coded timeout (see UrDriver), so the
70128
// robot will effectively be in charge of setting the frequency of this loop.
@@ -84,20 +142,28 @@ int main(int argc, char* argv[])
84142
// Simple motion command of last joint
85143
if (g_joint_positions[5] > 3)
86144
{
145+
passed_fast_part = increment > 0.01 || passed_fast_part;
87146
increment = -3; // this large jump will activate speed scaling
88147
}
89148
else if (g_joint_positions[5] < -3)
90149
{
150+
passed_slow_part = increment < 0.01 || passed_slow_part;
91151
increment = 0.02;
92152
}
93153
g_joint_positions[5] += increment;
94-
g_my_driver->writeJointCommand(g_joint_positions, comm::ControlMode::MODE_SERVOJ);
95-
std::cout << data_pkg->toString() << std::endl;
154+
bool ret = g_my_driver->writeJointCommand(g_joint_positions, comm::ControlMode::MODE_SERVOJ);
155+
if (!ret)
156+
{
157+
URCL_LOG_ERROR("Could not send joint command. Is the robot in remote control?");
158+
return 1;
159+
}
160+
URCL_LOG_DEBUG("data_pkg:\n%s", data_pkg->toString());
96161
}
97162
else
98163
{
99-
std::cout << "Could not get fresh data package from robot" << std::endl;
164+
URCL_LOG_WARN("Could not get fresh data package from robot");
100165
}
101166
}
167+
URCL_LOG_INFO("Movement done");
102168
return 0;
103169
}

examples/primary_pipeline.cpp

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,29 @@ using namespace urcl;
3434

3535
// In a real-world example it would be better to get those values from command line parameters / a better configuration
3636
// system such as Boost.Program_options
37-
const std::string ROBOT_IP = "192.168.56.101";
37+
const std::string DEFAULT_ROBOT_IP = "127.0.0.1";
3838

3939
int main(int argc, char* argv[])
4040
{
41+
// Set the loglevel to info get print out the DH parameters
42+
urcl::setLogLevel(urcl::LogLevel::INFO);
43+
44+
// Parse the ip arguments if given
45+
std::string robot_ip = DEFAULT_ROBOT_IP;
46+
if (argc > 1)
47+
{
48+
robot_ip = std::string(argv[1]);
49+
}
50+
51+
// Parse how may seconds to run
52+
int second_to_run = -1;
53+
if (argc > 2)
54+
{
55+
second_to_run = std::stoi(argv[2]);
56+
}
57+
4158
// First of all, we need a stream that connects to the robot
42-
comm::URStream<primary_interface::PrimaryPackage> primary_stream(ROBOT_IP, urcl::primary_interface::UR_PRIMARY_PORT);
59+
comm::URStream<primary_interface::PrimaryPackage> primary_stream(robot_ip, urcl::primary_interface::UR_PRIMARY_PORT);
4360

4461
// This will parse the primary packages
4562
primary_interface::PrimaryParser parser;
@@ -62,9 +79,9 @@ int main(int argc, char* argv[])
6279

6380
// Package contents will be printed while not being interrupted
6481
// Note: Packages for which the parsing isn't implemented, will only get their raw bytes printed.
65-
while (true)
82+
do
6683
{
67-
std::this_thread::sleep_for(std::chrono::seconds(1));
68-
}
84+
std::this_thread::sleep_for(std::chrono::seconds(second_to_run));
85+
} while (second_to_run < 0);
6986
return 0;
7087
}

examples/rtde_client.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,21 +29,36 @@
2929

3030
#include <iostream>
3131
#include <memory>
32+
#include <ctime>
3233

3334
using namespace urcl;
3435

3536
// In a real-world example it would be better to get those values from command line parameters / a better configuration
3637
// system such as Boost.Program_options
37-
const std::string ROBOT_IP = "192.168.56.101";
38+
const std::string DEFAULT_ROBOT_IP = "127.0.0.1";
3839
const std::string OUTPUT_RECIPE = "examples/resources/rtde_output_recipe.txt";
3940
const std::string INPUT_RECIPE = "examples/resources/rtde_input_recipe.txt";
4041
const std::chrono::milliseconds READ_TIMEOUT{ 100 };
4142

4243
int main(int argc, char* argv[])
4344
{
45+
// Parse the ip arguments if given
46+
std::string robot_ip = DEFAULT_ROBOT_IP;
47+
if (argc > 1)
48+
{
49+
robot_ip = std::string(argv[1]);
50+
}
51+
52+
// Parse how may seconds to run
53+
int second_to_run = -1;
54+
if (argc > 2)
55+
{
56+
second_to_run = std::stoi(argv[2]);
57+
}
58+
4459
// TODO: Write good docstring for notifier
4560
comm::INotifier notifier;
46-
rtde_interface::RTDEClient my_client(ROBOT_IP, notifier, OUTPUT_RECIPE, INPUT_RECIPE);
61+
rtde_interface::RTDEClient my_client(robot_ip, notifier, OUTPUT_RECIPE, INPUT_RECIPE);
4762
my_client.init();
4863

4964
// We will use the speed_slider_fraction as an example how to write to RTDE
@@ -54,7 +69,9 @@ int main(int argc, char* argv[])
5469
// otherwise we will get pipeline overflows. Therefor, do this directly before starting your main
5570
// loop.
5671
my_client.start();
57-
while (true)
72+
73+
unsigned long startTime = clock();
74+
while (second_to_run < 0 || ((clock() - startTime) / CLOCKS_PER_SEC) < static_cast<unsigned int>(second_to_run))
5875
{
5976
// Read latest RTDE package. This will block for READ_TIMEOUT, so the
6077
// robot will effectively be in charge of setting the frequency of this loop unless RTDE
@@ -69,6 +86,7 @@ int main(int argc, char* argv[])
6986
else
7087
{
7188
std::cout << "Could not get fresh data package from robot" << std::endl;
89+
return 1;
7290
}
7391

7492
if (!my_client.getWriter().sendSpeedSlider(speed_slider_fraction))
@@ -78,6 +96,7 @@ int main(int argc, char* argv[])
7896
std::cout << "\033[1;31mSending RTDE data failed."
7997
<< "\033[0m\n"
8098
<< std::endl;
99+
return 1;
81100
}
82101

83102
// Change the speed slider so that it will move between 0 and 1 all the time. This is for
@@ -96,5 +115,8 @@ int main(int argc, char* argv[])
96115
speed_slider_fraction += speed_slider_increment;
97116
}
98117

118+
// Resetting the speedslider back to 100%
119+
my_client.getWriter().sendSpeedSlider(1);
120+
99121
return 0;
100122
}

0 commit comments

Comments
 (0)