SMACC2
Loading...
Searching...
No Matches
cl_moveit2z::CbMoveEndEffectorTrajectory Class Reference

#include <cb_move_end_effector_trajectory.hpp>

Inheritance diagram for cl_moveit2z::CbMoveEndEffectorTrajectory:
Inheritance graph
Collaboration diagram for cl_moveit2z::CbMoveEndEffectorTrajectory:
Collaboration graph

Public Member Functions

 CbMoveEndEffectorTrajectory (std::optional< std::string > tipLink=std::nullopt)
 
 CbMoveEndEffectorTrajectory (const std::vector< geometry_msgs::msg::PoseStamped > &endEffectorTrajectory, std::optional< std::string > tipLink=std::nullopt)
 
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
virtual void onEntry () override
 
virtual void onExit () override
 
- Public Member Functions inherited from cl_moveit2z::CbMoveit2zClientBehaviorBase
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
virtual ~CbMoveit2zClientBehaviorBase ()
 
- Public Member Functions inherited from smacc2::SmaccAsyncClientBehavior
template<typename TOrthogonal , typename TSourceObject >
void onStateOrthogonalAllocation ()
 
 SmaccAsyncClientBehavior ()=default
 
 ~SmaccAsyncClientBehavior () override
 
 SmaccAsyncClientBehavior (const SmaccAsyncClientBehavior &)=delete
 
SmaccAsyncClientBehavior & operator= (const SmaccAsyncClientBehavior &)=delete
 
 SmaccAsyncClientBehavior (SmaccAsyncClientBehavior &&)=delete
 
SmaccAsyncClientBehavior & operator= (SmaccAsyncClientBehavior &&)=delete
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFinished (TCallback callback, T *object)
 
template<typename TCallback , typename T >
smacc2::SmaccSignalConnection onFailure (TCallback callback, T *object)
 
void requestForceFinish ()
 
void executeOnEntry () override
 
void executeOnExit () override
 
