joint_spline_trajectory_controller.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, Willow Garage, Inc.
3  * All rights reserved.
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  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the Willow Garage, Inc. nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
37 #ifndef JOINT_TRAJECTORY_CONTROLLER_H__
38 #define JOINT_TRAJECTORY_CONTROLLER_H__
39 
40 #include <vector>
41 
42 #include <boost/scoped_ptr.hpp>
43 #include <boost/shared_ptr.hpp>
44 #include <ros/node_handle.h>
45 #include <control_toolbox/pid.h>
49 
50 #include "trajectory_msgs/JointTrajectory.h"
51 //#include "robot_mechanism_controllers/Trajectory.h"
52 #include "pr2_controllers_msgs/QueryTrajectoryState.h"
53 #include "pr2_controllers_msgs/JointTrajectoryControllerState.h"
54 
55 namespace controller {
56 
58 {
59 public:
60 
63 
65 
66  void starting();
67  void update();
68 
69 private:
73  std::vector<pr2_mechanism_model::JointState*> joints_;
74  std::vector<control_toolbox::Pid> pids_;
75 
77 
78  void commandCB(const trajectory_msgs::JointTrajectoryConstPtr &msg);
80 
81  bool queryStateService(pr2_controllers_msgs::QueryTrajectoryState::Request &req,
82  pr2_controllers_msgs::QueryTrajectoryState::Response &resp);
84 
85  boost::scoped_ptr<
87  pr2_controllers_msgs::JointTrajectoryControllerState> > controller_state_publisher_;
88 
89 
90  // ------ Mechanisms for passing the trajectory into realtime
91 
92  // coef[0] + coef[1]*t + ... + coef[5]*t^5
93  struct Spline
94  {
95  std::vector<double> coef;
96 
97  Spline() : coef(6, 0.0) {}
98  };
99 
100  struct Segment
101  {
102  double start_time;
103  double duration;
104  std::vector<Spline> splines;
105  };
106  typedef std::vector<Segment> SpecifiedTrajectory;
107 
110 
111  // Holds the trajectory that we are currently following. The mutex
112  // guarding current_trajectory_ is locked from within realtime, so
113  // it may only be locked for a bounded duration.
114  //boost::shared_ptr<const SpecifiedTrajectory> current_trajectory_;
115  //boost::recursive_mutex current_trajectory_lock_RT_;
116 
117  std::vector<double> q, qd, qdd; // Preallocated in init
118 
119  // Samples, but handling time bounds. When the time is past the end
120  // of the spline duration, the position is the last valid position,
121  // and the derivatives are all 0.
122  static void sampleSplineWithTimeBounds(const std::vector<double>& coefficients, double duration, double time,
123  double& position, double& velocity, double& acceleration);
124 };
125 
126 }
127 
128 #endif
realtime_tools::RealtimeBox< boost::shared_ptr< const SpecifiedTrajectory > > current_trajectory_box_
static void sampleSplineWithTimeBounds(const std::vector< double > &coefficients, double duration, double time, double &position, double &velocity, double &acceleration)
std::vector< pr2_mechanism_model::JointState * > joints_
bool queryStateService(pr2_controllers_msgs::QueryTrajectoryState::Request &req, pr2_controllers_msgs::QueryTrajectoryState::Response &resp)
boost::scoped_ptr< realtime_tools::RealtimePublisher< pr2_controllers_msgs::JointTrajectoryControllerState > > controller_state_publisher_
bool init(pr2_mechanism_model::RobotState *robot, ros::NodeHandle &n)
void commandCB(const trajectory_msgs::JointTrajectoryConstPtr &msg)


robot_mechanism_controllers
Author(s): John Hsu, Melonee Wise, Stuart Glaser
autogenerated on Sat Nov 12 2022 03:16:28