@@ -43,7 +43,6 @@ const std::string DEFAULT_ROBOT_IP = "192.168.56.101";
4343const std::string SCRIPT_FILE = " resources/external_control.urscript" ;
4444const std::string OUTPUT_RECIPE = " examples/resources/rtde_output_recipe.txt" ;
4545const std::string INPUT_RECIPE = " examples/resources/rtde_input_recipe.txt" ;
46- const std::string CALIBRATION_CHECKSUM = " calib_12788084448423163542" ;
4746
4847std::unique_ptr<UrDriver> g_my_driver;
4948std::unique_ptr<DashboardClient> g_my_dashboard;
@@ -109,13 +108,7 @@ int main(int argc, char* argv[])
109108 std::unique_ptr<ToolCommSetup> tool_comm_setup;
110109 const bool headless = true ;
111110 g_my_driver.reset (new UrDriver (robot_ip, SCRIPT_FILE, OUTPUT_RECIPE, INPUT_RECIPE, &handleRobotProgramState, headless,
112- std::move (tool_comm_setup), CALIBRATION_CHECKSUM));
113-
114- // Once RTDE communication is started, we have to make sure to read from the interface buffer, as
115- // otherwise we will get pipeline overflows. Therefor, do this directly before starting your main
116- // loop.
117-
118- g_my_driver->startRTDECommunication ();
111+ std::move (tool_comm_setup)));
119112
120113 // Increment depends on robot version
121114 double increment_constant = 0.0005 ;
@@ -130,62 +123,65 @@ int main(int argc, char* argv[])
130123 bool passed_positive_part = false ;
131124 URCL_LOG_INFO (" Start moving the robot" );
132125 urcl::vector6d_t joint_target = { 0 , 0 , 0 , 0 , 0 , 0 };
126+
127+ // Once RTDE communication is started, we have to make sure to read from the interface buffer, as
128+ // otherwise we will get pipeline overflows. Therefor, do this directly before starting your main
129+ // loop.
130+ g_my_driver->startRTDECommunication ();
133131 while (!(passed_positive_part && passed_negative_part))
134132 {
135133 // Read latest RTDE package. This will block for a hard-coded timeout (see UrDriver), so the
136134 // robot will effectively be in charge of setting the frequency of this loop.
137135 // In a real-world application this thread should be scheduled with real-time priority in order
138136 // to ensure that this is called in time.
139137 std::unique_ptr<rtde_interface::DataPackage> data_pkg = g_my_driver->getDataPackage ();
140- if (data_pkg)
138+ if (! data_pkg)
141139 {
142- // Read current joint positions from robot data
143- if (!data_pkg->getData (" actual_q" , g_joint_positions))
144- {
145- // This throwing should never happen unless misconfigured
146- std::string error_msg = " Did not find 'actual_q' in data sent from robot. This should not happen!" ;
147- throw std::runtime_error (error_msg);
148- }
140+ URCL_LOG_WARN (" Could not get fresh data package from robot" );
141+ return 1 ;
142+ }
143+ // Read current joint positions from robot data
144+ if (!data_pkg->getData (" actual_q" , g_joint_positions))
145+ {
146+ // This throwing should never happen unless misconfigured
147+ std::string error_msg = " Did not find 'actual_q' in data sent from robot. This should not happen!" ;
148+ throw std::runtime_error (error_msg);
149+ }
149150
150- if (first_pass)
151- {
152- joint_target = g_joint_positions;
153- first_pass = false ;
154- }
151+ if (first_pass)
152+ {
153+ joint_target = g_joint_positions;
154+ first_pass = false ;
155+ }
155156
156- // Open loop control. The target is incremented with a constant each control loop
157- if (passed_positive_part == false )
158- {
159- increment = increment_constant;
160- if (g_joint_positions[5 ] >= 2 )
161- {
162- passed_positive_part = true ;
163- }
164- }
165- else if (passed_negative_part == false )
157+ // Open loop control. The target is incremented with a constant each control loop
158+ if (passed_positive_part == false )
159+ {
160+ increment = increment_constant;
161+ if (g_joint_positions[5 ] >= 2 )
166162 {
167- increment = -increment_constant;
168- if (g_joint_positions[5 ] <= 0 )
169- {
170- passed_negative_part = true ;
171- }
163+ passed_positive_part = true ;
172164 }
173- joint_target[5 ] += increment;
174- // Setting the RobotReceiveTimeout time is for example purposes only. This will make the example running more
175- // reliable on non-realtime systems. Use with caution in productive applications.
176- bool ret = g_my_driver->writeJointCommand (joint_target, comm::ControlMode::MODE_SERVOJ,
177- RobotReceiveTimeout::millisec (100 ));
178- if (!ret)
165+ }
166+ else if (passed_negative_part == false )
167+ {
168+ increment = -increment_constant;
169+ if (g_joint_positions[5 ] <= 0 )
179170 {
180- URCL_LOG_ERROR (" Could not send joint command. Is the robot in remote control?" );
181- return 1 ;
171+ passed_negative_part = true ;
182172 }
183- URCL_LOG_DEBUG (" data_pkg:\n %s" , data_pkg->toString ().c_str ());
184173 }
185- else
174+ joint_target[5 ] += increment;
175+ // Setting the RobotReceiveTimeout time is for example purposes only. This will make the example running more
176+ // reliable on non-realtime systems. Use with caution in productive applications.
177+ bool ret = g_my_driver->writeJointCommand (joint_target, comm::ControlMode::MODE_SERVOJ,
178+ RobotReceiveTimeout::millisec (100 ));
179+ if (!ret)
186180 {
187- URCL_LOG_WARN (" Could not get fresh data package from robot" );
181+ URCL_LOG_ERROR (" Could not send joint command. Is the robot in remote control?" );
182+ return 1 ;
188183 }
184+ URCL_LOG_DEBUG (" data_pkg:\n %s" , data_pkg->toString ().c_str ());
189185 }
190186 g_my_driver->stopControl ();
191187 URCL_LOG_INFO (" Movement done" );
0 commit comments