void waitOnEntryThread (bool requestFinish)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onSuccess (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFinished (TCallbackMethod callback, T *object)
 
template<typename TCallbackMethod , typename T >
smacc2::SmaccSignalConnection onFailure (TCallbackMethod callback, T *object)
 
- Public Member Functions inherited from smacc2::ISmaccClientBehavior
 ISmaccClientBehavior ()
 
virtual ~ISmaccClientBehavior ()
 
 ISmaccClientBehavior (const ISmaccClientBehavior &)=delete
 
ISmaccClientBehavior & operator= (const ISmaccClientBehavior &)=delete
 
 ISmaccClientBehavior (ISmaccClientBehavior &&)=delete
 
ISmaccClientBehavior & operator= (ISmaccClientBehavior &&)=delete
 
ISmaccStateMachine * getStateMachine ()
 
std::string getName () const
 
template<typename SmaccClientType >
void requiresClient (SmaccClientType *&storage)
 
template<typename SmaccComponentType >
void requiresComponent (SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 
template<typename SmaccComponentType >
void requiresComponent (const std::string &name, SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 

Public Attributes

std::optional< std::string > group_
 
std::optional< std::string > tipLink_
 
std::optional< bool > allowInitialTrajectoryStateJointDiscontinuity_
 

Protected Member Functions

ComputeJointTrajectoryErrorCode computeJointSpaceTrajectory (moveit_msgs::msg::RobotTrajectory &computedJointTrajectory)
 
void executeJointSpaceTrajectory (const moveit_msgs::msg::RobotTrajectory &computedJointTrajectory)
 
virtual void generateTrajectory ()
 
virtual void createMarkers ()
 
void getCurrentEndEffectorPose (std::string globalFrame, tf2::Stamped< tf2::Transform > &currentEndEffectorTransform)
 
- Protected Member Functions inherited from cl_moveit2z::CbMoveit2zClientBehaviorBase
void postMotionSuccess ()
 
void postMotionFailure ()
 
- Protected Member Functions inherited from smacc2::SmaccAsyncClientBehavior
void postSuccessEvent ()
 
void postFailureEvent ()
 
void dispose () override
 
bool isShutdownRequested ()
 onEntry is executed in a new thread. However the current state cannot be left until the onEntry thread finishes. This flag can be checked from the onEntry thread to force finishing the thread.
 
- Protected Member Functions inherited from smacc2::ISmaccClientBehavior
virtual void runtimeConfigure ()
 
template<typename EventType >
void postEvent (const EventType &ev)
 
template<typename EventType >
void postEvent ()
 
ISmaccState * getCurrentState ()
 
void postInitializationFailureEvent (const std::string &what)
 
virtual rclcpp::Node::SharedPtr getNode () const
 
virtual rclcpp::Logger getLogger () const
 
std::string getTraceStateName () const
 
std::string getTraceOrthogonalName () const
 

Protected Attributes

std::vector< geometry_msgs::msg::PoseStamped > endEffectorTrajectory_
 
CpTrajectoryVisualizer * cpTrajectoryVisualizer_ = nullptr
 
CpJointSpaceTrajectoryPlanner * cpJointSpaceTrajectoryPlanner_ = nullptr
 
CpTfListener * cpTfListener_ = nullptr
 
visualization_msgs::msg::MarkerArray beahiorMarkers_
 
- Protected Attributes inherited from cl_moveit2z::CbMoveit2zClientBehaviorBase
CpMoveGroupInterface * cpMoveGroup_ = nullptr
 
CpMotionPlanner * cpMotionPlanner_ = nullptr
 
CpTrajectoryExecutor * cpTrajectoryExecutor_ = nullptr
 
CpTrajectoryHistory * cpTrajectoryHistory_ = nullptr
 

Private Member Functions

void initializeROS ()
 

Private Attributes

rclcpp::Publisher< visualization_msgs::msg::MarkerArray >::SharedPtr markersPub_
 
rclcpp::Client< moveit_msgs::srv::GetPositionIK >::SharedPtr iksrv_
 
std::mutex m_mutex_
 
std::function< void(moveit_msgs::msg::RobotTrajectory &)> postJointDiscontinuityEvent
 
std::function< void(moveit_msgs::msg::RobotTrajectory &)> postIncorrectInitialStateEvent
 
std::function< void()> postMotionExecutionFailureEvents
 

Detailed Description

Definition at line 58 of file cb_move_end_effector_trajectory.hpp.

Constructor & Destructor Documentation

◆ CbMoveEndEffectorTrajectory() [1/2]

cl_moveit2z::CbMoveEndEffectorTrajectory::CbMoveEndEffectorTrajectory ( std::optional< std::string > tipLink = std::nullopt)
inline

Definition at line 67 of file cb_move_end_effector_trajectory.hpp.

67 : tipLink_(tipLink)
68 {
69 }

◆ CbMoveEndEffectorTrajectory() [2/2]

cl_moveit2z::CbMoveEndEffectorTrajectory::CbMoveEndEffectorTrajectory ( const std::vector< geometry_msgs::msg::PoseStamped > & endEffectorTrajectory,
std::optional< std::string > tipLink = std::nullopt )
inline

Definition at line 71 of file cb_move_end_effector_trajectory.hpp.

74 : tipLink_(tipLink), endEffectorTrajectory_(endEffectorTrajectory)
75 {
76 }
std::vector< geometry_msgs::msg::PoseStamped > endEffectorTrajectory_

Member Function Documentation

◆ computeJointSpaceTrajectory()

ComputeJointTrajectoryErrorCode cl_moveit2z::CbMoveEndEffectorTrajectory::computeJointSpaceTrajectory ( moveit_msgs::msg::RobotTrajectory & computedJointTrajectory)
inlineprotected

Definition at line 202 of file cb_move_end_effector_trajectory.hpp.

204 {
205 // Use the CpJointSpaceTrajectoryPlanner component when present (preferred)
206 CpJointSpaceTrajectoryPlanner * trajectoryPlanner = cpJointSpaceTrajectoryPlanner_;
207
208 if (trajectoryPlanner != nullptr)
209 {
210 // Use component-based trajectory planner (preferred)
211 RCLCPP_INFO(
212 getLogger(),
213 "[CbMoveEndEffectorTrajectory] Using CpJointSpaceTrajectoryPlanner component for IK "
214 "trajectory generation");
215
216 JointTrajectoryOptions options;
217 if (tipLink_ && !tipLink_->empty())
218 {
219 options.tipLink = *tipLink_;
220 }
222 {
223 options.allowInitialDiscontinuity = *allowInitialTrajectoryStateJointDiscontinuity_;
224 }
225
226 auto result = trajectoryPlanner->planFromWaypoints(endEffectorTrajectory_, options);
227
228 if (result.success)
229 {
230 computedJointTrajectory = result.trajectory;
231 RCLCPP_INFO(
232 getLogger(),
233 "[CbMoveEndEffectorTrajectory] IK trajectory generation succeeded (via "
234 "CpJointSpaceTrajectoryPlanner)");
236 }
237 else
238 {
239 computedJointTrajectory = result.trajectory; // Still return partial trajectory
240 RCLCPP_WARN(
241 getLogger(),
242 "[CbMoveEndEffectorTrajectory] IK trajectory generation failed (via "
243 "CpJointSpaceTrajectoryPlanner): %s",
244 result.errorMessage.c_str());
245
246 // Map error codes
247 switch (result.errorCode)
248 {
251 default: // JOINT_TRAJECTORY_DISCONTINUITY and anything else
253 }
254 }
255 }
256 else
257 {
258 // Fallback to legacy IK trajectory generation
259 RCLCPP_WARN(
260 getLogger(),
261 "[CbMoveEndEffectorTrajectory] CpJointSpaceTrajectoryPlanner component not available, "
262 "using legacy IK trajectory generation (consider adding CpJointSpaceTrajectoryPlanner "
263 "component)");
264
265 // LEGACY IMPLEMENTATION (keep for backward compatibility)
266 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] getting current state.. waiting");
267
268 auto currentState = cpMoveGroup_->moveGroupClientInterface->getCurrentState(100);
269 auto groupname = cpMoveGroup_->moveGroupClientInterface->getName();
270
271 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] getting joint names");
272 auto currentjointnames =
273 currentState->getJointModelGroup(groupname)->getActiveJointModelNames();
274
275 if (!tipLink_ || *tipLink_ == "")
276 {
277 tipLink_ = cpMoveGroup_->moveGroupClientInterface->getEndEffectorLink();
278 }
279
280 std::vector<double> jointPositions;
281 currentState->copyJointGroupPositions(groupname, jointPositions);
282
283 std::vector<std::vector<double>> trajectory;
284 std::vector<rclcpp::Duration> trajectoryTimeStamps;
285
286 trajectory.push_back(jointPositions);
287 trajectoryTimeStamps.push_back(rclcpp::Duration(0s));
288
289 auto & first = endEffectorTrajectory_.front();
290 rclcpp::Time referenceTime(first.header.stamp);
291
292 std::vector<int> discontinuityIndexes;
293
294 int ikAttempts = 4;
295 for (size_t k = 0; k < this->endEffectorTrajectory_.size(); k++)
296 {
297 auto & pose = this->endEffectorTrajectory_[k];
298 auto req = std::make_shared<moveit_msgs::srv::GetPositionIK::Request>();
299
300 req->ik_request.ik_link_name = *tipLink_;
301 req->ik_request.robot_state.joint_state.name = currentjointnames;
302 req->ik_request.robot_state.joint_state.position = jointPositions;
303 req->ik_request.group_name = groupname;
304 req->ik_request.avoid_collisions = true;
305 req->ik_request.pose_stamped = pose;
306
307 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] IK request: " << k << " " << *req);
308
309 auto resfut = iksrv_->async_send_request(req);
310 auto status = resfut.wait_for(3s);
311
312 if (status == std::future_status::ready)
313 {
314 auto & prevtrajpoint = trajectory.back();
315 auto res = resfut.get();
316
317 std::stringstream ss;
318 for (size_t j = 0; j < res->solution.joint_state.position.size(); j++)
319 {
320 auto & jointname = res->solution.joint_state.name[j];
321 auto it = std::find(currentjointnames.begin(), currentjointnames.end(), jointname);
322 if (it != currentjointnames.end())
323 {
324 int index = static_cast<int>(std::distance(currentjointnames.begin(), it));
325 jointPositions[index] = res->solution.joint_state.position[j];
326 ss << jointname << "(" << index << "): " << jointPositions[index] << std::endl;
327 }
328 }
329
330 // Continuity check
331 size_t jointindex = 0;
332 int discontinuityJointIndex = -1;
333 double discontinuityDeltaJointIndex = -1;
334 double deltajoint;
335
336 bool check = k > 0 || !allowInitialTrajectoryStateJointDiscontinuity_ ||
338 !(*allowInitialTrajectoryStateJointDiscontinuity_));
339 if (check)
340 {
341 for (jointindex = 0; jointindex < jointPositions.size(); jointindex++)
342 {
343 deltajoint = jointPositions[jointindex] - prevtrajpoint[jointindex];
344 if (fabs(deltajoint) > 0.3)
345 {
346 discontinuityDeltaJointIndex = deltajoint;
347 discontinuityJointIndex = static_cast<int>(jointindex);
348 }
349 }
350 }
351
352 if (ikAttempts > 0 && discontinuityJointIndex != -1)
353 {
354 k--;
355 ikAttempts--;
356 continue;
357 }
358 else
359 {
360 bool discontinuity = false;
361 if (ikAttempts == 0)
362 {
363 discontinuityIndexes.push_back(static_cast<int>(k));
364 discontinuity = true;
365 }
366
367 ikAttempts = 4;
368
369 if (discontinuity && discontinuityJointIndex != -1)
370 {
371 std::stringstream report;
372 report << "Traj[" << k << "/" << endEffectorTrajectory_.size() << "] "
373 << currentjointnames[discontinuityJointIndex]
374 << " IK discontinuity : " << discontinuityDeltaJointIndex << std::endl
375 << "prev joint value: " << prevtrajpoint[discontinuityJointIndex] << std::endl
376 << "current joint value: " << jointPositions[discontinuityJointIndex]
377 << std::endl;
378
379 report << std::endl;
380 for (size_t ji = 0; ji < jointPositions.size(); ji++)
381 {
382 report << currentjointnames[ji] << ": " << jointPositions[ji] << std::endl;
383 }
384
385 for (size_t kindex = 0; kindex < trajectory.size(); kindex++)
386 {
387 report << "[" << kindex << "]: " << trajectory[kindex][discontinuityJointIndex]
388 << std::endl;
389 }
390
391 if (k == 0)
392 {
393 report
394 << "This is the first posture of the trajectory. Maybe the robot initial posture "
395 "is "
396 "not coincident to the initial posture of the generated joint trajectory."
397 << std::endl;
398 }
399
400 RCLCPP_ERROR_STREAM(getLogger(), report.str());
401
402 trajectory.push_back(jointPositions);
403 rclcpp::Duration durationFromStart = rclcpp::Time(pose.header.stamp) - referenceTime;
404 trajectoryTimeStamps.push_back(durationFromStart);
405 continue;
406 }
407 else
408 {
409 trajectory.push_back(jointPositions);
410 rclcpp::Duration durationFromStart = rclcpp::Time(pose.header.stamp) - referenceTime;
411 trajectoryTimeStamps.push_back(durationFromStart);
412
413 RCLCPP_DEBUG_STREAM(getLogger(), "IK solution: " << res->solution.joint_state);
414 RCLCPP_DEBUG_STREAM(getLogger(), "trajpoint: " << std::endl << ss.str());
415 }
416 }
417 }
418 else
419 {
420 RCLCPP_ERROR_STREAM(getLogger(), "[" << getName() << "] wrong IK call");
421 }
422 }
423
424 computedJointTrajectory.joint_trajectory.joint_names = currentjointnames;
425 int i = 0;
426 for (const auto & p : trajectory)
427 {
428 if (i == 0) // Skip current state
429 {
430 i++;
431 continue;
432 }
433
434 trajectory_msgs::msg::JointTrajectoryPoint jp;
435 jp.positions = p;
436 jp.time_from_start = trajectoryTimeStamps[i];
437 computedJointTrajectory.joint_trajectory.points.push_back(jp);
438 i++;
439 }
440
441 if (discontinuityIndexes.size())
442 {
443 if (discontinuityIndexes[0] == 0)
445 else
447 }
448
450 }
451 }
rclcpp::Client< moveit_msgs::srv::GetPositionIK >::SharedPtr iksrv_
std::shared_ptr< moveit::planning_interface::MoveGroupInterface > moveGroupClientInterface
virtual rclcpp::Logger getLogger() const

