SMACC
Loading...
Searching...
No Matches
cb_move_cartesian_relative2.h
Go to the documentation of this file.
1/*****************************************************************************************************************
2 * ReelRobotix Inc. - Software License Agreement Copyright (c) 2018-2020
3 * Authors: Pablo Inigo Blasco, Brett Aldrich
4 *
5 ******************************************************************************************************************/
6
7#pragma once
8
11#include <tf/transform_datatypes.h>
12
14{
16 {
17 public:
18 geometry_msgs::Vector3 offset_;
19
20 boost::optional<double> linearSpeed_m_s_;
21
22 CbMoveCartesianRelative2(std::string referenceFrame, std::string tipLink)
24 {
25 globalFrame_ = referenceFrame;
26 }
27
28 CbMoveCartesianRelative2(std::string referenceFrame, std::string tipLink, geometry_msgs::Vector3 offset)
30 {
31 globalFrame_ = referenceFrame;
32 offset_ = offset;
33 }
34
35 virtual void generateTrajectory() override
36 {
37 // at least 1 sample per centimeter (average)
38 const double METERS_PER_SAMPLE = 0.001;
39
40 float dist_meters = 0;
41 tf::Vector3 voffset;
42 tf::vector3MsgToTF(offset_, voffset);
43
44 float totallineardist = voffset.length();
45
46 int totalSamplesCount = totallineardist / METERS_PER_SAMPLE;
47 int steps = totallineardist / METERS_PER_SAMPLE;
48
49 float interpolation_factor_step = 1.0 / totalSamplesCount;
50
51 double secondsPerSample;
52
54 {
55 linearSpeed_m_s_ = 0.1;
56 }
57
58 secondsPerSample = METERS_PER_SAMPLE / (*linearSpeed_m_s_);
59
60 tf::StampedTransform currentEndEffectorTransform;
61
62 this->getCurrentEndEffectorPose(globalFrame_, currentEndEffectorTransform);
63
64 tf::Transform finalEndEffectorTransform = currentEndEffectorTransform;
65 finalEndEffectorTransform.setOrigin(finalEndEffectorTransform.getOrigin() + voffset);
66
67 float linc = totallineardist / steps; // METERS_PER_SAMPLE with sign
68 float interpolation_factor = 0;
69
70 ros::Time startTime = ros::Time::now();
71
72 for (float i = 0; i < steps; i++)
73 {
74 interpolation_factor += interpolation_factor_step;
75 dist_meters += linc;
76
77 tf::Vector3 vi = currentEndEffectorTransform.getOrigin().lerp(finalEndEffectorTransform.getOrigin(), interpolation_factor);
78
79 tf::Transform pose;
80 pose.setOrigin(vi);
81 pose.setRotation(currentEndEffectorTransform.getRotation());
82
83 geometry_msgs::PoseStamped pointerPose;
84 tf::poseTFToMsg(pose, pointerPose.pose);
85 pointerPose.header.frame_id = globalFrame_;
86 pointerPose.header.stamp = startTime + ros::Duration(i * secondsPerSample);
87
88 this->endEffectorTrajectory_.push_back(pointerPose);
89 }
90
91 ROS_INFO_STREAM("[CbMoveEndEffectorRelative2] Target End efector Pose: " << this->endEffectorTrajectory_.back());
92
93 }
94
95 private:
96 std::string globalFrame_;
97 };
98} // namespace cl_move_group_interface
CbMoveCartesianRelative2(std::string referenceFrame, std::string tipLink)
CbMoveCartesianRelative2(std::string referenceFrame, std::string tipLink, geometry_msgs::Vector3 offset)
void getCurrentEndEffectorPose(std::string globalFrame, tf::StampedTransform &currentEndEffectorTransform)
std::vector< geometry_msgs::PoseStamped > endEffectorTrajectory_