joint_trajectory_controller.h
Go to the documentation of this file.
1 // Copyright (C) 2013, PAL Robotics S.L.
3 // Copyright (c) 2008, Willow Garage, Inc.
4 //
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
7 // * Redistributions of source code must retain the above copyright notice,
8 // this list of conditions and the following disclaimer.
9 // * Redistributions in binary form must reproduce the above copyright
10 // notice, this list of conditions and the following disclaimer in the
11 // documentation and/or other materials provided with the distribution.
12 // * Neither the name of PAL Robotics S.L. nor the names of its
13 // contributors may be used to endorse or promote products derived from
14 // this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
20 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 // POSSIBILITY OF SUCH DAMAGE.
28 
30 
31 #pragma once
32 
33 
34 // C++ standard
35 #include <cassert>
36 #include <stdexcept>
37 #include <string>
38 #include <memory>
39 
40 // Boost
41 #include <boost/shared_ptr.hpp>
42 #include <boost/dynamic_bitset.hpp>
43 
44 // ROS
45 #include <ros/node_handle.h>
46 
47 // URDF
48 #include <urdf/model.h>
49 
50 // ROS messages
51 #include <control_msgs/FollowJointTrajectoryAction.h>
52 #include <control_msgs/JointTrajectoryControllerState.h>
53 #include <control_msgs/QueryTrajectoryState.h>
54 #include <trajectory_msgs/JointTrajectory.h>
55 
56 // actionlib
58 
59 // realtime_tools
63 
64 // ros_controls
69 
70 // Project
72 
78 
80 {
81 
127 template <class SegmentImpl, class HardwareInterface>
129 {
130 public:
131 
133 
136  bool init(HardwareInterface* hw, ros::NodeHandle& root_nh, ros::NodeHandle& controller_nh);
137  /*\}*/
138 
142  void starting(const ros::Time& time);
143 
145  void stopping(const ros::Time& /*time*/);
146 
147  void update(const ros::Time& time, const ros::Duration& period);
148  /*\}*/
149 
150 protected:
151 
152  struct TimeData
153  {
154  TimeData() : time(0.0), period(0.0), uptime(0.0) {}
155 
159  };
160 
162  typedef std::shared_ptr<ActionServer> ActionServerPtr;
166  typedef trajectory_msgs::JointTrajectory::ConstPtr JointTrajectoryConstPtr;
168  typedef std::unique_ptr<StatePublisher> StatePublisherPtr;
169 
171  typedef std::vector<Segment> TrajectoryPerJoint;
172  typedef std::vector<TrajectoryPerJoint> Trajectory;
173  typedef std::shared_ptr<Trajectory> TrajectoryPtr;
174  typedef std::shared_ptr<TrajectoryPerJoint> TrajectoryPerJointPtr;
176  typedef typename Segment::Scalar Scalar;
177 
179  typedef typename HardwareInterface::ResourceHandleType JointHandle;
180 
181  bool verbose_;
182  std::string name_;
183  std::vector<JointHandle> joints_;
184  std::vector<bool> angle_wraparound_;
185  std::vector<std::string> joint_names_;
187  HwIfaceAdapter hw_iface_adapter_;
188 
189  RealtimeGoalHandlePtr rt_active_goal_;
190 
198  TrajectoryBox curr_trajectory_box_;
199  TrajectoryPtr hold_trajectory_ptr_;
200 
207 
208  std::unique_ptr<TrajectoryBuilder<SegmentImpl> > hold_traj_builder_;
209 
212 
215 
217  boost::dynamic_bitset<> successful_joint_traj_;
219 
220  // ROS API
223  ActionServerPtr action_server_;
225  StatePublisherPtr state_publisher_;
226 
229 
230  virtual bool updateTrajectoryCommand(const JointTrajectoryConstPtr& msg, RealtimeGoalHandlePtr gh, std::string* error_string = nullptr);
231  virtual void trajectoryCommandCB(const JointTrajectoryConstPtr& msg);
232  virtual void goalCB(GoalHandle gh);
233  virtual void cancelCB(GoalHandle gh);
234  virtual void preemptActiveGoal();
235  virtual bool queryStateService(control_msgs::QueryTrajectoryState::Request& req,
236  control_msgs::QueryTrajectoryState::Response& resp);
237 
243  void publishState(const ros::Time& time);
244 
253  void setHoldPosition(const ros::Time& time, RealtimeGoalHandlePtr gh=RealtimeGoalHandlePtr());
254 
255 protected:
259  unsigned int getNumberOfJoints() const;
260 
274  void updateStates(const ros::Time& sample_time, const Trajectory* const traj);
275 
276 protected:
281  static TrajectoryPtr createHoldTrajectory(const unsigned int& number_of_joints);
282 
283 private:
292  virtual void updateFuncExtensionPoint(const Trajectory& curr_traj, const TimeData& time_data);
293 
294 private:
302  void setActionFeedback();
303 
304 };
305 
306 } // namespace
307 
Segment::State current_state_
Preallocated workspace variable.
void setActionFeedback()
Updates the pre-allocated feedback of the current active goal (if any) based on the current state val...
Segment::State state_error_
Preallocated workspace variable.
HwIfaceAdapter hw_iface_adapter_
Adapts desired trajectory state to HW interface.
static TrajectoryPtr createHoldTrajectory(const unsigned int &number_of_joints)
Returns a trajectory consisting of joint trajectories with one pre-allocated segment.
Segment::State desired_joint_state_
Preallocated workspace variable.
Controller for executing joint-space trajectories on a group of joints.
trajectory_msgs::JointTrajectory::ConstPtr JointTrajectoryConstPtr
unsigned int getNumberOfJoints() const
Returns the number of joints of the robot.
Segment::State desired_state_
Preallocated workspace variable.
Segment::Time stop_trajectory_duration_
Duration for stop ramp. If zero, the controller stops at the actual position.
void update(const ros::Time &time, const ros::Duration &period)
bool verbose_
Hard coded verbose flag to help in debugging.
void starting(const ros::Time &time)
Holds the current position.
realtime_tools::RealtimeServerGoalHandle< control_msgs::FollowJointTrajectoryAction > RealtimeGoalHandle
virtual void trajectoryCommandCB(const JointTrajectoryConstPtr &msg)
realtime_tools::RealtimePublisher< control_msgs::JointTrajectoryControllerState > StatePublisher
void setHoldPosition(const ros::Time &time, RealtimeGoalHandlePtr gh=RealtimeGoalHandlePtr())
Hold the current position.
void updateStates(const ros::Time &sample_time, const Trajectory *const traj)
Updates the states by sampling the specified trajectory for each joint at the specified sampling time...
std::vector< JointHandle > joints_
Handles to controlled joints.
void publishState(const ros::Time &time)
Publish current controller state at a throttled frequency.
RealtimeGoalHandlePtr rt_active_goal_
Currently active action goal, if any.
virtual void updateFuncExtensionPoint(const Trajectory &curr_traj, const TimeData &time_data)
Allows derived classes to perform additional checks and to e.g. replace the newly calculated desired ...
bool init(HardwareInterface *hw, ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh)
TrajectoryPtr hold_trajectory_ptr_
Last hold trajectory values.
Segment::State state_joint_error_
Preallocated workspace variable.
ros::Time uptime
Controller uptime. Set to zero at every restart.
Class representing a multi-dimensional quintic spline segment with a start and end time...
HardwareInterfaceAdapter< HardwareInterface, typename Segment::State > HwIfaceAdapter
virtual bool queryStateService(control_msgs::QueryTrajectoryState::Request &req, control_msgs::QueryTrajectoryState::Response &resp)
virtual bool updateTrajectoryCommand(const JointTrajectoryConstPtr &msg, RealtimeGoalHandlePtr gh, std::string *error_string=nullptr)
std::unique_ptr< TrajectoryBuilder< SegmentImpl > > hold_traj_builder_
SegmentTolerances< Scalar > default_tolerances_
Default trajectory segment tolerances.
std::vector< std::string > joint_names_
Controlled joint names.
realtime_tools::RealtimeBox< TrajectoryPtr > TrajectoryBox
Segment::State old_desired_state_
Preallocated workspace variable.
void stopping(const ros::Time &)
Cancels the active action goal, if any.
Trajectory segment tolerances.
Definition: tolerances.h:73
std::vector< bool > angle_wraparound_
Whether controlled joints wrap around or not.
actionlib::ActionServer< control_msgs::FollowJointTrajectoryAction > ActionServer


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