Go to the documentation of this file.00001 #ifndef WALKINGCLIENT_H
00002 #define WALKINGCLIENT_H
00003
00004 #include <ocra-icub/IcubClient.h>
00005 #include <ocra-recipes/TrajectoryThread.h>
00006 #include <ocra-recipes/ControllerClient.h>
00007 #include <ocra/util/EigenUtilities.h>
00008 #include "walking-client/ZmpPreviewController.h"
00009 #include "walking-client/StepController.h"
00010 #include "walking-client/utils.h"
00011 #include "walking-client/MIQPController.h"
00012 #include "walking-client/Interpolator.h"
00013 #include <ocra/util/FileOperations.h>
00014 #include <yarp/os/Time.h>
00015 #include "gurobi_c++.h"
00016 #include "Gurobi.h"
00017
00018 class WalkingClient : public ocra_recipes::ControllerClient
00019 {
00020 DEFINE_CLASS_POINTER_TYPEDEFS(WalkingClient)
00021
00022 public:
00023 WalkingClient (std::shared_ptr<ocra::Model> modelPtr, const int loopPeriod);
00024 virtual ~WalkingClient ();
00025
00049 bool configure(yarp::os::ResourceFinder &rf);
00050
00051
00055 void printHelp();
00056
00057
00068 bool queryMIQPSolution(const int miqpPeriod, const int miqpPreviewPeriod, const int clientPeriod, Eigen::VectorXd &preview, Eigen::VectorXd &tPreview);
00069
00077 bool readFootWrench(FOOT whichFoot, Eigen::VectorXd &rawWrench);
00078
00079 yarp::os::BufferedPort<yarp::sig::Vector> portWrenchLeftFoot;
00080
00081 yarp::os::BufferedPort<yarp::sig::Vector> portWrenchRightFoot;
00082
00095 std::vector<Eigen::Vector2d> generateZMPTrajectoryTEST(const double tTrans,
00096 const double feetSeparation,
00097 const double timeStep,
00098 const int amplitudeFraction,
00099 const int N);
00100
00108 bool getFeetSeparation(Eigen::Vector3d &sep);
00109
00119 bool publish3dQuantity(yarp::os::BufferedPort<yarp::os::Bottle> &port, Eigen::Vector3d &value);
00120
00127 void performZMPTest(ZmpTestType type);
00128
00129
00142 void performZMPPreviewTest(ZmpTestType type);
00143
00144 void performZMPPreviewTestIntCoM(ZmpTestType type);
00145
00146 void performMIQPTest();
00147
00148 void performSingleStepTest();
00149
00153 void steppingTest();
00154
00161 std::string composePortName(std::string portName);
00162
00163 void findZMPPreviewControllerParams(yarp::os::ResourceFinder &rf);
00164 void findGeneralTestsParams(yarp::os::ResourceFinder &rf);
00165 void findCOMLinVelConstRefParams(yarp::os::ResourceFinder &rf);
00166 void findZMPConstRefParams(yarp::os::ResourceFinder &rf);
00167 void findSingleStepTestParams(yarp::os::ResourceFinder &rf);
00168 void findZMPVaryingReferenceParams(yarp::os::ResourceFinder &rf);
00169 void findMIQPParams(yarp::os::ResourceFinder &rf);
00170 void findSteppingTestParams(yarp::os::ResourceFinder &rf);
00171
00180 void transformStdVectorToEigenVector(std::vector< Eigen::Vector2d >& fullTraj, int from, int Nc, VectorXd& output);
00181
00182
00193 std::vector< Eigen::Vector2d > generateZMPStepTrajectoryTEST(double feetSeparation, double period, double duration, double riseTime, double constantReferenceY);
00194
00195 std::vector<Eigen::Vector2d> generateZMPSingleStepTrajectory(double period, double feetSeparation);
00196
00200 void generateStepPattern();
00201
00205 std::vector<Eigen::Vector2d> generateZMPSteppingTrajectory();
00206
00210 void startSteppinMotherFucker(int &stepTrigger, double &error);
00211
00219 void prepareAndsetDesiredCoMTaskState(Eigen::VectorXd comState, bool doSet);
00220
00221
00222
00223 protected:
00227 virtual bool initialize();
00228 virtual void release();
00229 virtual void loop();
00230
00231 private:
00232
00233 std::vector<FOOT> _stepOrder;
00234 Eigen::MatrixXd _stepTargets;
00235 Eigen::VectorXd _stepTargetDurations;
00236 bool _currentlyStepping;
00237 bool _waitBeforeNextStep;
00238 double _waitTimeStart;
00239 int _currentStepIndex;
00240 std::vector<Eigen::Vector2d> _steppingTrajectory;
00241 steppingTestParams _steppingTestParams;
00242
00243
00244
00245 std::shared_ptr<ZmpPreviewParams> _zmpPreviewParams;
00246 std::shared_ptr<ZmpPreviewController> _zmpPreviewController;
00247 std::shared_ptr<ocra_recipes::TaskConnection> _comTask;
00248 std::shared_ptr<MIQPController> _miqpController;
00249 std::shared_ptr<StepController> _stepController;
00250 std::vector<Eigen::Vector2d> _zmpTrajectory;
00251 std::vector<Eigen::Vector2d> _singleStepTrajectory;
00252 ocra::TaskState _desiredComState;
00253 MIQPParameters _miqpParams;
00254 Eigen::VectorXd _rawLeftFootWrench;
00255 Eigen::VectorXd _rawRightFootWrench;
00256 Eigen::Vector2d _globalZMP;
00257 Eigen::Vector2d _previousCOM;
00258 Eigen::Vector2d _previousCOMVel;
00259 std::string _clientName;
00260 std::string _robot;
00261 int _period;
00262 bool _isTestRun;
00263 std::string _testType;
00264 ZmpTestType _zmpTestType;
00265 std::string _homeDataDir;
00266 double _comYConstVel;
00267 double _stopTimeConstComVel;
00268 double _zmpYConstRef;
00269 double _stopTimeConstZmp;
00270 double _riseTimeConstZmp;
00271 double _trajectoryDurationConstZmp;
00272 double _constantReferenceY;
00273 singleStepTestParams _singleStepTestParams;
00274 double _tTrans;
00275 int _numberOfTransitions;
00276 int _amplitudeFraction;
00277 double _stopTimeVaryingZmp;
00278 int _k;
00279
00280 yarp::os::BufferedPort<yarp::os::Bottle> _zmpPort;
00281 yarp::os::BufferedPort<yarp::os::Bottle> _dcomErrorPort;
00282 yarp::os::BufferedPort<yarp::os::Bottle> _dComDesPort;
00283 yarp::os::BufferedPort<yarp::os::Bottle> _dComCurPort;
00284 yarp::os::BufferedPort<yarp::os::Bottle> _zmpDesPort;
00285 yarp::os::BufferedPort<yarp::os::Bottle> _zmpCurPort;
00286 yarp::os::BufferedPort<yarp::os::Bottle> _comCurrent;
00287 yarp::os::BufferedPort<yarp::os::Bottle> _ddcomCurrent;
00288 yarp::os::BufferedPort<yarp::os::Bottle> _ddcomFromZMP;
00289 Eigen::VectorXd _hkkPrevious;
00290 bool _firstLoop;
00291 Eigen::VectorXd zmpRefInPreviewWindow;
00292 Eigen::VectorXd comVelRefInPreviewWindow;
00293 Eigen::VectorXd optimalU;
00294
00295
00296 Eigen::VectorXd _X_kn;
00297 Eigen::VectorXd _t_kn;
00298 };
00299
00300
00301 #endif // TEST_CLIENT_H