References cl_moveit2z::JointTrajectoryOptions::allowInitialDiscontinuity, allowInitialTrajectoryStateJointDiscontinuity_, cpJointSpaceTrajectoryPlanner_, cl_moveit2z::CbMoveit2zClientBehaviorBase::cpMoveGroup_, smacc2::ISmaccClientBehavior::currentState, endEffectorTrajectory_, smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), iksrv_, cl_moveit2z::INCORRECT_INITIAL_STATE, cl_moveit2z::JOINT_TRAJECTORY_DISCONTINUITY, cl_moveit2z::CpMoveGroupInterface::moveGroupClientInterface, cl_moveit2z::CpJointSpaceTrajectoryPlanner::planFromWaypoints(), cl_moveit2z::SUCCESS, cl_moveit2z::JointTrajectoryOptions::tipLink, and tipLink_.

Referenced by onEntry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ createMarkers()

virtual void cl_moveit2z::CbMoveEndEffectorTrajectory::createMarkers ( )
inlineprotectedvirtual

Reimplemented in cl_moveit2z::CbCircularPivotMotion.

Definition at line 525 of file cb_move_end_effector_trajectory.hpp.

526 {
527 tf2::Transform localdirection;
528 localdirection.setIdentity();
529 localdirection.setOrigin(tf2::Vector3(0.05, 0, 0));
530 auto frameid = this->endEffectorTrajectory_.front().header.frame_id;
531
532 for (auto & pose : this->endEffectorTrajectory_)
533 {
534 visualization_msgs::msg::Marker marker;
535 marker.header.frame_id = frameid;
536 marker.header.stamp = getNode()->now();
537 marker.ns = "trajectory";
538 marker.id = static_cast<int>(this->beahiorMarkers_.markers.size());
539 marker.type = visualization_msgs::msg::Marker::ARROW;
540 marker.action = visualization_msgs::msg::Marker::ADD;
541 marker.scale.x = 0.005;
542 marker.scale.y = 0.01;
543 marker.scale.z = 0.01;
544 marker.color.a = 0.8;
545 marker.color.r = 1.0;
546 marker.color.g = 0;
547 marker.color.b = 0;
548
549 geometry_msgs::msg::Point start, end;
550 start.x = 0;
551 start.y = 0;
552 start.z = 0;
553
554 tf2::Transform basetransform;
555 tf2::fromMsg(pose.pose, basetransform);
556
557 end.x = localdirection.getOrigin().x();
558 end.y = localdirection.getOrigin().y();
559 end.z = localdirection.getOrigin().z();
560
561 marker.pose.position = pose.pose.position;
562 marker.pose.orientation = pose.pose.orientation;
563 marker.points.push_back(start);
564 marker.points.push_back(end);
565
566 beahiorMarkers_.markers.push_back(marker);
567 }
568 }
virtual rclcpp::Node::SharedPtr getNode() const
const std::string frameid

