trajectory_builder.h
Go to the documentation of this file.
1 // Copyright (c) 2020 Pilz GmbH & Co. KG
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are met:
6 // * Redistributions of source code must retain the above copyright notice,
7 // this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above copyright
9 // notice, this list of conditions and the following disclaimer in the
10 // documentation and/or other materials provided with the distribution.
11 // * Neither the name of Pilz GmbH & Co. KG nor the names of its
12 // contributors may be used to endorse or promote products derived from
13 // this software without specific prior written permission.
14 //
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 // POSSIBILITY OF SUCH DAMAGE.
27 
28 #ifndef TRAJECTORY_BUILDER_H
29 #define TRAJECTORY_BUILDER_H
30 
31 #include <vector>
32 
33 // Boost
34 #include <boost/shared_ptr.hpp>
35 #include <boost/optional.hpp>
36 
37 // ROS messages
38 #include <control_msgs/FollowJointTrajectoryAction.h>
39 
40 // realtime_tools
42 
44 
46 {
47 
63 template<class SegmentImpl>
65 {
66 public:
70  virtual ~TrajectoryBuilder<SegmentImpl>() = default;
71 
72 private:
74  using TrajectoryPerJoint = std::vector<Segment>;
75  using Trajectory = std::vector<TrajectoryPerJoint>;
76 
79 
80 public:
86  TrajectoryBuilder<SegmentImpl>* setStartTime(const typename Segment::Time& start_time);
87 
94 
95 public:
100  virtual void reset();
101 
102 public:
109  virtual bool buildTrajectory(Trajectory* trajectory) = 0;
110 
111 protected:
115  const boost::optional<typename Segment::Time>& getStartTime() const;
116 
117 protected:
119 
126  static bool isTrajectoryValid(const Trajectory* trajectory,
127  const unsigned int expected_number_of_joints,
128  const unsigned int expected_number_of_segments);
129 
130 private:
131  boost::optional<typename Segment::Time> start_time_ {boost::none};
132  // We do not want to participate in the life time management of the
133  // goal handle, therefore, only a reference is stored.
134  boost::optional<RealtimeGoalHandlePtr&> goal_handle_ {boost::none};
135 
136 };
137 
138 template<class SegmentImpl>
140 {
141  start_time_ = start_time;
142  return this;
143 }
144 
145 template<class SegmentImpl>
146 inline const boost::optional<typename TrajectoryBuilder<SegmentImpl>::Segment::Time>& TrajectoryBuilder<SegmentImpl>::getStartTime() const
147 {
148  return start_time_;
149 }
150 
151 template<class SegmentImpl>
153 {
154  goal_handle_ = goal_handle;
155  return this;
156 }
157 
158 template<class SegmentImpl>
160 {
162 }
163 
164 template<class SegmentImpl>
166 {
167  return RealtimeGoalHandlePtr();
168 }
169 
170 template<class SegmentImpl>
172 {
173  start_time_ = boost::none;
174  goal_handle_ = boost::none;
175 }
176 
177 template<class SegmentImpl>
179  const unsigned int expected_number_of_joints,
180  const unsigned int expected_number_of_segments)
181 {
182  if (trajectory->size() != expected_number_of_joints)
183  {
184  return false;
185  }
186  for (const auto& traj_per_joint : *trajectory)
187  {
188  if (traj_per_joint.size() != expected_number_of_segments)
189  {
190  return false;
191  }
192  }
193  return true;
194 }
195 
196 }
197 
198 #endif // TRAJECTORY_BUILDER_H
boost::optional< RealtimeGoalHandlePtr & > goal_handle_
virtual void reset()
Ensures re-usability by allowing the user to reset members of the builder which should be reset betwe...
boost::optional< typename Segment::Time > start_time_
TrajectoryBuilder< SegmentImpl > * setGoalHandle(RealtimeGoalHandlePtr &goal_handle)
Set the goal handle that will be attached to the trajectory segments.
Class representing a multi-dimensional quintic spline segment with a start and end time...
std::vector< TrajectoryPerJoint > Trajectory
virtual bool buildTrajectory(Trajectory *trajectory)=0
Creates the type of trajectory described by the builder.
static RealtimeGoalHandlePtr createDefaultGoalHandle()
TrajectoryBuilder< SegmentImpl > * setStartTime(const typename Segment::Time &start_time)
Set the start time [seconds] of the trajectory to be built.
static bool isTrajectoryValid(const Trajectory *trajectory, const unsigned int expected_number_of_joints, const unsigned int expected_number_of_segments)
Check if the elements of a given trajectory are sized properly.
Base class for classes used to construct diffent trajectory types.
RealtimeGoalHandlePtr createGoalHandlePtr() const
Return the set goal handle or a default one, if no goal handle was set.
const boost::optional< typename Segment::Time > & getStartTime() const
Return the set start time.
boost::shared_ptr< RealtimeGoalHandle > RealtimeGoalHandlePtr


joint_trajectory_controller
Author(s): Adolfo Rodriguez Tsouroukdissian
autogenerated on Fri Feb 3 2023 03:19:15