@@ -59,9 +59,7 @@ TrajectoryPointInterface::TrajectoryPointInterface(uint32_t port) : ReverseInter
5959{
6060}
6161
62- bool TrajectoryPointInterface::writeTrajectoryPoint (const vector6d_t * positions, const float acceleration,
63- const float velocity, const float goal_time,
64- const float blend_radius, const bool cartesian)
62+ bool TrajectoryPointInterface::writeMotionPrimitive (const std::shared_ptr<control::MotionPrimitive> primitive)
6563{
6664 if (client_fd_ == -1 )
6765 {
@@ -70,48 +68,62 @@ bool TrajectoryPointInterface::writeTrajectoryPoint(const vector6d_t* positions,
7068 uint8_t buffer[sizeof (int32_t ) * MESSAGE_LENGTH];
7169 uint8_t * b_pos = buffer;
7270
73- if (positions != nullptr )
71+ vector6d_t positions;
72+
73+ switch (primitive->type )
7474 {
75- for ( auto const & pos : *positions)
75+ case MotionType::MOVEJ:
7676 {
77- int32_t val = static_cast < int32_t >( round (pos * MULT_JOINTSTATE) );
78- val = htobe32 (val) ;
79- b_pos += append (b_pos, val) ;
77+ auto movej_primitive = std::static_pointer_cast<control::MoveJPrimitive>(primitive );
78+ positions = movej_primitive-> target_joint_configuration ;
79+ break ;
8080 }
81- for ( size_t i = 0 ; i < positions-> size (); ++i)
81+ case MotionType::MOVEL:
8282 {
83- int32_t val = static_cast <int32_t >(round (velocity * MULT_JOINTSTATE));
84- val = htobe32 (val);
85- b_pos += append (b_pos, val);
83+ auto movel_primitive = std::static_pointer_cast<control::MoveLPrimitive>(primitive);
84+ positions = { movel_primitive->target_pose .x , movel_primitive->target_pose .y , movel_primitive->target_pose .z ,
85+ movel_primitive->target_pose .rx , movel_primitive->target_pose .ry , movel_primitive->target_pose .rz };
86+ break ;
8687 }
87- for ( size_t i = 0 ; i < positions-> size (); ++i)
88+ case urcl::control::MotionType::MOVEP:
8889 {
89- int32_t val = static_cast <int32_t >(round (acceleration * MULT_JOINTSTATE));
90- val = htobe32 (val);
91- b_pos += append (b_pos, val);
90+ auto movep_primitive = std::static_pointer_cast<control::MovePPrimitive>(primitive);
91+ positions = { movep_primitive->target_pose .x , movep_primitive->target_pose .y , movep_primitive->target_pose .z ,
92+ movep_primitive->target_pose .rx , movep_primitive->target_pose .ry , movep_primitive->target_pose .rz };
93+ break ;
9294 }
95+ default :
96+ throw UnsupportedMotionType ();
9397 }
94- else
98+
99+ for (auto const & pos : positions)
95100 {
96- b_pos += 6 * sizeof (int32_t );
101+ int32_t val = static_cast <int32_t >(round (pos * MULT_JOINTSTATE));
102+ val = htobe32 (val);
103+ b_pos += append (b_pos, val);
104+ }
105+ for (size_t i = 0 ; i < positions.size (); ++i)
106+ {
107+ int32_t val = static_cast <int32_t >(round (primitive->velocity * MULT_JOINTSTATE));
108+ val = htobe32 (val);
109+ b_pos += append (b_pos, val);
110+ }
111+ for (size_t i = 0 ; i < positions.size (); ++i)
112+ {
113+ int32_t val = static_cast <int32_t >(round (primitive->acceleration * MULT_JOINTSTATE));
114+ val = htobe32 (val);
115+ b_pos += append (b_pos, val);
97116 }
98117
99- int32_t val = static_cast <int32_t >(round (goal_time * MULT_TIME));
118+ int32_t val = static_cast <int32_t >(round (primitive-> duration . count () * MULT_TIME));
100119 val = htobe32 (val);
101120 b_pos += append (b_pos, val);
102121
103- val = static_cast <int32_t >(round (blend_radius * MULT_TIME));
122+ val = static_cast <int32_t >(round (primitive-> blend_radius * MULT_TIME));
104123 val = htobe32 (val);
105124 b_pos += append (b_pos, val);
106125
107- if (cartesian)
108- {
109- val = static_cast <int32_t >(control::MotionType::MOVEL);
110- }
111- else
112- {
113- val = static_cast <int32_t >(control::MotionType::MOVEJ);
114- }
126+ val = static_cast <int32_t >(primitive->type );
115127
116128 val = htobe32 (val);
117129 b_pos += append (b_pos, val);
@@ -121,6 +133,28 @@ bool TrajectoryPointInterface::writeTrajectoryPoint(const vector6d_t* positions,
121133 return server_.write (client_fd_, buffer, sizeof (buffer), written);
122134}
123135
136+ bool TrajectoryPointInterface::writeTrajectoryPoint (const vector6d_t * positions, const float acceleration,
137+ const float velocity, const float goal_time,
138+ const float blend_radius, const bool cartesian)
139+ {
140+ std::shared_ptr<MotionPrimitive> primitive;
141+ if (cartesian)
142+ {
143+ primitive = std::make_shared<MoveLPrimitive>(
144+ urcl::Pose{ (*positions)[0 ], (*positions)[1 ], (*positions)[2 ], (*positions)[3 ], (*positions)[4 ],
145+ (*positions)[5 ] },
146+ blend_radius, std::chrono::milliseconds (static_cast <int >(goal_time * 1000 )), acceleration, velocity);
147+ }
148+ else
149+ {
150+ primitive = std::make_shared<MoveJPrimitive>(*positions, blend_radius,
151+ std::chrono::milliseconds (static_cast <int >(goal_time * 1000 )),
152+ acceleration, velocity);
153+ }
154+
155+ return writeMotionPrimitive (primitive);
156+ }
157+
124158bool TrajectoryPointInterface::writeTrajectoryPoint (const vector6d_t * positions, const float goal_time,
125159 const float blend_radius, const bool cartesian)
126160{
@@ -249,4 +283,4 @@ void TrajectoryPointInterface::messageCallback(const socket_t filedescriptor, ch
249283 }
250284}
251285} // namespace control
252- } // namespace urcl
286+ } // namespace urcl
0 commit comments