Go to the documentation of this file.00001 #ifndef YOUBOT_JOINTTRAJECTORYCONTROLLER_H
00002 #define YOUBOT_JOINTTRAJECTORYCONTROLLER_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054 #include <vector>
00055 #include <string>
00056 #include <cstdio>
00057 #include <stdexcept>
00058 #include <iostream>
00059 #include <youbot_driver/generic/Logger.hpp>
00060 #include <youbot_driver/generic/Units.hpp>
00061 #include <youbot_driver/generic/Time.hpp>
00062 #include <youbot_driver/generic/Exceptions.hpp>
00063 #include <youbot_driver/generic/PidController.hpp>
00064 #include <youbot_driver/generic-joint/JointTrajectory.hpp>
00065 #include <youbot_driver/youbot/YouBotJointParameter.hpp>
00066 #include <youbot_driver/youbot/YouBotJointParameterPasswordProtected.hpp>
00067 #include <youbot_driver/generic/dataobjectlockfree/DataObjectLockFree.hpp>
00068
00069 namespace youbot
00070 {
00071
00074 struct Spline
00075 {
00076 std::vector<double> coef;
00077
00078 Spline() :
00079 coef(6, 0.0)
00080 {
00081 }
00082 };
00083
00085 struct Segment
00086 {
00087 boost::posix_time::ptime start_time;
00088 boost::posix_time::time_duration duration;
00089 Spline spline;
00090 };
00091
00095 class JointTrajectoryController
00096 {
00097 public:
00098 JointTrajectoryController();
00099
00100 virtual ~JointTrajectoryController();
00101
00102 private:
00103 JointTrajectoryController(const JointTrajectoryController & source);
00104
00105 JointTrajectoryController & operator=(const JointTrajectoryController & source);
00106
00107 public:
00108 void getConfigurationParameter(double& PParameter, double& IParameter, double& DParameter, double& IClippingMax,
00109 double& IClippingMin);
00110
00111 void setConfigurationParameter(const double PParameter, const double IParameter, const double DParameter,
00112 const double IClippingMax, const double IClippingMin);
00113
00114 void setTrajectory(const JointTrajectory& input_traj);
00115
00116 void cancelCurrentTrajectory();
00117
00118 bool isTrajectoryControllerActive();
00119
00120 bool updateTrajectoryController(const SlaveMessageInput& actual, SlaveMessageOutput& velocity);
00121
00122 void getLastTargetPosition(JointAngleSetpoint& position);
00123
00124 void getLastTargetVelocity(JointVelocitySetpoint& velocity);
00125
00126 void setGearRatio(const double& ratio)
00127 {
00128 this->gearRatio = ratio;
00129 }
00130 ;
00131
00132 void setEncoderTicksPerRound(const int& encoderTicks)
00133 {
00134 this->encoderTicksPerRound = encoderTicks;
00135 }
00136 ;
00137
00138 void setInverseMovementDirection(const bool invDirection)
00139 {
00140 this->inverseDirection = invDirection;
00141 }
00142 ;
00143
00144 private:
00145 void getQuinticSplineCoefficients(const double start_pos, const double start_vel, const double start_acc,
00146 const double end_pos, const double end_vel, const double end_acc, const double time,
00147 std::vector<double>& coefficients);
00148
00149 void sampleQuinticSpline(const std::vector<double>& coefficients, const double time, double& position,
00150 double& velocity, double& acceleration);
00151
00152 void getCubicSplineCoefficients(const double start_pos, const double start_vel, const double end_pos,
00153 const double end_vel, const double time, std::vector<double>& coefficients);
00154
00155 void generatePowers(const int n, const double x, double* powers);
00156
00157 void sampleSplineWithTimeBounds(const std::vector<double>& coefficients, const double duration, const double time,
00158 double& position, double& velocity, double& acceleration);
00159
00160 bool isControllerActive;
00161
00162 PidController pid;
00163
00164 boost::posix_time::ptime time;
00165
00166 boost::posix_time::ptime last_time;
00167
00168 typedef std::vector<Segment> SpecifiedTrajectory;
00169
00170 DataObjectLockFree<boost::shared_ptr<const SpecifiedTrajectory> > current_trajectory_box_;
00171
00172 double targetPosition;
00173
00174 double targetVelocity;
00175
00176 double targetAcceleration;
00177
00178 int encoderTicksPerRound;
00179
00180 double gearRatio;
00181
00182 bool inverseDirection;
00183
00184 double pose_error;
00185
00186 double velocity_error;
00187
00188 double velsetpoint;
00189
00190 double time_till_seg_start;
00191 double duration;
00192 double actualpose;
00193 double actualvel;
00194
00195 };
00196
00197 }
00198 #endif