References beahiorMarkers_, endEffectorTrajectory_, and smacc2::ISmaccClientBehavior::getNode().

Referenced by cl_moveit2z::CbCircularPivotMotion::createMarkers(), and onEntry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ executeJointSpaceTrajectory()

void cl_moveit2z::CbMoveEndEffectorTrajectory::executeJointSpaceTrajectory ( const moveit_msgs::msg::RobotTrajectory & computedJointTrajectory)
inlineprotected

Definition at line 453 of file cb_move_end_effector_trajectory.hpp.

455 {
456 RCLCPP_INFO_STREAM(getLogger(), "[" << this->getName() << "] Executing joint trajectory");
457
458 // Use the CpTrajectoryExecutor component when present (preferred)
459 CpTrajectoryExecutor * trajectoryExecutor = cpTrajectoryExecutor_;
460
461 bool executionSuccess = false;
462
463 if (trajectoryExecutor != nullptr)
464 {
465 // Use component-based trajectory executor (preferred)
466 RCLCPP_INFO(
467 getLogger(),
468 "[CbMoveEndEffectorTrajectory] Using CpTrajectoryExecutor component for execution");
469
470 ExecutionOptions execOptions;
471 execOptions.trajectoryName = this->getName();
472
473 auto execResult = trajectoryExecutor->execute(computedJointTrajectory, execOptions);
474 executionSuccess = execResult.success;
475
476 if (executionSuccess)
477 {
478 RCLCPP_INFO(
479 getLogger(),
480 "[CbMoveEndEffectorTrajectory] Execution succeeded (via CpTrajectoryExecutor)");
481 }
482 else
483 {
484 RCLCPP_WARN(
485 getLogger(),
486 "[CbMoveEndEffectorTrajectory] Execution failed (via CpTrajectoryExecutor): %s",
487 execResult.errorMessage.c_str());
488 }
489 }
490 else
491 {
492 // Fallback to legacy direct execution
493 RCLCPP_WARN(
494 getLogger(),
495 "[CbMoveEndEffectorTrajectory] CpTrajectoryExecutor component not available, using legacy "
496 "execution (consider adding CpTrajectoryExecutor component)");
497
498 auto executionResult =
499 this->cpMoveGroup_->moveGroupClientInterface->execute(computedJointTrajectory);
500 executionSuccess = (executionResult == moveit_msgs::msg::MoveItErrorCodes::SUCCESS);
501
502 RCLCPP_INFO(
503 getLogger(), "[CbMoveEndEffectorTrajectory] Execution %s (legacy mode)",
504 executionSuccess ? "succeeded" : "failed");
505 }
506
507 // Post events
508 if (executionSuccess)
509 {
510 this->postMotionSuccess();
511 }
512 else
513 {
515 this->postFailureEvent();
516 }
517 }

