joint_trajectory_controller.h
Go to the documentation of this file.
00001 //
00002 // Created by tom on 10/04/16.
00003 //
00004 
00005 #ifndef ROBOTICAN_CONTROLLERS_JOINT_TRAJECTORY_CONTROLLE_H
00006 #define ROBOTICAN_CONTROLLERS_JOINT_TRAJECTORY_CONTROLLE_H
00007 
00008 #include <cassert>
00009 #include <iterator>
00010 #include <stdexcept>
00011 #include <string>
00012 
00013 // Boost
00014 #include <boost/shared_ptr.hpp>
00015 #include <boost/scoped_ptr.hpp>
00016 
00017 // ROS
00018 #include <ros/node_handle.h>
00019 
00020 // URDF
00021 #include <urdf/model.h>
00022 
00023 // ROS messages
00024 #include <control_msgs/FollowJointTrajectoryAction.h>
00025 #include <control_msgs/JointTrajectoryControllerState.h>
00026 #include <control_msgs/QueryTrajectoryState.h>
00027 #include <trajectory_msgs/JointTrajectory.h>
00028 
00029 // actionlib
00030 #include <actionlib/server/action_server.h>
00031 
00032 // realtime_tools
00033 #include <realtime_tools/realtime_box.h>
00034 #include <realtime_tools/realtime_buffer.h>
00035 #include <realtime_tools/realtime_publisher.h>
00036 
00037 // ros_controls
00038 #include <realtime_tools/realtime_server_goal_handle.h>
00039 #include <controller_interface/controller.h>
00040 #include <hardware_interface/joint_command_interface.h>
00041 #include <hardware_interface/internal/demangle_symbol.h>
00042 
00043 // Project
00044 #include <trajectory_interface/trajectory_interface.h>
00045 
00046 #include <joint_trajectory_controller/joint_trajectory_segment.h>
00047 #include <joint_trajectory_controller/init_joint_trajectory.h>
00048 #include <robotican_controllers/hardware_interface_adapter.h>
00049 
00050 namespace joint_trajectory_controller
00051 {
00052 
00098     template <class SegmentImpl, class HardwareInterface>
00099     class JointTrajectoryController : public controller_interface::Controller<HardwareInterface>
00100     {
00101     public:
00102 
00103         JointTrajectoryController();
00104 
00107         bool init(HardwareInterface* hw, ros::NodeHandle& root_nh, ros::NodeHandle& controller_nh);
00108         /*\}*/
00109 
00113         void starting(const ros::Time& time);
00114 
00116         void stopping(const ros::Time& /*time*/);
00117 
00118         void update(const ros::Time& time, const ros::Duration& period);
00119         /*\}*/
00120 
00121     private:
00122 
00123         struct TimeData
00124         {
00125             TimeData() : time(0.0), period(0.0), uptime(0.0) {}
00126 
00127             ros::Time     time;   
00128             ros::Duration period; 
00129             ros::Time     uptime; 
00130         };
00131 
00132         typedef actionlib::ActionServer<control_msgs::FollowJointTrajectoryAction>                  ActionServer;
00133         typedef boost::shared_ptr<ActionServer>                                                     ActionServerPtr;
00134         typedef ActionServer::GoalHandle                                                            GoalHandle;
00135         typedef realtime_tools::RealtimeServerGoalHandle<control_msgs::FollowJointTrajectoryAction> RealtimeGoalHandle;
00136         typedef boost::shared_ptr<RealtimeGoalHandle>                                               RealtimeGoalHandlePtr;
00137         typedef trajectory_msgs::JointTrajectory::ConstPtr                                          JointTrajectoryConstPtr;
00138         typedef realtime_tools::RealtimePublisher<control_msgs::JointTrajectoryControllerState>     StatePublisher;
00139         typedef boost::scoped_ptr<StatePublisher>                                                   StatePublisherPtr;
00140 
00141         typedef JointTrajectorySegment<SegmentImpl> Segment;
00142         typedef std::vector<Segment> Trajectory;
00143         typedef boost::shared_ptr<Trajectory> TrajectoryPtr;
00144         typedef realtime_tools::RealtimeBox<TrajectoryPtr> TrajectoryBox;
00145         typedef typename Segment::Scalar Scalar;
00146 
00147         typedef HardwareInterfaceAdapter<HardwareInterface, typename Segment::State> HwIfaceAdapter;
00148         typedef typename HardwareInterface::ResourceHandleType JointHandle;
00149 
00150         bool                      verbose_;            
00151         std::string               name_;               
00152         std::vector<JointHandle>  joints_;             
00153         std::vector<bool>         angle_wraparound_;   
00154         std::vector<std::string>  joint_names_;        
00155         SegmentTolerances<Scalar> default_tolerances_; 
00156         HwIfaceAdapter            hw_iface_adapter_;   
00157 
00158         RealtimeGoalHandlePtr     rt_active_goal_;     
00159 
00167         TrajectoryBox curr_trajectory_box_;
00168         TrajectoryPtr hold_trajectory_ptr_; 
00169 
00170         typename Segment::State current_state_;    
00171         typename Segment::State desired_state_;    
00172         typename Segment::State state_error_;      
00173         typename Segment::State hold_start_state_; 
00174         typename Segment::State hold_end_state_;   
00175 
00176         realtime_tools::RealtimeBuffer<TimeData> time_data_;
00177 
00178         ros::Duration state_publisher_period_;
00179         ros::Duration action_monitor_period_;
00180 
00181         typename Segment::Time stop_trajectory_duration_;
00182 
00183         // ROS API
00184         ros::NodeHandle    controller_nh_;
00185         ros::Subscriber    trajectory_command_sub_;
00186         ActionServerPtr    action_server_;
00187         ros::ServiceServer query_state_service_;
00188         StatePublisherPtr  state_publisher_;
00189         bool               _isAborted;
00190 
00191         ros::Timer         goal_handle_timer_;
00192         ros::Time          last_state_publish_time_;
00193 
00194         bool updateTrajectoryCommand(const JointTrajectoryConstPtr& msg, RealtimeGoalHandlePtr gh);
00195         void trajectoryCommandCB(const JointTrajectoryConstPtr& msg);
00196         void goalCB(GoalHandle gh);
00197         void cancelCB(GoalHandle gh);
00198         void preemptActiveGoal();
00199         bool queryStateService(control_msgs::QueryTrajectoryState::Request&  req,
00200                                control_msgs::QueryTrajectoryState::Response& resp);
00201 
00207         void publishState(const ros::Time& time);
00208 
00216         void setHoldPosition(const ros::Time& time);
00217 
00228         void checkPathTolerances(const typename Segment::State& state_error,
00229                                  const Segment&                 segment);
00230 
00242         void checkGoalTolerances(const typename Segment::State& state_error,
00243                                  const Segment&                 segment);
00244 
00245     };
00246 
00247 } // namespace
00248 
00249 #include <robotican_controllers/joint_trajectory_controller_impl.h>
00250 
00251 #endif //ROBOTICAN_CONTROLLERS_JOINT_TRAJECTORY_CONTROLLE_H


robotican_controllers
Author(s):
autogenerated on Fri Oct 27 2017 03:02:40