@@ -117,12 +117,20 @@ int main(int argc, char* argv[])
117117
118118 g_my_driver->startRTDECommunication ();
119119
120- double increment = 0.01 ;
120+ // Increment depends on robot version
121+ double increment_constant = 0.0005 ;
122+ if (g_my_driver->getVersion ().major < 5 )
123+ {
124+ increment_constant = 0.002 ;
125+ }
126+ double increment = increment_constant;
121127
122- bool passed_slow_part = false ;
123- bool passed_fast_part = false ;
128+ bool first_pass = true ;
129+ bool passed_negative_part = false ;
130+ bool passed_positive_part = false ;
124131 URCL_LOG_INFO (" Start moving the robot" );
125- while (!(passed_slow_part && passed_fast_part))
132+ urcl::vector6d_t joint_target = { 0 , 0 , 0 , 0 , 0 , 0 };
133+ while (!(passed_positive_part && passed_negative_part))
126134 {
127135 // Read latest RTDE package. This will block for a hard-coded timeout (see UrDriver), so the
128136 // robot will effectively be in charge of setting the frequency of this loop.
@@ -139,21 +147,33 @@ int main(int argc, char* argv[])
139147 throw std::runtime_error (error_msg);
140148 }
141149
142- // Simple motion command of last joint
143- if (g_joint_positions[5 ] > 3 )
150+ if (first_pass)
151+ {
152+ joint_target = g_joint_positions;
153+ first_pass = false ;
154+ }
155+
156+ // Open loop control. The target is incremented with a constant each control loop
157+ if (passed_positive_part == false )
144158 {
145- passed_fast_part = increment > 0.01 || passed_fast_part;
146- increment = -3 ; // this large jump will activate speed scaling
159+ increment = increment_constant;
160+ if (g_joint_positions[5 ] >= 2 )
161+ {
162+ passed_positive_part = true ;
163+ }
147164 }
148- else if (g_joint_positions[ 5 ] < - 3 )
165+ else if (passed_negative_part == false )
149166 {
150- passed_slow_part = increment < 0.01 || passed_slow_part;
151- increment = 0.02 ;
167+ increment = -increment_constant;
168+ if (g_joint_positions[5 ] <= 0 )
169+ {
170+ passed_negative_part = true ;
171+ }
152172 }
153- g_joint_positions [5 ] += increment;
173+ joint_target [5 ] += increment;
154174 // Setting the RobotReceiveTimeout time is for example purposes only. This will make the example running more
155175 // reliable on non-realtime systems. Use with caution in productive applications.
156- bool ret = g_my_driver->writeJointCommand (g_joint_positions , comm::ControlMode::MODE_SERVOJ,
176+ bool ret = g_my_driver->writeJointCommand (joint_target , comm::ControlMode::MODE_SERVOJ,
157177 RobotReceiveTimeout::millisec (100 ));
158178 if (!ret)
159179 {
0 commit comments