References cl_moveit2z::CbMoveit2zClientBehaviorBase::cpMoveGroup_, cl_moveit2z::CbMoveit2zClientBehaviorBase::cpTrajectoryExecutor_, cl_moveit2z::CpTrajectoryExecutor::execute(), smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), cl_moveit2z::CpMoveGroupInterface::moveGroupClientInterface, smacc2::SmaccAsyncClientBehavior::postFailureEvent(), postMotionExecutionFailureEvents, cl_moveit2z::CbMoveit2zClientBehaviorBase::postMotionSuccess(), and cl_moveit2z::ExecutionOptions::trajectoryName.

Referenced by onEntry(), and cl_moveit2z::CbUndoLastTrajectory::onEntry().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ generateTrajectory()

virtual void cl_moveit2z::CbMoveEndEffectorTrajectory::generateTrajectory ( )
inlineprotectedvirtual

Reimplemented in cl_moveit2z::CbCircularPivotMotion, cl_moveit2z::CbMoveCartesianRelative2, and cl_moveit2z::CbUndoLastTrajectory.

Definition at line 519 of file cb_move_end_effector_trajectory.hpp.

520 {
521 // bypass current trajectory, overridden in derived classes
522 // this->endEffectorTrajectory_ = ...
523 }

Referenced by onEntry().

