JointTrajectoryController.hpp
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 "generic/Logger.hpp"
00060 #include "generic/Units.hpp"
00061 #include "generic/Time.hpp"
00062 #include "generic/Exceptions.hpp"
00063 #include "generic/PidController.hpp"
00064 #include "generic-joint/JointTrajectory.hpp"
00065 #include "youbot/YouBotJointParameter.hpp"
00066 #include "youbot/YouBotJointParameterPasswordProtected.hpp"
00067 #include "generic/dataobjectlockfree/DataObjectLockFree.hpp"
00068
00069 namespace youbot {
00070
00071
00072
00073
00074
00075 struct Spline
00076 {
00077 std::vector<double> coef;
00078
00079 Spline() : coef(6, 0.0) {}
00080 };
00081
00082
00083 struct Segment
00084 {
00085 boost::posix_time::ptime start_time;
00086 boost::posix_time::time_duration duration;
00087 Spline spline;
00088 };
00089
00090
00091
00092
00093 class JointTrajectoryController {
00094 public:
00095 JointTrajectoryController();
00096
00097 virtual ~JointTrajectoryController();
00098
00099
00100 private:
00101 JointTrajectoryController(const JointTrajectoryController & source);
00102
00103 JointTrajectoryController & operator=(const JointTrajectoryController & source);
00104
00105
00106 public:
00107 void getConfigurationParameter(double& PParameter, double& IParameter, double& DParameter, double& IClippingMax, double& IClippingMin);
00108
00109 void setConfigurationParameter(const double PParameter, const double IParameter, const double DParameter, const double IClippingMax, const double IClippingMin);
00110
00111 void setTrajectory(const JointTrajectory& input_traj);
00112
00113 void cancelCurrentTrajectory();
00114
00115 bool isTrajectoryControllerActive();
00116
00117 bool updateTrajectoryController(const SlaveMessageInput& actual, SlaveMessageOutput& velocity);
00118
00119 void getLastTargetPosition(JointAngleSetpoint& position);
00120
00121 void getLastTargetVelocity(JointVelocitySetpoint& velocity);
00122
00123 void setGearRatio(const double& ratio) {this->gearRatio = ratio;};
00124
00125 void setEncoderTicksPerRound(const int& encoderTicks) {this->encoderTicksPerRound = encoderTicks;};
00126
00127 void setInverseMovementDirection(const bool invDirection) {this->inverseDirection = invDirection;};
00128
00129
00130 private:
00131 void getQuinticSplineCoefficients(const double start_pos, const double start_vel, const double start_acc, const double end_pos, const double end_vel, const double end_acc, const double time, std::vector<double>& coefficients);
00132
00133 void sampleQuinticSpline(const std::vector<double>& coefficients, const double time, double& position, double& velocity, double& acceleration);
00134
00135 void getCubicSplineCoefficients(const double start_pos, const double start_vel, const double end_pos, const double end_vel, const double time, std::vector<double>& coefficients);
00136
00137 void generatePowers(const int n, const double x, double* powers);
00138
00139 void sampleSplineWithTimeBounds(const std::vector<double>& coefficients, const double duration, const double time, double& position, double& velocity, double& acceleration);
00140
00141 bool isControllerActive;
00142
00143 PidController pid;
00144
00145 boost::posix_time::ptime time;
00146
00147 boost::posix_time::ptime last_time;
00148
00149 typedef std::vector<Segment> SpecifiedTrajectory;
00150
00151 DataObjectLockFree< boost::shared_ptr<const SpecifiedTrajectory> > current_trajectory_box_;
00152
00153 double targetPosition;
00154
00155 double targetVelocity;
00156
00157 double targetAcceleration;
00158
00159 int encoderTicksPerRound;
00160
00161 double gearRatio;
00162
00163 bool inverseDirection;
00164
00165 double pose_error;
00166
00167 double velocity_error;
00168
00169 double velsetpoint;
00170
00171 double time_till_seg_start;
00172 double duration;
00173 double actualpose;
00174 double actualvel;
00175
00176 };
00177
00178 }
00179 #endif