Go to the documentation of this file.
46 static const std::string
TIME_REPLACE(
"{{TIME_REPLACE}}");
95 std::ostringstream out;
126 std::stringstream begin_replace;
131 throw ToolCommNotAvailable(
"Tool communication setup requested, but this robot version does not support using "
132 "the tool communication interface. Please check your configuration.",
135 begin_replace <<
"set_tool_voltage("
136 <<
static_cast<std::underlying_type<ToolVoltage>::type
>(config.
tool_comm_setup->getToolVoltage())
138 begin_replace <<
"set_tool_communication(" <<
"True" <<
", " << config.
tool_comm_setup->getBaudRate() <<
", "
139 <<
static_cast<std::underlying_type<Parity>::type
>(config.
tool_comm_setup->getParity()) <<
", "
153 std::istringstream prog_stream(prog);
155 while (std::getline(prog_stream, line))
170 URCL_LOG_WARN(
"DEPRECATION NOTICE: Passing the calibration_checksum to the UrDriver's constructor has been "
171 "deprecated. Instead, use the checkCalibration(calibration_checksum) function separately. This "
172 "notice is for application developers using this library. If you are only using an application using "
173 "this library, you can ignore this message.");
180 URCL_LOG_ERROR(
"The calibration parameters of the connected robot don't match the ones from the given kinematics "
181 "config file. Please be aware that this can lead to critical inaccuracies of tcp positions. Use "
182 "the ur_calibration tool to extract the correct calibration from the robot and pass that into the "
184 "[https://github.com/UniversalRobots/Universal_Robots_ROS_Driver#extract-calibration-information] "
196 std::chrono::milliseconds timeout(get_packet_timeout_);
198 return rtde_client_->getDataPackage(timeout);
208 const bool cartesian,
const float goal_time,
const float blend_radius)
210 return trajectory_interface_->writeTrajectoryPoint(&positions, acceleration, velocity, goal_time, blend_radius,
215 const float blend_radius)
221 const vector6d_t& accelerations,
const float goal_time)
223 return trajectory_interface_->writeTrajectorySplinePoint(&positions, &velocities, &accelerations, goal_time);
227 const float goal_time)
229 return trajectory_interface_->writeTrajectorySplinePoint(&positions, &velocities,
nullptr, goal_time);
240 return reverse_interface_->writeTrajectoryControlMessage(trajectory_action, point_number, robot_receive_timeout);
251 return reverse_interface_->writeFreedriveControlMessage(freedrive_action, robot_receive_timeout);
258 std::stringstream ss;
259 ss <<
"Zeroing the Force-Torque sensor is only available for e-Series robots (Major version >= 5). This robot's "
273 URCL_LOG_WARN(
"Script command interface is not running. Falling back to sending plain script code. This will "
274 "only work, if the robot is in remote_control mode.");
275 std::stringstream cmd;
276 cmd <<
"sec tareSetup():" << std::endl <<
" zero_ftsensor()" << std::endl <<
"end";
290 URCL_LOG_WARN(
"Script command interface is not running. Falling back to sending plain script code. On e-Series "
291 "robots this will only work, if the robot is in remote_control mode.");
292 std::stringstream cmd;
293 cmd.imbue(std::locale::classic());
294 cmd <<
"sec setup():" << std::endl
295 <<
" set_payload(" << mass <<
", [" << cog[0] <<
", " << cog[1] <<
", " << cog[2] <<
"])" << std::endl
313 std::stringstream ss;
314 ss <<
"The tool voltage should be 0, 12 or 24. The tool voltage is " <<
toUnderlying(voltage);
325 URCL_LOG_WARN(
"Script command interface is not running. Falling back to sending plain script code. On e-Series "
326 "robots this will only work, if the robot is in remote_control mode.");
327 std::stringstream cmd;
328 cmd <<
"sec setup():" << std::endl <<
" set_tool_voltage(" <<
toUnderlying(voltage) <<
")" << std::endl <<
"end";
335 double damping_factor,
double gain_scaling_factor)
339 std::stringstream ss;
340 ss <<
"Force mode gain scaling factor cannot be set on a CB3 robot.";
355 std::stringstream ss;
356 ss <<
"The type should be 1, 2 or 3. The type is " << type;
360 for (
unsigned int i = 0; i < selection_vector.size(); ++i)
362 if (selection_vector[i] > 1)
364 std::stringstream ss;
365 ss <<
"The selection vector should only consist of 0's and 1's";
371 if (damping_factor > 1 || damping_factor < 0)
373 std::stringstream ss;
374 ss <<
"The force mode damping factor should be between 0 and 1, both inclusive.";
379 if (gain_scaling_factor > 2 || gain_scaling_factor < 0)
381 std::stringstream ss;
382 ss <<
"The force mode gain scaling factor should be between 0 and 2, both inclusive.";
390 damping_factor, gain_scaling_factor);
394 URCL_LOG_ERROR(
"Script command interface is not running. Unable to start Force mode.");
402 double damping_factor)
406 std::stringstream ss;
407 ss <<
"You should also specify a force mode gain scaling factor to activate force mode on an e-series robot.";
409 throw MissingArgument(ss.str(),
"startForceMode",
"gain_scaling_factor", 0.5);
421 std::stringstream ss;
422 ss <<
"The type should be 1, 2 or 3. The type is " << type;
426 for (
unsigned int i = 0; i < selection_vector.size(); ++i)
428 if (selection_vector[i] > 1)
430 std::stringstream ss;
431 ss <<
"The selection vector should only consist of 0's and 1's";
437 if (damping_factor > 1 || damping_factor < 0)
439 std::stringstream ss;
440 ss <<
"The force mode damping factor should be between 0 and 1, both inclusive.";
452 URCL_LOG_ERROR(
"Script command interface is not running. Unable to start Force mode.");
479 URCL_LOG_ERROR(
"Script command interface is not running. Unable to end Force mode.");
488 std::stringstream ss;
489 ss <<
"Tool contact is only available for e-Series robots (Major version >= 5). This robot's "
502 URCL_LOG_ERROR(
"Script command interface is not running. Unable to enable tool contact mode.");
511 std::stringstream ss;
512 ss <<
"Tool contact is only available for e-Series robots (Major version >= 5). This robot's "
525 URCL_LOG_ERROR(
"Script command interface is not running. Unable to end tool contact mode.");
553 std::stringstream ss;
554 ss <<
"URScript file '" << filename <<
"' doesn't exists.";
557 std::string content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
576 throw std::runtime_error(
"Sending script to robot requested while there is no primary client initialized. "
577 "This should not happen.");
590 URCL_LOG_ERROR(
"Tried to send robot program directly while not in headless mode");
602 URCL_LOG_WARN(
"DEPRECATION NOTICE: Setting the keepalive count has been deprecated. Instead use the "
603 "RobotReceiveTimeout, to set the timeout directly in the write commands. Please change your code to "
605 "read timeout in the write commands directly. This keepalive count will overwrite the timeout passed "
606 "to the write functions.");
608 #pragma GCC diagnostic push
609 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
611 #pragma GCC diagnostic pop
615 const std::vector<std::string>& input_recipe,
double target_frequency,
616 bool ignore_unavailable_outputs)
619 ignore_unavailable_outputs));
624 double target_frequency,
bool ignore_unavailable_outputs)
627 target_frequency, ignore_unavailable_outputs));
636 throw UrException(
"Initialization of RTDE client went wrong.");
642 auto rtde_frequency =
rtde_client_->getTargetFrequency();
643 auto step_time = std::chrono::milliseconds(
static_cast<int>(1000 / rtde_frequency));
std::vector< std::string > getRTDEOutputRecipe()
Getter for the RTDE output recipe used in the RTDE client.
ControlMode
Control modes as interpreted from the script runnning on the robot.
std::string output_recipe_file
Filename where the output recipe is stored in.
The RTDEWriter class offers an abstraction layer to send data to the robot via the RTDE interface....
std::unique_ptr< control::TrajectoryPointInterface > trajectory_interface_
std::function< void(bool)> handle_program_state
Function handle to a callback on program state changes.
void resetRTDEClient(const std::vector< std::string > &output_recipe, const std::vector< std::string > &input_recipe, double target_frequency=0.0, bool ignore_unavailable_outputs=false)
Reset the RTDE client. As during initialization the driver will start RTDE communication with the max...
static const std::string BEGIN_REPLACE("{{BEGIN_REPLACE}}")
std::string input_recipe_file
Filename where the input recipe is stored in.
void startRTDECommunication()
Starts the RTDE communication.
bool setPayload(const float mass, const vector3d_t &cog)
Set the payload mass and center of gravity. Note: It requires the external control script to be runni...
bool endForceMode()
Stop force mode and put the robot into normal operation mode.
The ScriptSender class starts a TCPServer for a robot to connect to and waits for a request to receiv...
std::string robot_ip
IP-address under which the robot is reachable.
double force_mode_gain_scale_factor_
Structure for configuration parameters of a UrDriver object.
uint32_t trajectory_port
Port used for sending trajectory points to the robot in case of trajectory forwarding.
ToolVoltage
Possible values for the tool voltage.
static const int32_t MULT_JOINTSTATE
bool stopControl()
Sends a stop command to the socket interface which will signal the program running on the robot to no...
static const std::string SERVER_PORT_REPLACE("{{SERVER_PORT_REPLACE}}")
rtde_interface::RTDEWriter & getRTDEWriter()
Getter for the RTDE writer used to write to the robot's RTDE interface.
The ReverseInterface class handles communication to the robot. It starts a server and waits for the r...
The ScriptCommandInterface class starts a TCPServer for a robot to connect to and this connection is ...
#define URCL_LOG_ERROR(...)
std::unique_ptr< ToolCommSetup > tool_comm_setup
Configuration for using the tool communication.
static const std::string TRAJECTORY_PORT_REPLACE("{{TRAJECTORY_SERVER_PORT_REPLACE}}")
uint32_t script_command_port
Port used for forwarding script commands to the robot.
bool writeJointCommand(const vector6d_t &values, const comm::ControlMode control_mode, const RobotReceiveTimeout &robot_receive_timeout=RobotReceiveTimeout::millisec(20))
Writes a joint command together with a keepalive signal onto the socket being sent to the robot.
std::array< double, 6 > vector6d_t
#define URCL_LOG_DEBUG(...)
static const std::string JOINT_STATE_REPLACE("{{JOINT_STATE_REPLACE}}")
void setupReverseInterface(const uint32_t reverse_port)
void setKeepaliveCount(const uint32_t count)
Set the Keepalive count. This will set the number of allowed timeout reads on the robot.
std::chrono::milliseconds rtde_initialization_timeout
Time in between initialization attempts of the RTDE interface.
static const std::string SERVO_J_REPLACE("{{SERVO_J_REPLACE}}")
size_t socket_connection_attempts_
bool startForceMode(const vector6d_t &task_frame, const vector6uint32_t &selection_vector, const vector6d_t &wrench, const unsigned int type, const vector6d_t &limits, double damping_factor)
Start the robot to be controlled in force mode.
TrajectoryControlMessage
Control messages for forwarding and aborting trajectories.
std::unique_ptr< rtde_interface::DataPackage > getDataPackage()
Access function to receive the latest data package sent from the robot through RTDE interface.
@ MODE_IDLE
Set when no controller is currently active controlling the robot.
std::array< uint32_t, 6 > vector6uint32_t
bool writeTrajectoryPoint(const vector6d_t &positions, const bool cartesian, const float goal_time=0.0, const float blend_radius=0.052)
Writes a trajectory point onto the dedicated socket.
bool sendScript(const std::string &program)
Sends a custom script program to the robot.
uint32_t reverse_port
Port that will be opened by the driver to allow direct communication between the driver and the robot...
int servoj_gain
Proportional gain for arm joints following target position, range [100,2000].
double servoj_lookahead_time_
Our base class for exceptions. Specialized exceptions should inherit from those.
std::unique_ptr< control::ReverseInterface > reverse_interface_
std::chrono::milliseconds socket_reconnection_timeout_
static const std::string SCRIPT_COMMAND_PORT_REPLACE("{{SCRIPT_COMMAND_SERVER_PORT_REPLACE}}")
std::string calibration_checksum
bool writeFreedriveControlMessage(const control::FreedriveControlMessage freedrive_action, const RobotReceiveTimeout &robot_receive_timeout=RobotReceiveTimeout::millisec(200))
Writes a control message in freedrive mode.
comm::INotifier notifier_
VersionInformation robot_version_
std::string reverse_ip
IP address that the reverse_port will get bound to.
double servoj_lookahead_time
Time [S], range [0.03,0.2] smoothens servoj calls with this lookahead time.
std::unique_ptr< rtde_interface::RTDEClient > rtde_client_
bool writeTrajectorySplinePoint(const vector6d_t &positions, const vector6d_t &velocities, const vector6d_t &accelerations, const float goal_time=0.0)
Writes a trajectory spline point for quintic spline interpolation onto the dedicated socket.
bool writeKeepalive(const RobotReceiveTimeout &robot_receive_timeout=RobotReceiveTimeout::millisec(1000))
Write a keepalive signal only.
bool checkCalibration(const std::string &checksum)
Checks if the kinematics information in the used model fits the actual robot.
size_t rtde_initialization_attempts
Number of attempts to initialize (given a successful socket connection) the RTDE interface.
uint32_t script_sender_port
The driver will offer an interface to receive the program's URScript on this port....
std::function< void(bool)> handle_program_state_
std::deque< urcl::primary_interface::ErrorCode > getErrorCodes()
Retrieves previously raised error codes from PrimaryClient. After calling this, recorded errors will ...
std::unique_ptr< control::ScriptSender > script_sender_
std::chrono::milliseconds socket_reconnection_timeout
Time in between connection attempts to sockets such as the primary or RTDE interface.
#define URCL_LOG_INFO(...)
std::chrono::milliseconds rtde_initialization_timeout_
std::unique_ptr< control::ScriptCommandInterface > script_command_interface_
static const std::string FORCE_MODE_SET_DAMPING_REPLACE("{{FORCE_MODE_SET_DAMPING_REPLACE}}")
@ MODE_STOPPED
When this is set, the program is expected to stop and exit.
static const std::string FORCE_MODE_SET_GAIN_SCALING_REPLACE("{{FORCE_MODE_SET_GAIN_SCALING_REPLACE}}")
size_t socket_reconnect_attempts
Number of attempts to reconnect to sockets such as the primary or RTDE interface.
std::string full_robot_program_
bool endToolContact()
This will stop the robot from looking for a tool contact, it will also enable sending move commands t...
bool zeroFTSensor()
Zero the force torque sensor (only availbe on e-Series). Note: It requires the external control scrip...
const VersionInformation & getVersion()
Returns version information about the currently connected robot.
void startPrimaryClientCommunication()
Starts the primary client.
bool headless_mode
Parameter to control if the driver should be started in headless mode.
constexpr std::underlying_type< E >::type toUnderlying(const E e) noexcept
Converts an enum type to its underlying type.
#define URCL_LOG_WARN(...)
The TrajectoryPointInterface class handles trajectory forwarding to the robot. Full trajectories are ...
std::array< double, 3 > vector3d_t
bool startToolContact()
This will make the robot look for tool contact in the tcp directions that the robot is currently movi...
static const std::string TIME_REPLACE("{{TIME_REPLACE}}")
static std::string readScriptFile(const std::string &filename)
bool writeMotionPrimitive(const std::shared_ptr< control::MotionPrimitive > motion_instruction)
Writes a motion command to the trajectory point interface.
void init(const UrDriverConfiguration &config)
RobotReceiveTimeout class containing a timeout configuration.
bool sendRobotProgram()
Sends the external control program to the robot.
static const std::string SERVER_IP_REPLACE("{{SERVER_IP_REPLACE}}")
FreedriveControlMessage
Control messages for starting and stopping freedrive mode.
std::shared_ptr< urcl::primary_interface::PrimaryClient > primary_client_
size_t rtde_initialization_attempts_
The RTDEClient class manages communication over the RTDE interface. It contains the RTDE handshake an...
std::string script_file
URScript file that should be sent to the robot.
static const int32_t MULT_TIME
bool setToolVoltage(const ToolVoltage voltage)
Set the tool voltage. Note: It requires the external control script to be running or the robot to be ...
bool writeTrajectoryControlMessage(const control::TrajectoryControlMessage trajectory_action, const int point_number=0, const RobotReceiveTimeout &robot_receive_timeout=RobotReceiveTimeout::millisec(200))
Writes a control message in trajectory forward mode.
double force_mode_damping_factor_
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