Here is the caller graph for this function:

◆ getCurrentEndEffectorPose()

void cl_moveit2z::CbMoveEndEffectorTrajectory::getCurrentEndEffectorPose ( std::string globalFrame,
tf2::Stamped< tf2::Transform > & currentEndEffectorTransform )
inlineprotected

Definition at line 578 of file cb_move_end_effector_trajectory.hpp.

580 {
581 // components resolved in onStateOrthogonalAllocation
582 CpTfListener * tfListener = cpTfListener_;
583
584 try
585 {
586 if (!tipLink_ || *tipLink_ == "")
587 {
588 tipLink_ = this->cpMoveGroup_->moveGroupClientInterface->getEndEffectorLink();
589 }
590
591 if (tfListener != nullptr)
592 {
593 // Use component-based TF listener (preferred)
594 auto transformOpt = tfListener->lookupTransform(globalFrame, *tipLink_, rclcpp::Time(0));
595 if (transformOpt)
596 {
597 tf2::fromMsg(transformOpt.value(), currentEndEffectorTransform);
598 }
599 else
600 {
601 RCLCPP_ERROR_STREAM(
602 getLogger(), "[" << getName() << "] Failed to lookup transform from " << *tipLink_
603 << " to " << globalFrame);
604 }
605 }
606 else
607 {
608 // Fallback to legacy TF2 usage if component not available
609 RCLCPP_WARN_STREAM(
610 getLogger(), "[" << getName()
611 << "] CpTfListener component not available, using legacy TF2 (consider "
612 "adding CpTfListener component)");
613 tf2_ros::Buffer tfBuffer(getNode()->get_clock());
614 tf2_ros::TransformListener tfListenerLegacy(tfBuffer);
615
616 tf2::fromMsg(
617 tfBuffer.lookupTransform(globalFrame, *tipLink_, rclcpp::Time(0), rclcpp::Duration(10s)),
618 currentEndEffectorTransform);
619 }
620 }
621 catch (const std::exception & e)
622 {
623 RCLCPP_ERROR_STREAM(
624 getLogger(), "[" << getName() << "] Exception in getCurrentEndEffectorPose: " << e.what());
625 }
626 }

References cl_moveit2z::CbMoveit2zClientBehaviorBase::cpMoveGroup_, cpTfListener_, smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), smacc2::ISmaccClientBehavior::getNode(), cl_moveit2z::CpTfListener::lookupTransform(), cl_moveit2z::CpMoveGroupInterface::moveGroupClientInterface, and tipLink_.

Referenced by cl_moveit2z::CbMoveCartesianRelative2::generateTrajectory().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ initializeROS()

void cl_moveit2z::CbMoveEndEffectorTrajectory::initializeROS ( )
inlineprivate

Definition at line 629 of file cb_move_end_effector_trajectory.hpp.

630 {
631 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] initializing ros");
632
633 auto nh = this->getNode();
634
635 // Only create marker publisher for legacy mode (when CpTrajectoryVisualizer is not used)
636 markersPub_ = nh->create_publisher<visualization_msgs::msg::MarkerArray>(
637 "trajectory_markers", rclcpp::QoS(1));
638
639 iksrv_ = nh->create_client<moveit_msgs::srv::GetPositionIK>("/compute_ik");
640 }
rclcpp::Publisher< visualization_msgs::msg::MarkerArray >::SharedPtr markersPub_

References smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), smacc2::ISmaccClientBehavior::getNode(), iksrv_, and markersPub_.

Referenced by onStateOrthogonalAllocation().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ onEntry()

virtual void cl_moveit2z::CbMoveEndEffectorTrajectory::onEntry ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Reimplemented in cl_moveit2z::CbEndEffectorRotate, and cl_moveit2z::CbUndoLastTrajectory.

Definition at line 113 of file cb_move_end_effector_trajectory.hpp.

