3232#include < ur_client_library/control/trajectory_point_interface.h>
3333#include < ur_client_library/comm/tcp_socket.h>
3434#include < ur_client_library/control/motion_primitives.h>
35+ #include " ur_client_library/exceptions.h"
3536
3637using namespace urcl ;
3738
@@ -179,6 +180,58 @@ class TrajectoryPointInterfaceTest : public ::testing::Test
179180 readMessage (spl.pos , spl.vel , spl.acc , spl.goal_time , spl.blend_radius_or_spline_type , spl.motion_type );
180181 return spl;
181182 }
183+
184+ std::shared_ptr<control::MotionPrimitive> getMotionPrimitive ()
185+ {
186+ TrajData spl = getData ();
187+ if (spl.motion_type == static_cast <int32_t >(control::MotionType::MOVEJ))
188+ {
189+ return std::make_shared<control::MoveJPrimitive>(
190+ vector6d_t {
191+ (double )spl.pos [0 ] / control::TrajectoryPointInterface::MULT_JOINTSTATE,
192+ (double )spl.pos [1 ] / control::TrajectoryPointInterface::MULT_JOINTSTATE,
193+ (double )spl.pos [2 ] / control::TrajectoryPointInterface::MULT_JOINTSTATE,
194+ (double )spl.pos [3 ] / control::TrajectoryPointInterface::MULT_JOINTSTATE,
195+ (double )spl.pos [4 ] / control::TrajectoryPointInterface::MULT_JOINTSTATE,
196+ (double )spl.pos [5 ] / control::TrajectoryPointInterface::MULT_JOINTSTATE,
197+ },
198+ (double )spl.blend_radius_or_spline_type / control::TrajectoryPointInterface::MULT_TIME,
199+ std::chrono::milliseconds (spl.goal_time ),
200+ (double )spl.acc [0 ] / control::TrajectoryPointInterface::MULT_JOINTSTATE,
201+ (double )spl.vel [0 ] / control::TrajectoryPointInterface::MULT_JOINTSTATE);
202+ }
203+ else if (spl.motion_type == static_cast <int32_t >(control::MotionType::MOVEL))
204+ {
205+ return std::make_shared<control::MoveLPrimitive>(
206+ urcl::Pose{ ((double )spl.pos [0 ]) / control::TrajectoryPointInterface::MULT_JOINTSTATE,
207+ ((double )spl.pos [1 ]) / control::TrajectoryPointInterface::MULT_JOINTSTATE,
208+ ((double )spl.pos [2 ]) / control::TrajectoryPointInterface::MULT_JOINTSTATE,
209+ ((double )spl.pos [3 ]) / control::TrajectoryPointInterface::MULT_JOINTSTATE,
210+ ((double )spl.pos [4 ]) / control::TrajectoryPointInterface::MULT_JOINTSTATE,
211+ ((double )spl.pos [5 ]) / control::TrajectoryPointInterface::MULT_JOINTSTATE },
212+ (double )spl.blend_radius_or_spline_type / control::TrajectoryPointInterface::MULT_TIME,
213+ std::chrono::milliseconds (spl.goal_time ),
214+ (double )spl.acc [0 ] / control::TrajectoryPointInterface::MULT_JOINTSTATE,
215+ (double )spl.vel [0 ] / control::TrajectoryPointInterface::MULT_JOINTSTATE);
216+ }
217+ else if (spl.motion_type == static_cast <int32_t >(control::MotionType::MOVEP))
218+ {
219+ return std::make_shared<control::MovePPrimitive>(
220+ urcl::Pose{ ((double )spl.pos [0 ]) / control::TrajectoryPointInterface::MULT_JOINTSTATE,
221+ ((double )spl.pos [1 ]) / control::TrajectoryPointInterface::MULT_JOINTSTATE,
222+ ((double )spl.pos [2 ]) / control::TrajectoryPointInterface::MULT_JOINTSTATE,
223+ ((double )spl.pos [3 ]) / control::TrajectoryPointInterface::MULT_JOINTSTATE,
224+ ((double )spl.pos [4 ]) / control::TrajectoryPointInterface::MULT_JOINTSTATE,
225+ ((double )spl.pos [5 ]) / control::TrajectoryPointInterface::MULT_JOINTSTATE },
226+ (double )spl.blend_radius_or_spline_type / control::TrajectoryPointInterface::MULT_TIME,
227+ (double )spl.acc [0 ] / control::TrajectoryPointInterface::MULT_JOINTSTATE,
228+ (double )spl.vel [0 ] / control::TrajectoryPointInterface::MULT_JOINTSTATE);
229+ }
230+ else
231+ {
232+ throw std::runtime_error (" Unknown motion type" );
233+ }
234+ }
182235 };
183236
184237 void SetUp ()
@@ -439,9 +492,73 @@ TEST_F(TrajectoryPointInterfaceTest, trajectory_result)
439492 EXPECT_TRUE (waitTrajectoryEnd (1000 , control::TrajectoryResult::TRAJECTORY_RESULT_SUCCESS));
440493}
441494
495+ TEST_F (TrajectoryPointInterfaceTest, send_movej)
496+ {
497+ urcl::vector6d_t send_positions = { 1.2 , 3.1 , 2.2 , -3.4 , -1.1 , -1.2 };
498+ double blend_radius = 0.5 ;
499+ double velocity = 0.6 ;
500+ double acceleration = 0.7 ;
501+ auto duration = std::chrono::milliseconds (434 );
502+ auto primitive =
503+ std::make_shared<control::MoveJPrimitive>(send_positions, blend_radius, duration, acceleration, velocity);
504+
505+ traj_point_interface_->writeMotionPrimitive (primitive);
506+ auto received_primitive = client_->getMotionPrimitive ();
507+ EXPECT_EQ (received_primitive->type , control::MotionType::MOVEJ);
508+ EXPECT_EQ (std::static_pointer_cast<control::MoveJPrimitive>(received_primitive)->target_joint_configuration ,
509+ send_positions);
510+ EXPECT_EQ (received_primitive->blend_radius , blend_radius);
511+ EXPECT_EQ (received_primitive->velocity , velocity);
512+ EXPECT_EQ (received_primitive->acceleration , acceleration);
513+ EXPECT_EQ (received_primitive->duration , duration);
514+ }
515+
516+ TEST_F (TrajectoryPointInterfaceTest, send_movel)
517+ {
518+ urcl::Pose send_positions = { 1.2 , 3.1 , 2.2 , -3.4 , -1.1 , -1.2 };
519+ double blend_radius = 0.5 ;
520+ double velocity = 0.6 ;
521+ double acceleration = 0.7 ;
522+ auto duration = std::chrono::milliseconds (434 );
523+ auto primitive =
524+ std::make_shared<control::MoveLPrimitive>(send_positions, blend_radius, duration, acceleration, velocity);
525+
526+ traj_point_interface_->writeMotionPrimitive (primitive);
527+ auto received_primitive = client_->getMotionPrimitive ();
528+ EXPECT_EQ (received_primitive->type , control::MotionType::MOVEL);
529+ EXPECT_EQ (std::static_pointer_cast<control::MoveLPrimitive>(received_primitive)->target_pose , send_positions);
530+ EXPECT_EQ (received_primitive->blend_radius , blend_radius);
531+ EXPECT_EQ (received_primitive->velocity , velocity);
532+ EXPECT_EQ (received_primitive->acceleration , acceleration);
533+ EXPECT_EQ (received_primitive->duration , duration);
534+ }
535+
536+ TEST_F (TrajectoryPointInterfaceTest, send_movep)
537+ {
538+ urcl::Pose send_positions = { 1.2 , 3.1 , 2.2 , -3.4 , -1.1 , -1.2 };
539+ double blend_radius = 0.5 ;
540+ double velocity = 0.6 ;
541+ double acceleration = 0.7 ;
542+ auto primitive = std::make_shared<control::MovePPrimitive>(send_positions, blend_radius, acceleration, velocity);
543+
544+ traj_point_interface_->writeMotionPrimitive (primitive);
545+ auto received_primitive = client_->getMotionPrimitive ();
546+ EXPECT_EQ (received_primitive->type , control::MotionType::MOVEP);
547+ EXPECT_EQ (std::static_pointer_cast<control::MovePPrimitive>(received_primitive)->target_pose , send_positions);
548+ EXPECT_EQ (received_primitive->blend_radius , blend_radius);
549+ EXPECT_EQ (received_primitive->velocity , velocity);
550+ EXPECT_EQ (received_primitive->acceleration , acceleration);
551+ }
552+
553+ TEST_F (TrajectoryPointInterfaceTest, unsupported_motion_type_throws)
554+ {
555+ auto primitive = std::make_shared<control::MotionPrimitive>();
556+ EXPECT_THROW (traj_point_interface_->writeMotionPrimitive (primitive), urcl::UnsupportedMotionType);
557+ }
558+
442559int main (int argc, char * argv[])
443560{
444561 ::testing::InitGoogleTest (&argc, argv);
445562
446563 return RUN_ALL_TESTS ();
447- }
564+ }
0 commit comments