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 ()
 
virtual ~SmaccAsyncClientBehavior ()
 
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 ()
 
ISmaccStateMachinegetStateMachine ()
 
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 (std::string name, SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)
 

Public Attributes

std::optional< std::string > group_
 
std::optional< std::string > tipLink_
 
std::optional< boolallowInitialTrajectoryStateJointDiscontinuity_
 

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 ()
 
virtual 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 ()
 
ISmaccStategetCurrentState ()
 
virtual rclcpp::Node::SharedPtr getNode () const
 
virtual rclcpp::Logger getLogger () const
 

Protected Attributes

std::vector< geometry_msgs::msg::PoseStamped > endEffectorTrajectory_
 
CpTrajectoryVisualizercpTrajectoryVisualizer_ = nullptr
 
CpJointSpaceTrajectoryPlannercpJointSpaceTrajectoryPlanner_ = nullptr
 
CpTfListenercpTfListener_ = nullptr
 
visualization_msgs::msg::MarkerArray beahiorMarkers_
 
- Protected Attributes inherited from cl_moveit2z::CbMoveit2zClientBehaviorBase
CpMoveGroupInterfacecpMoveGroup_ = nullptr
 
CpMotionPlannercpMotionPlanner_ = nullptr
 
CpTrajectoryExecutorcpTrajectoryExecutor_ = nullptr
 
CpTrajectoryHistorycpTrajectoryHistory_ = 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
 
bool autocleanmarkers = false
 

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 68 of file cb_move_end_effector_trajectory.hpp.

68 : tipLink_(tipLink)
69 {
70 }

◆ 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 72 of file cb_move_end_effector_trajectory.hpp.

75 : tipLink_(tipLink), endEffectorTrajectory_(endEffectorTrajectory)
76 {
77 }
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 203 of file cb_move_end_effector_trajectory.hpp.

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

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

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

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 521 of file cb_move_end_effector_trajectory.hpp.

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

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 581 of file cb_move_end_effector_trajectory.hpp.

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

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 632 of file cb_move_end_effector_trajectory.hpp.

633 {
634 RCLCPP_INFO_STREAM(getLogger(), "[" << getName() << "] initializing ros");
635
636 auto nh = this->getNode();
637
638 // Only create marker publisher for legacy mode (when CpTrajectoryVisualizer is not used)
639 markersPub_ = nh->create_publisher<visualization_msgs::msg::MarkerArray>(
640 "trajectory_markers", rclcpp::QoS(1));
641
642 iksrv_ = nh->create_client<moveit_msgs::srv::GetPositionIK>("/compute_ik");
643 }
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 114 of file cb_move_end_effector_trajectory.hpp.

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

200{}

◆ onStateOrthogonalAllocation()

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

Definition at line 80 of file cb_move_end_effector_trajectory.hpp.

81 {
82 this->initializeROS();
83
84 // optional components specific to this behavior family; the shared ones
85 // (move group, motion planner, executor, history) come from the base chain
89
91
92 postJointDiscontinuityEvent = [this](auto traj)
93 {
94 auto ev = new EvJointDiscontinuity<TSourceObject, TOrthogonal>();
95 ev->trajectory = traj;
96 this->postEvent(ev);
97 };
98
99 postIncorrectInitialStateEvent = [this](auto traj)
100 {
101 auto ev = new EvIncorrectInitialPosition<TSourceObject, TOrthogonal>();
102 ev->trajectory = traj;
103 this->postEvent(ev);
104 };
105
107 {
108 RCLCPP_INFO_STREAM(getLogger(), "[" << this->getName() << "] motion execution failed");
111 };
112 }
void requiresComponent(SmaccComponentType *&storage, ComponentRequirement requirementType=ComponentRequirement::SOFT)

References cpJointSpaceTrajectoryPlanner_, cl_moveit2z::CbMoveit2zClientBehaviorBase::cpMoveGroup_, cpTfListener_, cpTrajectoryVisualizer_, smacc2::ISmaccClientBehavior::getLogger(), smacc2::ISmaccClientBehavior::getName(), initializeROS(), 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 66 of file cb_move_end_effector_trajectory.hpp.

Referenced by computeJointSpaceTrajectory().

◆ autocleanmarkers

bool cl_moveit2z::CbMoveEndEffectorTrajectory::autocleanmarkers = false
private

Definition at line 656 of file cb_move_end_effector_trajectory.hpp.

◆ 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 575 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 62 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 649 of file cb_move_end_effector_trajectory.hpp.

◆ markersPub_

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

Definition at line 645 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 652 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 651 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: