Skip to content

Commit 7d0c16a

Browse files
author
Pablo David Aranda Rodriguez
committed
Improved logic to handle recipe input/output file/vector
1 parent c98ad77 commit 7d0c16a

File tree

4 files changed

+69
-20
lines changed

4 files changed

+69
-20
lines changed

include/ur_client_library/rtde/rtde_client.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,9 @@ class RTDEClient
222222
return output_recipe_;
223223
}
224224

225+
// Reads output or input recipe from a file
226+
static std::vector<std::string> readRecipe(const std::string& recipe_file);
227+
225228
private:
226229
comm::URStream<RTDEPackage> stream_;
227230
std::vector<std::string> output_recipe_;
@@ -247,9 +250,6 @@ class RTDEClient
247250
constexpr static const double CB3_MAX_FREQUENCY = 125.0;
248251
constexpr static const double URE_MAX_FREQUENCY = 500.0;
249252

250-
// Reads output or input recipe from a file
251-
std::vector<std::string> readRecipe(const std::string& recipe_file) const;
252-
253253
// Helper function to ensure that timestamp is present in the output recipe. The timestamp is needed to ensure that
254254
// the robot is booted.
255255
std::vector<std::string> ensureTimestampIsPresent(const std::vector<std::string>& output_recipe) const;

include/ur_client_library/ur/ur_driver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,7 @@ class UrDriver
989989
private:
990990
void init(const UrDriverConfiguration& config);
991991

992+
void handleRTDEReset(const UrDriverConfiguration& config);
992993
void initRTDE();
993994
void setupReverseInterface(const uint32_t reverse_port);
994995

src/rtde/rtde_client.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,7 +664,7 @@ bool RTDEClient::sendPause()
664664
throw UrException(ss.str());
665665
}
666666

