Go to the documentation of this file.
39 namespace primary_interface
51 std::vector<std::shared_ptr<comm::IConsumer<PrimaryPackage>>> consumers;
68 pipeline_->init(max_num_tries, reconnection_time);
97 std::deque<ErrorCode> error_codes;
108 auto program_with_newline = program +
'\n';
110 size_t len = program_with_newline.size();
111 const uint8_t* data =
reinterpret_cast<const uint8_t*
>(program_with_newline.c_str());
114 const auto send_script_contents = [
this, program_with_newline, data, len,
115 &written](
const std::string&& description) ->
bool {
116 if (
stream_.write(data, len, written))
118 URCL_LOG_DEBUG(
"Sent program to robot:\n%s", program_with_newline.c_str());
121 const std::string error_message =
"Could not send program to robot: " + description;
126 if (send_script_contents(
"initial attempt"))
133 return send_script_contents(
"after reconnecting primary stream");
154 std::shared_ptr<primary_interface::KinematicsInfo> kin_info =
consumer_->getKinematicsInfo();
155 while (kin_info ==
nullptr)
157 std::this_thread::sleep_for(std::chrono::seconds(1));
158 kin_info =
consumer_->getKinematicsInfo();
162 return kin_info->toHash() == checksum;
169 throw UrException(
"Failed to send power on command to robot");
180 throw TimeoutException(
"Robot did not power on within the given timeout", timeout);
189 throw UrException(
"Failed to send power off command to robot");
199 throw TimeoutException(
"Robot did not power off within the given timeout", timeout);
208 throw UrException(
"Failed to send brake release command to robot");
218 throw TimeoutException(
"Robot did not release the brakes within the given timeout", timeout);
225 if (!
sendScript(
"set unlock protective stop"))
227 throw UrException(
"Failed to send unlock protective stop command to robot");
233 waitFor([
this]() {
return consumer_->getRobotModeData()->is_protective_stopped_ ==
false; }, timeout);
237 throw TimeoutException(
"Robot did not unlock the protective stop within the given timeout", timeout);
244 std::shared_ptr<RobotModeData> robot_mode_data =
consumer_->getRobotModeData();
245 if (robot_mode_data ==
nullptr)
247 throw UrException(
"Stopping a program while robot state is unknown. This should not happen");
252 throw UrException(
"Failed to send the command `stop program` to robot");
260 return !
consumer_->getRobotModeData()->is_program_running_ &&
261 !
consumer_->getRobotModeData()->is_program_paused_;
267 throw TimeoutException(
"Robot did not stop the program within the given timeout", timeout);
272 const std::chrono::milliseconds timeout)
276 waitFor([
this]() {
return consumer_->getVersionInformation() !=
nullptr; }, timeout);
279 return consumer_->getVersionInformation();
284 std::shared_ptr<ConfigurationData> configuration_data =
consumer_->getConfigurationData();
285 if (configuration_data ==
nullptr)
289 return static_cast<RobotType>(configuration_data->robot_type_);
void addPrimaryConsumer(std::shared_ptr< comm::IConsumer< PrimaryPackage >> primary_consumer)
Adds a primary consumer to the list of consumers.
comm::URStream< PrimaryPackage > stream_
std::unique_ptr< comm::MultiConsumer< PrimaryPackage > > multi_consumer_
bool checkCalibration(const std::string &checksum)
bool sendScript(const std::string &program)
Sends a custom script program to the robot.
Primary consumer implementation.
Consumer, that allows one product to be consumed by multiple arbitrary consumers.
std::unique_ptr< comm::Pipeline< PrimaryPackage > > pipeline_
std::deque< ErrorCode > error_code_queue_
void waitFor(std::function< bool()> condition, const std::chrono::milliseconds timeout, const std::chrono::milliseconds check_interval=std::chrono::milliseconds(50))
Wait for a condition to be true.
#define URCL_LOG_ERROR(...)
RobotType getRobotType()
Get the Robot type.
#define URCL_LOG_DEBUG(...)
void commandBrakeRelease(const bool validate=true, const std::chrono::milliseconds timeout=std::chrono::seconds(30))
Commands the robot to release the brakes.
A general producer for URPackages. Implements funcionality to produce packages by reading and parsing...
void commandStop(const bool validate=true, const std::chrono::milliseconds timeout=std::chrono::seconds(2))
Our base class for exceptions. Specialized exceptions should inherit from those.
void commandUnlockProtectiveStop(const bool validate=true, const std::chrono::milliseconds timeout=std::chrono::milliseconds(5000))
Commands the robot to unlock the protective stop.
Parent class for notifiers.
RobotMode getRobotMode()
Get the latest robot mode.
void errorMessageCallback(ErrorCode &code)
std::unique_ptr< comm::URProducer< PrimaryPackage > > prod_
The Pipeline manages the production and optionally consumption of packages. Cyclically the producer i...
std::shared_ptr< VersionInformation > getRobotVersion(bool wait_for_message=true, const std::chrono::milliseconds timeout=std::chrono::seconds(2))
Get the robot's software version as Major.Minor.Bugfix.
std::mutex error_code_queue_mutex_
comm::INotifier notifier_
A specialized exception representing that communication to the tool is not possible.
#define URCL_LOG_INFO(...)
static const int UR_PRIMARY_PORT
std::shared_ptr< PrimaryConsumer > consumer_
void removePrimaryConsumer(std::shared_ptr< comm::IConsumer< PrimaryPackage >> primary_consumer)
Remove a primary consumer from the list of consumers.
void commandPowerOn(const bool validate=true, const std::chrono::milliseconds timeout=std::chrono::seconds(30))
Commands the robot to power on.
void start(const size_t max_connection_attempts=0, const std::chrono::milliseconds reconnection_timeout=urcl::comm::TCPSocket::DEFAULT_RECONNECTION_TIME)
std::deque< ErrorCode > getErrorCodes()
Retrieves previously raised error codes from PrimaryClient. After calling this, recorded errors will ...
void commandPowerOff(const bool validate=true, const std::chrono::milliseconds timeout=std::chrono::seconds(30))
Commands the robot to power off.
bool reconnectStream()
Reconnects the primary stream used to send program to the robot.
ur_client_library
Author(s): Thomas Timm Andersen, Simon Rasmussen, Felix Exner, Lea Steffen, Tristan Schnell
autogenerated on Mon May 26 2025 02:35:58