114 {
115 // components resolved in onStateOrthogonalAllocation
116 CpTrajectoryVisualizer * trajectoryVisualizer = cpTrajectoryVisualizer_;
117
118 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] Generating end effector trajectory");
119
120 this->generateTrajectory();
121
122 if (this->endEffectorTrajectory_.size() == 0)
123 {
124 RCLCPP_WARN_STREAM(
125 getLogger(), "[" << smacc2::demangleSymbol(typeid(*this).name())
126 << "] No points in the trajectory. Skipping behavior.");
127 return;
128 }
129
130 // Use CpTrajectoryVisualizer if available, otherwise use legacy marker system
131 if (trajectoryVisualizer != nullptr)
132 {
133 RCLCPP_INFO_STREAM(
134 getLogger(),
135 "[" << getName() << "] Setting trajectory visualization using CpTrajectoryVisualizer.");
136 trajectoryVisualizer->setTrajectory(this->endEffectorTrajectory_, "trajectory");
137 }
138 else
139 {
140 RCLCPP_INFO_STREAM(
141 getLogger(), "[" << getName()
142 << "] Creating markers (legacy mode - consider adding "
143 "CpTrajectoryVisualizer component).");
144 this->createMarkers();
145 }
146
147 moveit_msgs::msg::RobotTrajectory computedTrajectory;
148
149 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] Computing joint space trajectory.");
150
151 auto errorcode = computeJointSpaceTrajectory(computedTrajectory);
152
153 bool trajectoryGenerationSuccess = errorcode == ComputeJointTrajectoryErrorCode::SUCCESS;
154
155 CpTrajectoryHistory * trajectoryHistory = cpTrajectoryHistory_;
156
157 if (!trajectoryGenerationSuccess)
158 {
159 RCLCPP_INFO_STREAM(
160 getLogger(), "[" << this->getName() << "] Incorrect trajectory. Posting failure event.");
161 if (trajectoryHistory != nullptr)
162 {
163 moveit_msgs::msg::MoveItErrorCodes error;
164 error.val = moveit_msgs::msg::MoveItErrorCodes::NO_IK_SOLUTION;
165 trajectoryHistory->pushTrajectory(this->getName(), computedTrajectory, error);
166 }
167
169 this->postFailureEvent();
170
172 {
173 this->postJointDiscontinuityEvent(computedTrajectory);
174 }
176 {
177 this->postIncorrectInitialStateEvent(computedTrajectory);
178 }
179 return;
180 }
181 else
182 {
183 if (trajectoryHistory != nullptr)
184 {
185 moveit_msgs::msg::MoveItErrorCodes error;
186 error.val = moveit_msgs::msg::MoveItErrorCodes::SUCCESS;
187 trajectoryHistory->pushTrajectory(this->getName(), computedTrajectory, error);
188 }
189
190 this->executeJointSpaceTrajectory(computedTrajectory);
191 }
192
193 // handle finishing events
194 }
std::function< void(moveit_msgs::msg::RobotTrajectory &)> postJointDiscontinuityEvent
std::function< void(moveit_msgs::msg::RobotTrajectory &)> postIncorrectInitialStateEvent
ComputeJointTrajectoryErrorCode computeJointSpaceTrajectory(moveit_msgs::msg::RobotTrajectory &computedJointTrajectory)
void executeJointSpaceTrajectory(const moveit_msgs::msg::RobotTrajectory &computedJointTrajectory)
std::string demangleSymbol()

References computeJointSpaceTrajectory(), cl_moveit2z::CbMoveit2zClientBehaviorBase::cpMoveGroup_, cl_moveit2z::CbMoveit2zClientBehaviorBase::cpTrajectoryHistory_, cpTrajectoryVisualizer_, createMarkers(), smacc2::introspection::demangleSymbol(), endEffectorTrajectory_, executeJointSpaceTrajectory(), generateTrajectory(), smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), cl_moveit2z::INCORRECT_INITIAL_STATE, cl_moveit2z::JOINT_TRAJECTORY_DISCONTINUITY, cl_moveit2z::CpMoveGroupInterface::postEventMotionExecutionFailed(), smacc2::SmaccAsyncClientBehavior::postFailureEvent(), postIncorrectInitialStateEvent, postJointDiscontinuityEvent, cl_moveit2z::CpTrajectoryHistory::pushTrajectory(), cl_moveit2z::CpTrajectoryVisualizer::setTrajectory(), and cl_moveit2z::SUCCESS.

Here is the call graph for this function:

◆ onExit()

virtual void cl_moveit2z::CbMoveEndEffectorTrajectory::onExit ( )
inlineoverridevirtual

Reimplemented from smacc2::ISmaccClientBehavior.

Definition at line 199 of file cb_move_end_effector_trajectory.hpp.

199{}

◆ onStateOrthogonalAllocation()

template<typename TOrthogonal , typename TSourceObject >
void cl_moveit2z::CbMoveEndEffectorTrajectory::onStateOrthogonalAllocation ( )
inline

Definition at line 79 of file cb_move_end_effector_trajectory.hpp.

