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_;
188 
190 
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
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 
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 
demangle_symbol.h
realtime_tools::RealtimeBuffer
joint_trajectory_controller::SegmentTolerances
Trajectory segment tolerances.
Definition: tolerances.h:73
realtime_publisher.h
realtime_server_goal_handle.h
node_handle.h
joint_trajectory_controller::JointTrajectoryController::StatePublisherPtr
std::unique_ptr< StatePublisher > StatePublisherPtr
Definition: joint_trajectory_controller.h:168
joint_trajectory_controller::JointTrajectoryController::TrajectoryPerJoint
std::vector< Segment > TrajectoryPerJoint
Definition: joint_trajectory_controller.h:171
joint_trajectory_controller::JointTrajectoryController::hold_trajectory_ptr_
TrajectoryPtr hold_trajectory_ptr_
Last hold trajectory values.
Definition: joint_trajectory_controller.h:199
joint_trajectory_controller::JointTrajectoryController::JointHandle
HardwareInterface::ResourceHandleType JointHandle
Definition: joint_trajectory_controller.h:179
joint_trajectory_controller::JointTrajectoryController::JointTrajectoryConstPtr
trajectory_msgs::JointTrajectory::ConstPtr JointTrajectoryConstPtr
Definition: joint_trajectory_controller.h:166
joint_trajectory_controller::JointTrajectoryController::StatePublisher
realtime_tools::RealtimePublisher< control_msgs::JointTrajectoryControllerState > StatePublisher
Definition: joint_trajectory_controller.h:167
joint_trajectory_controller::JointTrajectoryController::goalCB
virtual void goalCB(GoalHandle gh)
Definition: joint_trajectory_controller_impl.h:567
joint_trajectory_controller::JointTrajectoryController::TimeData::TimeData
TimeData()
Definition: joint_trajectory_controller.h:154
boost::shared_ptr< RealtimeGoalHandle >
actionlib::ServerGoalHandle
joint_trajectory_controller::JointTrajectorySegment::Time
Segment::Time Time
Definition: joint_trajectory_segment.h:74
joint_trajectory_controller::JointTrajectoryController::ActionServer
actionlib::ActionServer< control_msgs::FollowJointTrajectoryAction > ActionServer
Definition: joint_trajectory_controller.h:161
joint_trajectory_controller::JointTrajectoryController::setActionFeedback
void setActionFeedback()
Updates the pre-allocated feedback of the current active goal (if any) based on the current state val...
Definition: joint_trajectory_controller_impl.h:798
joint_trajectory_controller::JointTrajectoryController::joints_
std::vector< JointHandle > joints_
Handles to controlled joints.
Definition: joint_trajectory_controller.h:183
joint_trajectory_controller::JointTrajectoryController::Scalar
Segment::Scalar Scalar
Definition: joint_trajectory_controller.h:176
actionlib::ActionServer
realtime_buffer.h
joint_trajectory_controller::JointTrajectoryController::GoalHandle
ActionServer::GoalHandle GoalHandle
Definition: joint_trajectory_controller.h:163
joint_trajectory_controller::JointTrajectorySegment::Scalar
Segment::Scalar Scalar
Definition: joint_trajectory_segment.h:73
joint_trajectory_controller::JointTrajectoryController::time_data_
realtime_tools::RealtimeBuffer< TimeData > time_data_
Definition: joint_trajectory_controller.h:210
joint_trajectory_controller::JointTrajectoryController::rt_active_goal_
RealtimeGoalHandlePtr rt_active_goal_
Currently active action goal, if any.
Definition: joint_trajectory_controller.h:189
trajectory_interface.h
joint_trajectory_controller::JointTrajectoryController::TimeData::time
ros::Time time
Time of last update cycle.
Definition: joint_trajectory_controller.h:156
joint_trajectory_controller::JointTrajectoryController::desired_state_
Segment::State desired_state_
Preallocated workspace variable.
Definition: joint_trajectory_controller.h:202
joint_trajectory_controller::JointTrajectoryController::hw_iface_adapter_
HwIfaceAdapter hw_iface_adapter_
Adapts desired trajectory state to HW interface.
Definition: joint_trajectory_controller.h:187
controller_interface::Controller
joint_trajectory_controller::JointTrajectoryController::TimeData::uptime
ros::Time uptime
Controller uptime. Set to zero at every restart.
Definition: joint_trajectory_controller.h:158
joint_trajectory_controller::JointTrajectoryController::queryStateService
virtual bool queryStateService(control_msgs::QueryTrajectoryState::Request &req, control_msgs::QueryTrajectoryState::Response &resp)
Definition: joint_trajectory_controller_impl.h:664
joint_trajectory_controller::JointTrajectoryController::goal_handle_timer_
ros::Timer goal_handle_timer_
Definition: joint_trajectory_controller.h:227
joint_trajectory_controller::JointTrajectoryController::query_state_service_
ros::ServiceServer query_state_service_
Definition: joint_trajectory_controller.h:224
joint_trajectory_controller::JointTrajectoryController::Segment
JointTrajectorySegment< SegmentImpl > Segment
Definition: joint_trajectory_controller.h:170
init_joint_trajectory.h
ros::ServiceServer
joint_trajectory_controller::JointTrajectoryController::starting
void starting(const ros::Time &time)
Holds the current position.
Definition: joint_trajectory_controller_impl.h:133
realtime_tools::RealtimePublisher
joint_trajectory_controller::JointTrajectoryController::curr_trajectory_box_
TrajectoryBox curr_trajectory_box_
Definition: joint_trajectory_controller.h:198
joint_trajectory_controller::JointTrajectoryController::successful_joint_traj_
boost::dynamic_bitset successful_joint_traj_
Definition: joint_trajectory_controller.h:217
joint_trajectory_controller
Definition: hold_trajectory_builder.h:35
joint_trajectory_controller::JointTrajectorySegment::State
Definition: joint_trajectory_segment.h:79
joint_trajectory_controller::JointTrajectoryController::setHoldPosition
void setHoldPosition(const ros::Time &time, RealtimeGoalHandlePtr gh=RealtimeGoalHandlePtr())
Hold the current position.
Definition: joint_trajectory_controller_impl.h:740
controller.h
joint_command_interface.h
joint_trajectory_controller::JointTrajectoryController::updateStates
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...
Definition: joint_trajectory_controller_impl.h:766
joint_trajectory_controller::JointTrajectorySegment
Class representing a multi-dimensional quintic spline segment with a start and end time.
Definition: joint_trajectory_segment.h:70
joint_trajectory_controller::JointTrajectoryController::TrajectoryPtr
std::shared_ptr< Trajectory > TrajectoryPtr
Definition: joint_trajectory_controller.h:173
realtime_tools::RealtimeBox< TrajectoryPtr >
hold_trajectory_builder.h
joint_trajectory_controller::JointTrajectoryController::TimeData
Definition: joint_trajectory_controller.h:152
model.h
joint_trajectory_controller::JointTrajectoryController::publishState
void publishState(const ros::Time &time)
Publish current controller state at a throttled frequency.
Definition: joint_trajectory_controller_impl.h:712
joint_trajectory_controller::JointTrajectoryController::TimeData::period
ros::Duration period
Period of last update cycle.
Definition: joint_trajectory_controller.h:157
joint_trajectory_controller::JointTrajectoryController::update
void update(const ros::Time &time, const ros::Duration &period)
Definition: joint_trajectory_controller_impl.h:347
joint_trajectory_controller::JointTrajectoryController::default_tolerances_
SegmentTolerances< Scalar > default_tolerances_
Default trajectory segment tolerances.
Definition: joint_trajectory_controller.h:186
joint_trajectory_controller::JointTrajectoryController::joint_names_
std::vector< std::string > joint_names_
Controlled joint names.
Definition: joint_trajectory_controller.h:185
joint_trajectory_controller::JointTrajectoryController::trajectoryCommandCB
virtual void trajectoryCommandCB(const JointTrajectoryConstPtr &msg)
Definition: joint_trajectory_controller_impl.h:167
joint_trajectory_controller::JointTrajectoryController::old_time_data_
TimeData old_time_data_
Definition: joint_trajectory_controller.h:211
joint_trajectory_controller::JointTrajectoryController::state_joint_error_
Segment::State state_joint_error_
Preallocated workspace variable.
Definition: joint_trajectory_controller.h:206
joint_trajectory_controller::JointTrajectoryController::Trajectory
std::vector< TrajectoryPerJoint > Trajectory
Definition: joint_trajectory_controller.h:172
joint_trajectory_controller::JointTrajectoryController::HwIfaceAdapter
HardwareInterfaceAdapter< HardwareInterface, typename Segment::State > HwIfaceAdapter
Definition: joint_trajectory_controller.h:178
joint_trajectory_controller::JointTrajectoryController::init
bool init(HardwareInterface *hw, ros::NodeHandle &root_nh, ros::NodeHandle &controller_nh)
Definition: joint_trajectory_controller_impl.h:205
joint_trajectory_segment.h
joint_trajectory_controller::JointTrajectoryController::TrajectoryPerJointPtr
std::shared_ptr< TrajectoryPerJoint > TrajectoryPerJointPtr
Definition: joint_trajectory_controller.h:174
joint_trajectory_controller::JointTrajectoryController::ActionServerPtr
std::shared_ptr< ActionServer > ActionServerPtr
Definition: joint_trajectory_controller.h:162
joint_trajectory_controller::JointTrajectoryController::controller_nh_
ros::NodeHandle controller_nh_
Definition: joint_trajectory_controller.h:221
action_server.h
joint_trajectory_controller::JointTrajectoryController::updateTrajectoryCommand
virtual bool updateTrajectoryCommand(const JointTrajectoryConstPtr &msg, RealtimeGoalHandlePtr gh, std::string *error_string=nullptr)
Definition: joint_trajectory_controller_impl.h:481
joint_trajectory_controller::JointTrajectoryController::RealtimeGoalHandle
realtime_tools::RealtimeServerGoalHandle< control_msgs::FollowJointTrajectoryAction > RealtimeGoalHandle
Definition: joint_trajectory_controller.h:164
joint_trajectory_controller::JointTrajectoryController::state_publisher_period_
ros::Duration state_publisher_period_
Definition: joint_trajectory_controller.h:213
joint_trajectory_controller::JointTrajectoryController::desired_joint_state_
Segment::State desired_joint_state_
Preallocated workspace variable.
Definition: joint_trajectory_controller.h:205
joint_trajectory_controller::JointTrajectoryController::stopping
void stopping(const ros::Time &)
Cancels the active action goal, if any.
Definition: joint_trajectory_controller_impl.h:160
realtime_tools::RealtimeServerGoalHandle
joint_trajectory_controller::JointTrajectoryController
Controller for executing joint-space trajectories on a group of joints.
Definition: joint_trajectory_controller.h:128
stop_trajectory_builder.h
ros::Time
HardwareInterfaceAdapter< HardwareInterface, typename Segment::State >
joint_trajectory_controller::JointTrajectoryController::createHoldTrajectory
static TrajectoryPtr createHoldTrajectory(const unsigned int &number_of_joints)
Returns a trajectory consisting of joint trajectories with one pre-allocated segment.
Definition: joint_trajectory_controller_impl.h:823
joint_trajectory_controller::JointTrajectoryController::state_error_
Segment::State state_error_
Preallocated workspace variable.
Definition: joint_trajectory_controller.h:204
joint_trajectory_controller_impl.h
joint_trajectory_controller::JointTrajectoryController::preemptActiveGoal
virtual void preemptActiveGoal()
Definition: joint_trajectory_controller_impl.h:175
joint_trajectory_controller::JointTrajectoryController::JointTrajectoryController
JointTrajectoryController()
Definition: joint_trajectory_controller_impl.h:190
joint_trajectory_controller::JointTrajectoryController::cancelCB
virtual void cancelCB(GoalHandle gh)
Definition: joint_trajectory_controller_impl.h:640
joint_trajectory_controller::JointTrajectoryController::trajectory_command_sub_
ros::Subscriber trajectory_command_sub_
Definition: joint_trajectory_controller.h:222
joint_trajectory_controller::JointTrajectoryController::RealtimeGoalHandlePtr
boost::shared_ptr< RealtimeGoalHandle > RealtimeGoalHandlePtr
Definition: joint_trajectory_controller.h:165
joint_trajectory_controller::JointTrajectoryController::getNumberOfJoints
unsigned int getNumberOfJoints() const
Returns the number of joints of the robot.
Definition: joint_trajectory_controller_impl.h:759
joint_trajectory_controller::JointTrajectoryController::old_desired_state_
Segment::State old_desired_state_
Preallocated workspace variable.
Definition: joint_trajectory_controller.h:203
joint_trajectory_controller::JointTrajectoryController::updateFuncExtensionPoint
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 ...
Definition: joint_trajectory_controller_impl.h:752
hardware_interface_adapter.h
joint_trajectory_controller::JointTrajectoryController::current_state_
Segment::State current_state_
Preallocated workspace variable.
Definition: joint_trajectory_controller.h:201
joint_trajectory_controller::JointTrajectoryController::allow_partial_joints_goal_
bool allow_partial_joints_goal_
Definition: joint_trajectory_controller.h:218
joint_trajectory_controller::JointTrajectoryController::last_state_publish_time_
ros::Time last_state_publish_time_
Definition: joint_trajectory_controller.h:228
joint_trajectory_controller::JointTrajectoryController::angle_wraparound_
std::vector< bool > angle_wraparound_
Whether controlled joints wrap around or not.
Definition: joint_trajectory_controller.h:184
ros::Duration
joint_trajectory_controller::JointTrajectoryController::action_server_
ActionServerPtr action_server_
Definition: joint_trajectory_controller.h:223
joint_trajectory_controller::JointTrajectoryController::hold_traj_builder_
std::unique_ptr< TrajectoryBuilder< SegmentImpl > > hold_traj_builder_
Definition: joint_trajectory_controller.h:208
ros::Timer
joint_trajectory_controller::JointTrajectoryController::action_monitor_period_
ros::Duration action_monitor_period_
Definition: joint_trajectory_controller.h:214
joint_trajectory_controller::JointTrajectoryController::TrajectoryBox
realtime_tools::RealtimeBox< TrajectoryPtr > TrajectoryBox
Definition: joint_trajectory_controller.h:175
joint_trajectory_controller::JointTrajectoryController::state_publisher_
StatePublisherPtr state_publisher_
Definition: joint_trajectory_controller.h:225
joint_trajectory_controller::JointTrajectoryController::name_
std::string name_
Controller name.
Definition: joint_trajectory_controller.h:182
ros::NodeHandle
ros::Subscriber
joint_trajectory_controller::JointTrajectoryController::stop_trajectory_duration_
Segment::Time stop_trajectory_duration_
Duration for stop ramp. If zero, the controller stops at the actual position.
Definition: joint_trajectory_controller.h:216
joint_trajectory_controller::JointTrajectoryController::verbose_
bool verbose_
Hard coded verbose flag to help in debugging.
Definition: joint_trajectory_controller.h:181
realtime_box.h


joint_trajectory_controller
Author(s): Adolfo Rodriguez Tsouroukdissian
autogenerated on Fri Nov 3 2023 02:18:24