51 const std::string& output_recipe_file,
const std::string& input_recipe_file,
52 std::function<
void(
bool)> handle_program_state,
bool headless_mode,
53 std::unique_ptr<ToolCommSetup> tool_comm_setup,
const std::string& calibration_checksum,
54 const uint32_t reverse_port,
const uint32_t script_sender_port,
int servoj_gain,
55 double servoj_lookahead_time,
bool non_blocking_read)
57 , servoj_gain_(servoj_gain)
58 , servoj_lookahead_time_(servoj_lookahead_time)
59 , handle_program_state_(handle_program_state)
71 URCL_LOG_INFO(
"Checking if calibration data matches connected robot.");
79 throw UrException(
"Initialization of RTDE client went wrong.");
93 std::ostringstream out;
112 std::stringstream begin_replace;
113 if (tool_comm_setup !=
nullptr)
117 throw ToolCommNotAvailable(
"Tool communication setup requested, but this robot version does not support using " 118 "the tool communication interface. Please check your configuration.",
121 begin_replace <<
"set_tool_voltage(" 122 <<
static_cast<std::underlying_type<ToolVoltage>::type
>(tool_comm_setup->getToolVoltage()) <<
")\n";
123 begin_replace <<
"set_tool_communication(" 125 <<
", " << tool_comm_setup->getBaudRate() <<
", " 126 <<
static_cast<std::underlying_type<Parity>::type
>(tool_comm_setup->getParity()) <<
", " 127 << tool_comm_setup->getStopBits() <<
", " << tool_comm_setup->getRxIdleChars() <<
", " 128 << tool_comm_setup->getTxIdleChars() <<
")";
136 std::istringstream prog_stream(prog);
138 while (std::getline(prog_stream, line))
190 std::ifstream ifs(filename);
191 std::string content((std::istreambuf_iterator<char>(ifs)), (std::istreambuf_iterator<char>()));
200 throw std::runtime_error(
"checkCalibration() called without a primary interface connection being established.");
215 std::this_thread::sleep_for(std::chrono::seconds(1));
229 throw std::runtime_error(
"Sending script to robot requested while there is no primary interface established. This " 230 "should not happen.");
236 auto program_with_newline = program +
'\n';
238 size_t len = program_with_newline.size();
239 const uint8_t* data =
reinterpret_cast<const uint8_t*
>(program_with_newline.c_str());
244 URCL_LOG_DEBUG(
"Sent program to robot:\n%s", program_with_newline.c_str());
259 URCL_LOG_ERROR(
"Tried to send robot program directly while not in headless mode");
static const std::string SERVER_IP_REPLACE("{{SERVER_IP_REPLACE}}")
#define URCL_LOG_ERROR(...)
bool writeJointCommand(const vector6d_t &values, const comm::ControlMode control_mode)
Writes a joint command together with a keepalive signal onto the socket being sent to the robot...
void setupProducer() override
Triggers the stream to connect to the robot.
void run()
Starts the producer and, if existing, the consumer in new threads.
comm::INotifier notifier_
VersionInformation robot_version_
static const std::string JOINT_STATE_REPLACE("{{JOINT_STATE_REPLACE}}")
The stream is an abstraction of the TCPSocket that offers reading a full UR data package out of the s...
std::string readScriptFile(const std::string &filename)
std::vector< std::string > getRTDEOutputRecipe()
Getter for the RTDE output recipe used in the RTDE client.
UrDriver(const std::string &robot_ip, const std::string &script_file, const std::string &output_recipe_file, const std::string &input_recipe_file, std::function< void(bool)> handle_program_state, bool headless_mode, std::unique_ptr< ToolCommSetup > tool_comm_setup, const std::string &calibration_checksum="", const uint32_t reverse_port=50001, const uint32_t script_sender_port=50002, int servoj_gain=2000, double servoj_lookahead_time=0.03, bool non_blocking_read=false)
Constructs a new UrDriver object. Upon initialization this class will check the calibration checksum ...
bool sendRobotProgram()
Sends the external control program to the robot.
The primary specific parser. Interprets a given byte stream as serialized primary packages and parses...
static const int32_t MULT_JOINTSTATE
void startRTDECommunication()
Starts the RTDE communication.
Set when no controller is currently active controlling the robot.
The RTDEWriter class offers an abstraction layer to send data to the robot via the RTDE interface...
bool stopControl()
Sends a stop command to the socket interface which will signal the program running on the robot to no...
void checkCalibration(const std::string &checksum)
Checks if the kinematics information in the used model fits the actual robot.
std::unique_ptr< comm::ReverseInterface > reverse_interface_
rtde_interface::RTDEWriter & getRTDEWriter()
Getter for the RTDE writer used to write to the robot's RTDE interface.
static const std::string SERVO_J_REPLACE("{{SERVO_J_REPLACE}}")
Parent class for notifiers.
std::string full_robot_program_
#define URCL_LOG_DEBUG(...)
static const std::string SERVER_PORT_REPLACE("{{SERVER_PORT_REPLACE}}")
bool writeKeepalive()
Write a keepalive signal only.
bool sendScript(const std::string &program)
Sends a custom script program to the robot.
std::unique_ptr< comm::URStream< primary_interface::PrimaryPackage > > primary_stream_
bool isChecked()
Used to make sure the calibration check is not performed several times.
ControlMode
Control modes as interpreted from the script runnning on the robot.
When this is set, the program is expected to stop and exit.
std::unique_ptr< rtde_interface::DataPackage > getDataPackage()
Access function to receive the latest data package sent from the robot through RTDE interface...
std::unique_ptr< rtde_interface::RTDEClient > rtde_client_
The CalibrationChecker class consumes primary packages ignoring all but KinematicsInfo packages...
The RTDEClient class manages communication over the RTDE interface. It contains the RTDE handshake an...
static const int UR_SECONDARY_PORT
double servoj_lookahead_time_
static const std::string BEGIN_REPLACE("{{BEGIN_REPLACE}}")
The ScriptSender class starts a TCPServer for a robot to connect to and waits for a request to receiv...
The ReverseInterface class handles communication to the robot. It starts a server and waits for the r...
std::array< double, 6 > vector6d_t
The Pipepline manages the production and optionally consumption of packages. Cyclically the producer ...
#define URCL_LOG_INFO(...)
std::unique_ptr< comm::URStream< primary_interface::PrimaryPackage > > secondary_stream_
A general producer for URPackages. Implements funcionality to produce packages by reading and parsing...
std::unique_ptr< comm::ScriptSender > script_sender_
Our base class for exceptions. Specialized exceptions should inherit from those.
static const int UR_PRIMARY_PORT
void setKeepaliveCount(const uint32_t &count)
Set the Keepalive count. This will set the number of allowed timeout reads on the robot...