Calibrator.hpp
Go to the documentation of this file.
00001 /*
00002  * Calibrator.hpp
00003  *
00004  *  Created on: Feb 8, 2012
00005  *      Author: mriedel
00006  */
00007 
00008 #ifndef CALIBRATOR_HPP_
00009 #define CALIBRATOR_HPP_
00010 
00011 #include <telekyb_defines/telekyb_defines.hpp>
00012 #include <tk_behavior/Behavior.hpp>
00013 
00014 //#include <telekyb_base/Spaces/Angle.hpp>
00015 
00016 // plugin stuff
00017 #include <pluginlib/class_list_macros.h>
00018 
00019 // sensormsgs
00020 //#include <sensor_msgs/Joy.h>
00021 
00022 #include <telekyb_base/Time.hpp>
00023 
00024 #include <telekyb_interface/MKInterface.hpp>
00025 #include <boost/thread.hpp>
00026 
00027 // to calculate median
00028 #include <boost/accumulators/accumulators.hpp>
00029 #include <boost/accumulators/statistics/stats.hpp>
00030 #include <boost/accumulators/statistics/median.hpp>
00031 
00032 using namespace TELEKYB_NAMESPACE;
00033 using namespace boost::accumulators;
00034 
00035 namespace telekyb_behavior {
00036 
00037 class Calibrator : public Behavior {
00038 protected:
00039         // Option references
00040         Option<bool>* tDoMassEstimation;
00041         bool tDoMassEstimationSave;
00042         Option<double>* tPCIntegralGain;
00043         double tPCIntegralGainSave;
00044 
00045         // turn active conditions
00046         Option<double>* tMaxInitialVelocity;
00047         Option<double>* tMaxInitialYawError;
00048 
00049         Option<double>* tSettleTime;
00050         Option<int>* tValueRange;
00051         Option<int>* tCenterValueX;
00052         Option<int>* tCenterValueY;
00053 
00054         // Error Matrix
00055         Eigen::MatrixXd errorMatrix;
00056 
00057         // current Field
00058         Eigen::Vector2i currentField;
00059         // this is the actual field to test.
00060         //Eigen::Vector2d currentTestField;
00061 
00062         // 9 cases (0-9. mod -> row, div -> col);
00063         //int currentTestOffset;
00064 
00065         // Test Variables
00066         bool initialSetup;
00067         //double maxErrorTest;
00068         //double meanErrorTest;
00069         //Eigen::Vector2d meanErrorVector;
00070         //int meanNrSamples;
00071 
00072         // Position to hold
00073         Position3D calibrationPosition;
00074 
00075         // Timers
00076         Timer testTimer;
00077         Timer behaviorActiveTimer;
00078 
00079         Timer transitionTimer;
00080 
00081         // ROS
00082         ros::NodeHandle nodeHandle;
00083 
00084         // MKInterface to directly communicate with the QC.
00085         telekyb_interface::MKInterface* mkInterface;
00086         MKSingleValuePacket offsetRawAcc_X;
00087         MKSingleValuePacket offsetRawAcc_Y;
00088 
00089         bool valuesSet;
00090         bool setValueThreadDone;
00091 
00092         double jumpConstant;
00093 
00094         // Set Value Thread!
00095         boost::thread setValueThread;
00096         //boost::posix_time::time_duration timeout = boost::posix_time::milliseconds(500);
00097 
00098         accumulator_set<double, stats<tag::median > > acc;
00099 
00100         accumulator_set<double, stats<tag::median > > accMedianX;
00101         accumulator_set<double, stats<tag::median > > accMedianY;
00102 
00103         bool calibrationDone;
00104 
00105 public:
00106         Calibrator();
00107 
00108         virtual void initialize();
00109         virtual void destroy();
00110 
00111         // Called directly after Change Event is registered.
00112         virtual bool willBecomeActive(const TKState& currentState, const Behavior& previousBehavior);
00113         // Called after actual Switch. Note: During execution trajectoryStepCreation is used
00114         virtual void didBecomeActive(const TKState& currentState, const Behavior& previousBehavior);
00115         // Called directly after Change Event is registered: During execution trajectoryStepTermination is used
00116         virtual void willBecomeInActive(const TKState& currentState, const Behavior& nextBehavior);
00117         // Called after actual Switch. Runs in seperate Thread.
00118         virtual void didBecomeInActive(const TKState& currentState, const Behavior& nextBehavior);
00119 
00120         // called everytime a new TKState is available AND it is the NEW Behavior of an active Switch
00121         virtual void trajectoryStepCreation(const TKState& currentState, TKTrajectory& generatedTrajInput);
00122 
00123         // called everytime a new TKState is available. Should return false if invalid (swtich to next behavior, or Hover if undef).
00124         virtual void trajectoryStepActive(const TKState& currentState, TKTrajectory& generatedTrajInput);
00125 
00126         // called everytime a new TKState is available AND it is the OLD Behavior of an active Switch
00127         virtual void trajectoryStepTermination(const TKState& currentState, TKTrajectory& generatedTrajInput);
00128 
00129         // Return true if the active Behavior is (still) valid. Initiate Switch otherwise
00130         virtual bool isValid(const TKState& currentState) const;
00131 
00132         // Threaded SetValue
00133         void setValueThreadFunc();
00134 
00135 };
00136 
00137 }
00138 
00139 #endif /* CALIBRATOR_HPP_ */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends Defines


tk_mk_tools
Author(s): Martin Riedel
autogenerated on Thu Apr 25 2013 11:16:03