80 {
81 this->initializeROS();
82
83 // optional components specific to this behavior family; the shared ones
84 // (move group, motion planner, executor, history) come from the base chain
88
90
91 postJointDiscontinuityEvent = [this](const auto & traj)
92 {
94 ev->trajectory = traj;
95 this->postEvent(ev);
96 };
97
98 postIncorrectInitialStateEvent = [this](const auto & traj)
99 {
101 ev->trajectory = traj;
102 this->postEvent(ev);
103 };
104
106 {
107 RCLCPP_INFO_STREAM(getLogger(), "[" << this->getName() << "] motion execution failed");
110 };
111 }
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
boost::intrusive_ptr< EventType > makeEvent(Args &&... args)

References cpJointSpaceTrajectoryPlanner_, cl_moveit2z::CbMoveit2zClientBehaviorBase::cpMoveGroup_, cpTfListener_, cpTrajectoryVisualizer_, smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), initializeROS(), smacc2::makeEvent(), cl_moveit2z::CbMoveit2zClientBehaviorBase::onStateOrthogonalAllocation(), smacc2::ISmaccClientBehavior::postEvent(), cl_moveit2z::CpMoveGroupInterface::postEventMotionExecutionFailed(), postIncorrectInitialStateEvent, postJointDiscontinuityEvent, postMotionExecutionFailureEvents, smacc2::ISmaccClientBehavior::requiresComponent(), and smacc2::SOFT.

Here is the call graph for this function:

Member Data Documentation

◆ allowInitialTrajectoryStateJointDiscontinuity_

std::optional<bool> cl_moveit2z::CbMoveEndEffectorTrajectory::allowInitialTrajectoryStateJointDiscontinuity_

Definition at line 65 of file cb_move_end_effector_trajectory.hpp.

Referenced by computeJointSpaceTrajectory().

◆ beahiorMarkers_

visualization_msgs::msg::MarkerArray cl_moveit2z::CbMoveEndEffectorTrajectory::beahiorMarkers_
protected

◆ cpJointSpaceTrajectoryPlanner_

CpJointSpaceTrajectoryPlanner* cl_moveit2z::CbMoveEndEffectorTrajectory::cpJointSpaceTrajectoryPlanner_ = nullptr
protected

◆ cpTfListener_

◆ cpTrajectoryVisualizer_

CpTrajectoryVisualizer* cl_moveit2z::CbMoveEndEffectorTrajectory::cpTrajectoryVisualizer_ = nullptr
protected

Definition at line 572 of file cb_move_end_effector_trajectory.hpp.

Referenced by onEntry(), and onStateOrthogonalAllocation().

◆ endEffectorTrajectory_

std::vector<geometry_msgs::msg::PoseStamped> cl_moveit2z::CbMoveEndEffectorTrajectory::endEffectorTrajectory_
protected

◆ group_

std::optional<std::string> cl_moveit2z::CbMoveEndEffectorTrajectory::group_

Definition at line 61 of file cb_move_end_effector_trajectory.hpp.

◆ iksrv_

rclcpp::Client<moveit_msgs::srv::GetPositionIK>::SharedPtr cl_moveit2z::CbMoveEndEffectorTrajectory::iksrv_
private

◆ m_mutex_

std::mutex cl_moveit2z::CbMoveEndEffectorTrajectory::m_mutex_
private

Definition at line 646 of file cb_move_end_effector_trajectory.hpp.

◆ markersPub_

rclcpp::Publisher<visualization_msgs::msg::MarkerArray>::SharedPtr cl_moveit2z::CbMoveEndEffectorTrajectory::markersPub_
private

Definition at line 642 of file cb_move_end_effector_trajectory.hpp.

Referenced by initializeROS().

◆ postIncorrectInitialStateEvent

std::function<void(moveit_msgs::msg::RobotTrajectory &)> cl_moveit2z::CbMoveEndEffectorTrajectory::postIncorrectInitialStateEvent
private

Definition at line 649 of file cb_move_end_effector_trajectory.hpp.

Referenced by onEntry(), and onStateOrthogonalAllocation().

◆ postJointDiscontinuityEvent

std::function<void(moveit_msgs::msg::RobotTrajectory &)> cl_moveit2z::CbMoveEndEffectorTrajectory::postJointDiscontinuityEvent
private

Definition at line 648 of file cb_move_end_effector_trajectory.hpp.

Referenced by onEntry(), and onStateOrthogonalAllocation().

◆ postMotionExecutionFailureEvents

std::function<void()> cl_moveit2z::CbMoveEndEffectorTrajectory::postMotionExecutionFailureEvents
private

◆ tipLink_


The documentation for this class was generated from the following file: