joint_trajectory_controller.h
Go to the documentation of this file.
00001 
00002 // Copyright (C) 2013, PAL Robotics S.L.
00003 // Copyright (c) 2008, Willow Garage, Inc.
00004 //
00005 // Redistribution and use in source and binary forms, with or without
00006 // modification, are permitted provided that the following conditions are met:
00007 //   * Redistributions of source code must retain the above copyright notice,
00008 //     this list of conditions and the following disclaimer.
00009 //   * Redistributions in binary form must reproduce the above copyright
00010 //     notice, this list of conditions and the following disclaimer in the
00011 //     documentation and/or other materials provided with the distribution.
00012 //   * Neither the name of PAL Robotics S.L. nor the names of its
00013 //     contributors may be used to endorse or promote products derived from
00014 //     this software without specific prior written permission.
00015 //
00016 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00019 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00020 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00021 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00022 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00023 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00024 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00025 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00026 // POSSIBILITY OF SUCH DAMAGE.
00028 
00030 
00031 #ifndef JOINT_TRAJECTORY_CONTROLLER_JOINT_TRAJECTORY_CONTROLLER_H
00032 #define JOINT_TRAJECTORY_CONTROLLER_JOINT_TRAJECTORY_CONTROLLER_H
00033 
00034 // C++ standard
00035 #include <cassert>
00036 #include <iterator>
00037 #include <stdexcept>
00038 #include <string>
00039 
00040 // Boost
00041 #include <boost/shared_ptr.hpp>
00042 #include <boost/scoped_ptr.hpp>
00043 
00044 // ROS
00045 #include <ros/node_handle.h>
00046 
00047 // URDF
00048 #include <urdf/model.h>
00049 
00050 // ROS messages
00051 #include <control_msgs/FollowJointTrajectoryAction.h>
00052 #include <control_msgs/JointTrajectoryControllerState.h>
00053 #include <control_msgs/QueryTrajectoryState.h>
00054 #include <trajectory_msgs/JointTrajectory.h>
00055 
00056 // actionlib
00057 #include <actionlib/server/action_server.h>
00058 
00059 // realtime_tools
00060 #include <realtime_tools/realtime_box.h>
00061 #include <realtime_tools/realtime_buffer.h>
00062 #include <realtime_tools/realtime_publisher.h>
00063 
00064 // ros_controls
00065 #include <realtime_tools/realtime_server_goal_handle.h>
00066 #include <controller_interface/controller.h>
00067 #include <hardware_interface/joint_command_interface.h>
00068 #include <hardware_interface/internal/demangle_symbol.h>
00069 
00070 // Project
00071 #include <trajectory_interface/trajectory_interface.h>
00072 
00073 #include <joint_trajectory_controller/joint_trajectory_segment.h>
00074 #include <joint_trajectory_controller/init_joint_trajectory.h>
00075 #include <joint_trajectory_controller/hardware_interface_adapter.h>
00076 
00077 namespace joint_trajectory_controller
00078 {
00079 
00125 template <class SegmentImpl, class HardwareInterface>
00126 class JointTrajectoryController : public controller_interface::Controller<HardwareInterface>
00127 {
00128 public:
00129 
00130   JointTrajectoryController();
00131 
00134   bool init(HardwareInterface* hw, ros::NodeHandle& root_nh, ros::NodeHandle& controller_nh);
00135   /*\}*/
00136 
00140   void starting(const ros::Time& time);
00141 
00143   void stopping(const ros::Time& /*time*/);
00144 
00145   void update(const ros::Time& time, const ros::Duration& period);
00146   /*\}*/
00147 
00148 private:
00149 
00150   struct TimeData
00151   {
00152     TimeData() : time(0.0), period(0.0), uptime(0.0) {}
00153 
00154     ros::Time     time;   
00155     ros::Duration period; 
00156     ros::Time     uptime; 
00157   };
00158 
00159   typedef actionlib::ActionServer<control_msgs::FollowJointTrajectoryAction>                  ActionServer;
00160   typedef boost::shared_ptr<ActionServer>                                                     ActionServerPtr;
00161   typedef ActionServer::GoalHandle                                                            GoalHandle;
00162   typedef realtime_tools::RealtimeServerGoalHandle<control_msgs::FollowJointTrajectoryAction> RealtimeGoalHandle;
00163   typedef boost::shared_ptr<RealtimeGoalHandle>                                               RealtimeGoalHandlePtr;
00164   typedef trajectory_msgs::JointTrajectory::ConstPtr                                          JointTrajectoryConstPtr;
00165   typedef realtime_tools::RealtimePublisher<control_msgs::JointTrajectoryControllerState>     StatePublisher;
00166   typedef boost::scoped_ptr<StatePublisher>                                                   StatePublisherPtr;
00167 
00168   typedef JointTrajectorySegment<SegmentImpl> Segment;
00169   typedef std::vector<Segment> Trajectory;
00170   typedef boost::shared_ptr<Trajectory> TrajectoryPtr;
00171   typedef realtime_tools::RealtimeBox<TrajectoryPtr> TrajectoryBox;
00172   typedef typename Segment::Scalar Scalar;
00173 
00174   typedef HardwareInterfaceAdapter<HardwareInterface, typename Segment::State> HwIfaceAdapter;
00175   typedef typename HardwareInterface::ResourceHandleType JointHandle;
00176 
00177   bool                      verbose_;            
00178   std::string               name_;               
00179   std::vector<JointHandle>  joints_;             
00180   std::vector<bool>         angle_wraparound_;   
00181   std::vector<std::string>  joint_names_;        
00182   SegmentTolerances<Scalar> default_tolerances_; 
00183   HwIfaceAdapter            hw_iface_adapter_;   
00184 
00185   RealtimeGoalHandlePtr     rt_active_goal_;     
00186 
00194   TrajectoryBox curr_trajectory_box_;
00195   TrajectoryPtr hold_trajectory_ptr_; 
00196 
00197   typename Segment::State current_state_;    
00198   typename Segment::State desired_state_;    
00199   typename Segment::State state_error_;      
00200   typename Segment::State hold_start_state_; 
00201   typename Segment::State hold_end_state_;   
00202 
00203   realtime_tools::RealtimeBuffer<TimeData> time_data_;
00204 
00205   ros::Duration state_publisher_period_;
00206   ros::Duration action_monitor_period_;
00207 
00208   typename Segment::Time stop_trajectory_duration_;
00209 
00210   // ROS API
00211   ros::NodeHandle    controller_nh_;
00212   ros::Subscriber    trajectory_command_sub_;
00213   ActionServerPtr    action_server_;
00214   ros::ServiceServer query_state_service_;
00215   StatePublisherPtr  state_publisher_;
00216 
00217   ros::Timer         goal_handle_timer_;
00218   ros::Time          last_state_publish_time_;
00219 
00220   bool updateTrajectoryCommand(const JointTrajectoryConstPtr& msg, RealtimeGoalHandlePtr gh);
00221   void trajectoryCommandCB(const JointTrajectoryConstPtr& msg);
00222   void goalCB(GoalHandle gh);
00223   void cancelCB(GoalHandle gh);
00224   void preemptActiveGoal();
00225   bool queryStateService(control_msgs::QueryTrajectoryState::Request&  req,
00226                          control_msgs::QueryTrajectoryState::Response& resp);
00227 
00233   void publishState(const ros::Time& time);
00234 
00242   void setHoldPosition(const ros::Time& time);
00243 
00254   void checkPathTolerances(const typename Segment::State& state_error,
00255                            const Segment&                 segment);
00256 
00268   void checkGoalTolerances(const typename Segment::State& state_error,
00269                            const Segment&                 segment);
00270 
00271 };
00272 
00273 } // namespace
00274 
00275 #include <joint_trajectory_controller/joint_trajectory_controller_impl.h>
00276 
00277 #endif // header guard


joint_trajectory_controller
Author(s): Adolfo Rodriguez Tsouroukdissian
autogenerated on Sat Aug 13 2016 04:20:51