667-
std::vector<std::string> RTDEClient::readRecipe(const std::string& recipe_file) const
667+
std::vector<std::string> RTDEClient::readRecipe(const std::string& recipe_file)
668668
{
669669
std::vector<std::string> recipe;
670670
std::ifstream file(recipe_file);

src/ur/ur_driver.cpp

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,16 @@
3232
//----------------------------------------------------------------------
3333

3434
#include "ur_client_library/ur/ur_driver.h"
35+
#include "ur_client_library/rtde/rtde_client.h"
3536
#include "ur_client_library/control/script_reader.h"
3637
#include "ur_client_library/exceptions.h"
3738
#include "ur_client_library/helpers.h"
3839
#include "ur_client_library/primary/primary_parser.h"
3940
#include "ur_client_library/helpers.h"
4041
#include <memory>
4142
#include <sstream>
43+
#include <stdexcept>
44+
#include <filesystem>
4245

4346
#include <ur_client_library/ur/calibration_checker.h>
4447

@@ -76,11 +79,7 @@ void UrDriver::init(const UrDriverConfiguration& config)
7679

7780
URCL_LOG_DEBUG("Initializing urdriver");
7881
URCL_LOG_DEBUG("Initializing RTDE client");
79-
if (config.output_recipe_file.empty() && config.input_recipe_file.empty())
80-
rtde_client_.reset(new rtde_interface::RTDEClient(robot_ip_, notifier_, config.output_recipe, config.input_recipe));
81-
else
82-
rtde_client_.reset(
83-
new rtde_interface::RTDEClient(robot_ip_, notifier_, config.output_recipe_file, config.input_recipe_file));
82+
handleRTDEReset(config);
8483

8584
primary_client_.reset(new urcl::primary_interface::PrimaryClient(robot_ip_, notifier_));
8685

@@ -129,7 +128,8 @@ void UrDriver::init(const UrDriverConfiguration& config)
129128
{
130129
if (robot_version_.major < 5)
131130
{
132-
throw ToolCommNotAvailable("Tool communication setup requested, but this robot version does not support using "
131+
throw ToolCommNotAvailable("Tool communication setup requested, but this robot version does not support "
132+
"using "
133133
"the tool communication interface. Please check your configuration.",
134134
VersionInformation::fromString("5.0.0"), robot_version_);
135135
}
@@ -171,19 +171,24 @@ void UrDriver::init(const UrDriverConfiguration& config)
171171
{
172172
URCL_LOG_WARN("DEPRECATION NOTICE: Passing the calibration_checksum to the UrDriver's constructor has been "
173173
"deprecated. Instead, use the checkCalibration(calibration_checksum) function separately. This "
174-
"notice is for application developers using this library. If you are only using an application using "
174+
"notice is for application developers using this library. If you are only using an application "
175+
"using "
175176
"this library, you can ignore this message.");
176177
if (checkCalibration(config.calibration_checksum))
177178
{
178179
URCL_LOG_INFO("Calibration checked successfully.");
179180
}
180181
else
181182
{
182-
URCL_LOG_ERROR("The calibration parameters of the connected robot don't match the ones from the given kinematics "
183-
"config file. Please be aware that this can lead to critical inaccuracies of tcp positions. Use "
184-
"the ur_calibration tool to extract the correct calibration from the robot and pass that into the "
183+
URCL_LOG_ERROR("The calibration parameters of the connected robot don't match the ones from the given "
184+
"kinematics "
185+
"config file. Please be aware that this can lead to critical inaccuracies of tcp positions. "
186+
"Use "
187+
"the ur_calibration tool to extract the correct calibration from the robot and pass that into "
188+
"the "
185189
"description. See "
186-
"[https://github.com/UniversalRobots/Universal_Robots_ROS_Driver#extract-calibration-information] "
190+
"[https://github.com/UniversalRobots/"
191+
"Universal_Robots_ROS_Driver#extract-calibration-information] "
187192
"for details.");
188193
}
189194
}
@@ -192,8 +197,8 @@ void UrDriver::init(const UrDriverConfiguration& config)
192197

193198
std::unique_ptr<rtde_interface::DataPackage> urcl::UrDriver::getDataPackage()
194199
{
195-
// This can take one of two values, 0ms or 100ms. The large timeout is for when the robot is commanding the control
196-
// loop's timing (read is blocking). The zero timeout is for when the robot is sharing a control loop with
200+
// This can take one of two values, 0ms or 100ms. The large timeout is for when the robot is commanding the
201+
// control loop's timing (read is blocking). The zero timeout is for when the robot is sharing a control loop with
197202
// something else (combined_robot_hw)
198203
std::chrono::milliseconds timeout(get_packet_timeout_);
199204

@@ -258,7 +263,8 @@ bool UrDriver::zeroFTSensor()
258263
if (getVersion().major < 5)
259264
{
260265
std::stringstream ss;
261-
ss << "Zeroing the Force-Torque sensor is only available for e-Series robots (Major version >= 5). This robot's "
266+
ss << "Zeroing the Force-Torque sensor is only available for e-Series robots (Major version >= 5). This "
267+
"robot's "
262268
"version is "
263269
<< getVersion();
264270
URCL_LOG_ERROR(ss.str().c_str());
@@ -629,9 +635,11 @@ std::vector<std::string> UrDriver::getRTDEOutputRecipe()
629635
void UrDriver::setKeepaliveCount(const uint32_t count)
630636
{
631637
URCL_LOG_WARN("DEPRECATION NOTICE: Setting the keepalive count has been deprecated. Instead use the "
632-
"RobotReceiveTimeout, to set the timeout directly in the write commands. Please change your code to "
638+
"RobotReceiveTimeout, to set the timeout directly in the write commands. Please change your code "
639+
"to "
633640
"set the "
634-
"read timeout in the write commands directly. This keepalive count will overwrite the timeout passed "
641+
"read timeout in the write commands directly. This keepalive count will overwrite the timeout "
642+
"passed "
635643
"to the write functions.");
636644
// TODO: Remove 2027-05
637645
#pragma GCC diagnostic push
@@ -687,4 +695,44 @@ std::deque<urcl::primary_interface::ErrorCode> UrDriver::getErrorCodes()
687695
{
688696
return primary_client_->getErrorCodes();
689697
}
698+
699+
void UrDriver::handleRTDEReset(const UrDriverConfiguration& config)
700+
{
701+
bool use_output_file = true;
702+
if (config.output_recipe_file.empty() && config.output_recipe.size() == 0)
703+
throw UrException("Neither output recipe file nor output recipe have been defined");
704+
else if (!config.output_recipe_file.empty() && config.output_recipe.size() != 0)
705+
URCL_LOG_WARN("Both output recipe file and output recipe vector are used. Defaulting to output recipe file");
706+
else if (config.output_recipe_file.empty())
707+
use_output_file = false;
708+
if (use_output_file && !std::filesystem::exists(config.output_recipe_file))
709+
throw UrException("Output recipe file does not exist: " + config.output_recipe_file);
710+
711+
bool use_input_file = true;
712+
if (config.input_recipe_file.empty() && config.input_recipe.size() == 0)
713+
throw UrException("Neither input recipe file nor input recipe have been defined");
714+
else if (!config.input_recipe_file.empty() && config.input_recipe.size() != 0)
715+
URCL_LOG_WARN("Both input recipe file and input recipe vector are used. Defaulting to input recipe file");
716+
else if (config.input_recipe_file.empty())
717+
use_input_file = false;
718+
719+
if (use_input_file && !std::filesystem::exists(config.input_recipe_file))
720+
throw UrException("Input recipe file does not exist: " + config.input_recipe_file);
721+
722+
if (use_input_file && use_output_file)
723+
rtde_client_.reset(
724+
new rtde_interface::RTDEClient(robot_ip_, notifier_, config.output_recipe_file, config.input_recipe_file));
725+
else
726+
{
727+
auto input_recipe = config.input_recipe;
728+
auto output_recipe = config.output_recipe;
729+
if (use_input_file)
730+
input_recipe = rtde_interface::RTDEClient::readRecipe(config.input_recipe_file);
731+
if (use_output_file)
732+
output_recipe = rtde_interface::RTDEClient::readRecipe(config.output_recipe_file);
733+
734+
rtde_client_.reset(new rtde_interface::RTDEClient(robot_ip_, notifier_, output_recipe, input_recipe));
735+
}
736+
}
737+
690738
} // namespace urcl

0 commit comments

Comments
 (0)