3232// ----------------------------------------------------------------------
3333
3434#include " ur_client_library/ur/ur_driver.h"
35+ #include " ur_client_library/control/script_reader.h"
3536#include " ur_client_library/exceptions.h"
3637#include " ur_client_library/helpers.h"
3738#include " ur_client_library/primary/primary_parser.h"
4243
4344namespace urcl
4445{
45- static const std::string BEGIN_REPLACE (" {{ BEGIN_REPLACE}} " );
46- static const std::string JOINT_STATE_REPLACE (" {{ JOINT_STATE_REPLACE}} " );
47- static const std::string TIME_REPLACE (" {{ TIME_REPLACE}} " );
48- static const std::string SERVO_J_REPLACE (" {{ SERVO_J_REPLACE}} " );
49- static const std::string SERVER_IP_REPLACE (" {{ SERVER_IP_REPLACE}} " );
50- static const std::string SERVER_PORT_REPLACE (" {{ SERVER_PORT_REPLACE}} " );
51- static const std::string TRAJECTORY_PORT_REPLACE (" {{ TRAJECTORY_SERVER_PORT_REPLACE}} " );
52- static const std::string SCRIPT_COMMAND_PORT_REPLACE (" {{ SCRIPT_COMMAND_SERVER_PORT_REPLACE}} " );
53- static const std::string FORCE_MODE_SET_DAMPING_REPLACE (" {{ FORCE_MODE_SET_DAMPING_REPLACE}} " );
54- static const std::string FORCE_MODE_SET_GAIN_SCALING_REPLACE (" {{ FORCE_MODE_SET_GAIN_SCALING_REPLACE}} " );
46+ static const std::string BEGIN_REPLACE (" BEGIN_REPLACE" );
47+ static const std::string JOINT_STATE_REPLACE (" JOINT_STATE_REPLACE" );
48+ static const std::string TIME_REPLACE (" TIME_REPLACE" );
49+ static const std::string SERVO_J_REPLACE (" SERVO_J_REPLACE" );
50+ static const std::string SERVER_IP_REPLACE (" SERVER_IP_REPLACE" );
51+ static const std::string SERVER_PORT_REPLACE (" SERVER_PORT_REPLACE" );
52+ static const std::string TRAJECTORY_PORT_REPLACE (" TRAJECTORY_SERVER_PORT_REPLACE" );
53+ static const std::string SCRIPT_COMMAND_PORT_REPLACE (" SCRIPT_COMMAND_SERVER_PORT_REPLACE" );
54+ static const std::string FORCE_MODE_SET_DAMPING_REPLACE (" FORCE_MODE_SET_DAMPING_REPLACE" );
55+ static const std::string FORCE_MODE_SET_GAIN_SCALING_REPLACE (" FORCE_MODE_SET_GAIN_SCALING_REPLACE" );
5556
5657UrDriver::~UrDriver ()
5758{
@@ -87,52 +88,21 @@ void UrDriver::init(const UrDriverConfiguration& config)
8788 // Figure out the ip automatically if the user didn't provide it
8889 std::string local_ip = config.reverse_ip .empty () ? rtde_client_->getIP () : config.reverse_ip ;
8990
90- startPrimaryClientCommunication ();
91- waitFor ([this ]() { return primary_client_->getConfigurationData () != nullptr ; }, std::chrono::milliseconds (500 ));
92- control::ScriptReader::RobotInfo robot_info;
93- robot_info.robot_type = primary_client_->getRobotType ();
94- script_reader_.reset (new control::ScriptReader (robot_info));
91+ trajectory_interface_.reset (new control::TrajectoryPointInterface (config.trajectory_port ));
92+ script_command_interface_.reset (new control::ScriptCommandInterface (config.script_command_port ));
9593
96- std::string prog = readScriptFile (config.script_file );
97- while (prog.find (JOINT_STATE_REPLACE) != std::string::npos)
98- {
99- prog.replace (prog.find (JOINT_STATE_REPLACE), JOINT_STATE_REPLACE.length (),
100- std::to_string (control::ReverseInterface::MULT_JOINTSTATE));
101- }
102- while (prog.find (TIME_REPLACE) != std::string::npos)
103- {
104- prog.replace (prog.find (TIME_REPLACE), TIME_REPLACE.length (),
105- std::to_string (control::TrajectoryPointInterface::MULT_TIME));
106- }
94+ startPrimaryClientCommunication ();
10795
96+ control::ScriptReader::DataDict data;
97+ data[JOINT_STATE_REPLACE] = std::to_string (control::ReverseInterface::MULT_JOINTSTATE);
98+ data[TIME_REPLACE] = std::to_string (control::TrajectoryPointInterface::MULT_TIME);
10899 std::ostringstream out;
109100 out << " lookahead_time=" << servoj_lookahead_time_ << " , gain=" << servoj_gain_;
110- while (prog.find (SERVO_J_REPLACE) != std::string::npos)
111- {
112- prog.replace (prog.find (SERVO_J_REPLACE), SERVO_J_REPLACE.length (), out.str ());
113- }
114-
115- while (prog.find (SERVER_IP_REPLACE) != std::string::npos)
116- {
117- prog.replace (prog.find (SERVER_IP_REPLACE), SERVER_IP_REPLACE.length (), local_ip);
118- }
119-
120- while (prog.find (SERVER_PORT_REPLACE) != std::string::npos)
121- {
122- prog.replace (prog.find (SERVER_PORT_REPLACE), SERVER_PORT_REPLACE.length (), std::to_string (config.reverse_port ));
123- }
124-
125- while (prog.find (TRAJECTORY_PORT_REPLACE) != std::string::npos)
126- {
127- prog.replace (prog.find (TRAJECTORY_PORT_REPLACE), TRAJECTORY_PORT_REPLACE.length (),
128- std::to_string (config.trajectory_port ));
129- }
130-
131- while (prog.find (SCRIPT_COMMAND_PORT_REPLACE) != std::string::npos)
132- {
133- prog.replace (prog.find (SCRIPT_COMMAND_PORT_REPLACE), SCRIPT_COMMAND_PORT_REPLACE.length (),
134- std::to_string (config.script_command_port ));
135- }
101+ data[SERVO_J_REPLACE] = out.str ();
102+ data[SERVER_IP_REPLACE] = local_ip;
103+ data[SERVER_PORT_REPLACE] = std::to_string (config.reverse_port );
104+ data[TRAJECTORY_PORT_REPLACE] = std::to_string (config.trajectory_port );
105+ data[SCRIPT_COMMAND_PORT_REPLACE] = std::to_string (config.script_command_port );
136106
137107 robot_version_ = rtde_client_->getVersion ();
138108
@@ -153,10 +123,9 @@ void UrDriver::init(const UrDriverConfiguration& config)
153123 << config.tool_comm_setup ->getStopBits () << " , " << config.tool_comm_setup ->getRxIdleChars () << " , "
154124 << config.tool_comm_setup ->getTxIdleChars () << " )" ;
155125 }
156- prog.replace (prog.find (BEGIN_REPLACE), BEGIN_REPLACE.length (), begin_replace.str ());
157-
158- trajectory_interface_.reset (new control::TrajectoryPointInterface (config.trajectory_port ));
159- script_command_interface_.reset (new control::ScriptCommandInterface (config.script_command_port ));
126+ data[BEGIN_REPLACE] = begin_replace.str ();
127+ script_reader_.reset (new control::ScriptReader ());
128+ std::string prog = script_reader_->readScriptFile (config.script_file , data);
160129
161130 if (in_headless_mode_)
162131 {
0 commit comments