diff --git a/include/CMakeLists.txt b/include/CMakeLists.txt index b2e48559f69bb27e67bd23727cfbfc21a4f9ded3..66ca7facc5735df8861ee47460b5ff7cef725769 100644 --- a/include/CMakeLists.txt +++ b/include/CMakeLists.txt @@ -88,8 +88,14 @@ rotation-simple.h weighted-sot.h solver-hierarchical-inequalities.h -#reader +#traces reader.h + +#tools +periodic-call.h +utils-windows.h +time-stamp.h +timer.h ) # Recreate correct path for the headers diff --git a/include/sot-core/constraint.h b/include/sot-core/constraint.h index 8fd216d4e7d66b722d4a538da5bb1637b26dc509..ffb1c94f572947819ac6ab8554eecc4fce4aa38f 100644 --- a/include/sot-core/constraint.h +++ b/include/sot-core/constraint.h @@ -46,7 +46,7 @@ namespace ml = maal::boost; /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (Constraint_EXPORTS) +# if defined (constraint_EXPORTS) # define SOTCONSTRAINT_EXPORT __declspec(dllexport) # else # define SOTCONSTRAINT_EXPORT __declspec(dllimport) diff --git a/include/sot-core/contiifstream.h b/include/sot-core/contiifstream.h index 87246de54ded36b5c8da645dddcf985def28726a..67e57814bb0ea8c8cf7347a64ea7db76d0fdcf76 100644 --- a/include/sot-core/contiifstream.h +++ b/include/sot-core/contiifstream.h @@ -44,7 +44,7 @@ /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (Contiifstream_EXPORTS) +# if defined (contiifstream_EXPORTS) # define SOTCONTIIFSTREAM_EXPORT __declspec(dllexport) # else # define SOTCONTIIFSTREAM_EXPORT __declspec(dllimport) diff --git a/include/sot-core/feature-1d.h b/include/sot-core/feature-1d.h index 1d8e54b49f16b95494e1707ee23e296342358542..182af621b3dfabeb73cf85b10488d0ed400393c6 100644 --- a/include/sot-core/feature-1d.h +++ b/include/sot-core/feature-1d.h @@ -34,7 +34,7 @@ /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotFeature1D_EXPORTS) +# if defined (feature_1d_EXPORTS) # define SOTFEATURE1D_EXPORT __declspec(dllexport) # else # define SOTFEATURE1D_EXPORT __declspec(dllimport) diff --git a/include/sot-core/feature-generic.h b/include/sot-core/feature-generic.h index dde64b54bad063326bdcd45dec95bcaeaee1bae4..5753917f1eb9df7b4fe8cee5f137211b2c7a9e7b 100644 --- a/include/sot-core/feature-generic.h +++ b/include/sot-core/feature-generic.h @@ -34,7 +34,7 @@ /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotFeatureGeneric_EXPORTS) +# if defined (feature_generic_EXPORTS) # define SOTFEATUREGENERIC_EXPORT __declspec(dllexport) # else # define SOTFEATUREGENERIC_EXPORT __declspec(dllimport) diff --git a/include/sot-core/feature-joint-limits.h b/include/sot-core/feature-joint-limits.h index d9f589c3c78cc41280753109ef81033cbf74ab75..1424560fe6717b833368733c0ecd7cda44684ab7 100644 --- a/include/sot-core/feature-joint-limits.h +++ b/include/sot-core/feature-joint-limits.h @@ -34,7 +34,7 @@ /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotFeatureJointLimits_EXPORTS) +# if defined (feature_joint_limits_EXPORTS) # define SOTFEATUREJOINTLIMITS_EXPORT __declspec(dllexport) # else # define SOTFEATUREJOINTLIMITS_EXPORT __declspec(dllimport) diff --git a/include/sot-core/feature-line-distance.h b/include/sot-core/feature-line-distance.h index 9dee937e60e897e440c88597bf4c680e219cc1fb..2b324c133258398e4676b8e7673f731e3ecb2ade 100644 --- a/include/sot-core/feature-line-distance.h +++ b/include/sot-core/feature-line-distance.h @@ -35,7 +35,7 @@ /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotFeatureLineDistance_EXPORTS) +# if defined (feature_line_distance_EXPORTS) # define SOTFEATURELINEDISTANCE_EXPORT __declspec(dllexport) # else # define SOTFEATURELINEDISTANCE_EXPORT __declspec(dllimport) diff --git a/include/sot-core/feature-point6d-relative.h b/include/sot-core/feature-point6d-relative.h index 21d277d7b968e3197ef89d14e3d3fecfaa2353a0..faa5fba81dd0c8fab8a2c1522626c135db63d465 100644 --- a/include/sot-core/feature-point6d-relative.h +++ b/include/sot-core/feature-point6d-relative.h @@ -36,7 +36,7 @@ /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotFeaturePoint6dRelative_EXPORTS) +# if defined (feature_point_6d_relative_EXPORTS) # define SOTFEATUREPOINT6DRELATIVE_EXPORT __declspec(dllexport) # else # define SOTFEATUREPOINT6DRELATIVE_EXPORT __declspec(dllimport) diff --git a/include/sot-core/feature-point6d.h b/include/sot-core/feature-point6d.h index 4c4f46a6bb9b4cdb225ed9c39feed77a50c16b5a..97cfd6fa54d0079d65701c08f7ae88611286de97 100644 --- a/include/sot-core/feature-point6d.h +++ b/include/sot-core/feature-point6d.h @@ -35,7 +35,7 @@ /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotFeaturePoint6d_EXPORTS) +# if defined (feature_point_6d_EXPORTS) # define SOTFEATUREPOINT6D_EXPORT __declspec(dllexport) # else # define SOTFEATUREPOINT6D_EXPORT __declspec(dllimport) diff --git a/include/sot-core/feature-task.h b/include/sot-core/feature-task.h index f567ccd707a2f789b4fdfe2ddd239d0add9ac677..132a17cfe600f885033f52957ad5df822a009379 100644 --- a/include/sot-core/feature-task.h +++ b/include/sot-core/feature-task.h @@ -35,7 +35,7 @@ /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotFeatureTask_EXPORTS) +# if defined (feature_task_EXPORTS) # define SOTFEATURETASK_EXPORT __declspec(dllexport) # else # define SOTFEATURETASK_EXPORT __declspec(dllimport) diff --git a/include/sot-core/feature-vector3.h b/include/sot-core/feature-vector3.h index 87711b257ac5e19992713e84d16a9d765a2deb18..b72930fe746f10848c0c14f1bb4aea8ba01ffa14 100644 --- a/include/sot-core/feature-vector3.h +++ b/include/sot-core/feature-vector3.h @@ -35,7 +35,7 @@ /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotFeatureVector3_EXPORTS) +# if defined (feature_vector3_EXPORTS) # define SOTFEATUREVECTOR3_EXPORT __declspec(dllexport) # else # define SOTFEATUREVECTOR3_EXPORT __declspec(dllimport) diff --git a/include/sot-core/feature-visual-point.h b/include/sot-core/feature-visual-point.h index 5ebf6d983b320b47f9a436af2857a878a462a0d5..52c8b8c532795b4799291cce8d7ba9bccab8b60b 100644 --- a/include/sot-core/feature-visual-point.h +++ b/include/sot-core/feature-visual-point.h @@ -34,7 +34,7 @@ /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotFeatureVisualPoint_EXPORTS) +# if defined (feature_visual_point_EXPORTS) # define SOTFEATUREVISUALPOINT_EXPORT __declspec(dllexport) # else # define SOTFEATUREVISUALPOINT_EXPORT __declspec(dllimport) diff --git a/include/sot-core/gain-adaptive.h b/include/sot-core/gain-adaptive.h index 50e27df5671ca413a284b88e5dcecfd7dc250133..318929396d42167e1685bd67515baace02ffbd46 100644 --- a/include/sot-core/gain-adaptive.h +++ b/include/sot-core/gain-adaptive.h @@ -39,7 +39,7 @@ namespace ml = maal::boost; /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotGainAdaptive_EXPORTS) +# if defined (gain_adaptive_EXPORTS) # define SOTGAINADAPTATIVE_EXPORT __declspec(dllexport) # else # define SOTGAINADAPTATIVE_EXPORT __declspec(dllimport) diff --git a/include/sot-core/gain-hyperbolic.h b/include/sot-core/gain-hyperbolic.h index 80d7bb2a94f789b6b56157d3e8b66561def2f00c..433117968be2ca9dc292392714958568233dae3b 100644 --- a/include/sot-core/gain-hyperbolic.h +++ b/include/sot-core/gain-hyperbolic.h @@ -40,7 +40,7 @@ namespace ml = maal::boost; /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotGainHyperbolic_EXPORTS) +# if defined (gain_hyperbolic_EXPORTS) # define SOTGAINHYPERBOLIC_EXPORT __declspec(dllexport) # else # define SOTGAINHYPERBOLIC_EXPORT __declspec(dllimport) diff --git a/include/sot-core/import-default-paths.h b/include/sot-core/import-default-paths.h new file mode 100644 index 0000000000000000000000000000000000000000..d0495ae6ae2bd9f9266e503683fd45d28865c178 --- /dev/null +++ b/include/sot-core/import-default-paths.h @@ -0,0 +1,8 @@ +// -*- c++ -*- +#ifndef SOT_FACTORY_COMMAND_IMPORT_DEFAULT_PATHS_H +# define SOT_FACTORY_COMMAND_IMPORT_DEFAULT_PATHS_H + +/// Default script path as known by CMake at configure time. +# define SOT_IMPORT_DEFAULT_PATHS "/home/blue/sot-lib/script" + +#endif //! SOT_FACTORY_COMMAND_IMPORT_DEFAULT_PATHS_H diff --git a/include/sot-core/memory-task-sot.h b/include/sot-core/memory-task-sot.h index b46cece84918594a9e0b3ac166feeb281e1922d0..6a494ee10da3d5e2d2b3c85f614e85af24e8c96d 100644 --- a/include/sot-core/memory-task-sot.h +++ b/include/sot-core/memory-task-sot.h @@ -30,7 +30,7 @@ #ifndef SOTSOT_CORE_EXPORT # if defined (WIN32) -# if defined (sotSOT_CORE_EXPORTS) +# if defined (sot_core_EXPORTS) # define SOTSOT_CORE_EXPORT __declspec(dllexport) # else # define SOTSOT_CORE_EXPORT __declspec(dllimport) diff --git a/include/sot-core/op-point-modifier.h b/include/sot-core/op-point-modifier.h index 38a07b106f16d6d37b699b8ebe98e71246ad9faa..797ada488e310d688b8c58ed878f4d71f8cc3eb3 100644 --- a/include/sot-core/op-point-modifier.h +++ b/include/sot-core/op-point-modifier.h @@ -34,7 +34,7 @@ namespace ml = maal::boost; /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (OpPointModifier_EXPORTS) +# if defined (op_point_modifier_EXPORTS) # define SOTOPPOINTMODIFIER_EXPORT __declspec(dllexport) # else # define SOTOPPOINTMODIFIER_EXPORT __declspec(dllimport) diff --git a/include/sot-core/periodic-call.h b/include/sot-core/periodic-call.h new file mode 100644 index 0000000000000000000000000000000000000000..5c459ade3de6913b720b9ca8b9de76ba2761eb34 --- /dev/null +++ b/include/sot-core/periodic-call.h @@ -0,0 +1,94 @@ +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * Copyright Projet JRL-Japan, 2007 + *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * + * File: PeriodicCall.h + * Project: SOT + * Author: Nicolas Mansard + * + * Version control + * =============== + * + * $Id$ + * + * Description + * ============ + * + * + * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ + + +#ifndef __SOT_PERIODICCALL_HH__ +#define __SOT_PERIODICCALL_HH__ + +/* --------------------------------------------------------------------- */ +/* --- INCLUDE --------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + + +/* SOT */ +#include <dynamic-graph/signal-base.h> +#include <sot-core/sot-core-api.h> +/* STD */ +#include <list> +#include <map> +#include <string> + +/* --------------------------------------------------------------------- */ +/* --- CLASS ----------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + +namespace sot { + +/*! + \class PeriodicCall +*/ +class SOT_CORE_EXPORT PeriodicCall +{ + protected: + typedef std::map< std::string,dynamicgraph::SignalBase<int>* > SignalMapType; + SignalMapType signalMap; + + typedef std::list< std::string > CmdListType; + CmdListType cmdList; + + int innerTime; + + /* --- FUNCTIONS ------------------------------------------------------------ */ + public: + PeriodicCall( void ); + virtual ~PeriodicCall( void ) {} + + void addSignal( const std::string &name, dynamicgraph::SignalBase<int>& sig ); + void addSignal( std::istringstream& args ); + void rmSignal( const std::string &name ); + void rmSignal( std::istringstream& args ); + + void addCmd( std::istringstream& args ); + void rmCmd( std::istringstream& args ); + + void runSignals( const int& t ); + void runCmds( void ); + void run( const int& t ); + + void clear( void ) { signalMap.clear(); cmdList.clear(); } + + void display( std::ostream& os ) const; + bool commandLine( const std::string& cmdLine, + std::istringstream& cmdArgs, + std::ostream& os ); +}; + + + +} // namespace sot + + + +#endif // #ifndef __SOT_PERIODICCALL_HH__ + +/* + * Local variables: + * c-basic-offset: 2 + * End: + */ diff --git a/include/sot-core/reader.h b/include/sot-core/reader.h index fdf0db93965e498a2ea52f1e49d86dac7cfd62da..03260163c2224b9e04549d9dfd249151fac34a70 100644 --- a/include/sot-core/reader.h +++ b/include/sot-core/reader.h @@ -50,7 +50,7 @@ namespace ml = maal::boost; /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotReader_EXPORTS) +# if defined (reader_EXPORTS) # define SOTREADER_EXPORT __declspec(dllexport) # else # define SOTREADER_EXPORT __declspec(dllimport) diff --git a/include/sot-core/rotation-simple.h b/include/sot-core/rotation-simple.h index 92aa754df8a3d66c85ff4e3b4ce44c5bb35ece9e..023e717cb52ca52fa7e33213b0424f05aa02d877 100644 --- a/include/sot-core/rotation-simple.h +++ b/include/sot-core/rotation-simple.h @@ -18,7 +18,7 @@ #ifndef SOTSOTH_EXPORT # if defined (WIN32) -# if defined (sotSOTH_EXPORTS) +# if defined (sot_h_EXPORTS) # define SOTSOTH_EXPORT __declspec(dllexport) # else # define SOTSOTH_EXPORT __declspec(dllimport) diff --git a/include/sot-core/solver-hierarchical-inequalities.h b/include/sot-core/solver-hierarchical-inequalities.h index 3417c66efa6d4fa53bad9447cb200520efa5bf55..b141a88c5b5a1db8f7d32c238ffea235f5b53fed 100644 --- a/include/sot-core/solver-hierarchical-inequalities.h +++ b/include/sot-core/solver-hierarchical-inequalities.h @@ -39,7 +39,7 @@ #ifndef SOTSOTH_EXPORT # if defined (WIN32) -# if defined (sotSOTH_EXPORTS) +# if defined (sot_h_EXPORTS) # define SOTSOTH_EXPORT __declspec(dllexport) # else # define SOTSOTH_EXPORT __declspec(dllimport) diff --git a/include/sot-core/sot-h.h b/include/sot-core/sot-h.h index 69e36fcdd9f1945ef67edae7ddf8fed1f664763b..fc3957d5e67991b9370c817a33ed7144b8c90915 100644 --- a/include/sot-core/sot-h.h +++ b/include/sot-core/sot-h.h @@ -36,7 +36,7 @@ #ifndef SOTSOTH_EXPORT # if defined (WIN32) -# if defined (sotSOTH_EXPORTS) +# if defined (sot_h_EXPORTS) # define SOTSOTH_EXPORT __declspec(dllexport) # else # define SOTSOTH_EXPORT __declspec(dllimport) diff --git a/include/sot-core/sot-qr.h b/include/sot-core/sot-qr.h index 7cdba61c36466925e45f99bd8fcf5511d4e68bbf..52d025acd7fe437d28bc9d6b4f6c9bac98d3d170 100644 --- a/include/sot-core/sot-qr.h +++ b/include/sot-core/sot-qr.h @@ -44,7 +44,7 @@ namespace ml = maal::boost; /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotSOTQr_EXPORTS) +# if defined (sot_qr_EXPORTS) # define SOTSOTQR_EXPORT __declspec(dllexport) # else # define SOTSOTQR_EXPORT __declspec(dllimport) diff --git a/include/sot-core/sot.h b/include/sot-core/sot.h index 5abee9f2f687ca06b6eae75492e4100d7a0d2d46..f78c23c3ba80929781e26d786bf7481c6f26d93b 100644 --- a/include/sot-core/sot.h +++ b/include/sot-core/sot.h @@ -45,7 +45,7 @@ namespace ml = maal::boost; #ifndef SOTSOT_CORE_EXPORT # if defined (WIN32) -# if defined (sotSOT_CORE_EXPORTS) +# if defined (sot_EXPORTS) # define SOTSOT_CORE_EXPORT __declspec(dllexport) # else # define SOTSOT_CORE_EXPORT __declspec(dllimport) diff --git a/include/sot-core/task-conti.h b/include/sot-core/task-conti.h index b3e351bbb79cf164ff17c57e010011b29c6665f6..4c651df5f656c9bdd06571304a928d724bed234f 100644 --- a/include/sot-core/task-conti.h +++ b/include/sot-core/task-conti.h @@ -45,7 +45,7 @@ namespace ml = maal::boost; /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotTaskConti_EXPORTS) +# if defined (task_conti_EXPORTS) # define SOTTASKCONTI_EXPORT __declspec(dllexport) # else # define SOTTASKCONTI_EXPORT __declspec(dllimport) diff --git a/include/sot-core/task-pd.h b/include/sot-core/task-pd.h index 0eb2301d30345c6bf717cf8c4e2eb1db635bd4be..271703da20fd36399736de9655082eb08b712ef5 100644 --- a/include/sot-core/task-pd.h +++ b/include/sot-core/task-pd.h @@ -35,7 +35,7 @@ /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotTaskPD_EXPORTS) +# if defined (task_pd_EXPORTS) # define SOTTASKPD_EXPORT __declspec(dllexport) # else # define SOTTASKPD_EXPORT __declspec(dllimport) diff --git a/include/sot-core/task-unilateral.h b/include/sot-core/task-unilateral.h index 0d09ae82713c14c99072dc02cdc1509f94a6be2c..df5696cd6d1cbe4a99fed2102500175fa54d649e 100644 --- a/include/sot-core/task-unilateral.h +++ b/include/sot-core/task-unilateral.h @@ -47,7 +47,7 @@ namespace ml = maal::boost; /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotTaskUnilateral_EXPORTS) +# if defined (task_unilateral_EXPORTS) # define SOTTASKUNILATERAL_EXPORT __declspec(dllexport) # else # define SOTTASKUNILATERAL_EXPORT __declspec(dllimport) diff --git a/include/sot-core/task.h b/include/sot-core/task.h index 72f123f89b4b5a6ede2d169419978b87323fff7e..c348dc3bc92976dd4382cfccb78e95692a1d27a2 100644 --- a/include/sot-core/task.h +++ b/include/sot-core/task.h @@ -47,7 +47,7 @@ namespace ml = maal::boost; /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotTask_EXPORTS) +# if defined task_EXPORTS) # define SOTTASK_EXPORT __declspec(dllexport) # else # define SOTTASK_EXPORT __declspec(dllimport) diff --git a/include/sot-core/time-stamp.h b/include/sot-core/time-stamp.h new file mode 100644 index 0000000000000000000000000000000000000000..d9e349317cf08f0b83d4962d1ac1d0255c2b29c9 --- /dev/null +++ b/include/sot-core/time-stamp.h @@ -0,0 +1,117 @@ +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * Copyright Projet JRL-Japan, 2007 + *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * + * File: TimeStamp.h + * Project: SOT + * Author: Paul Evrard + * + * Version control + * =============== + * + * $Id$ + * + * Description + * ============ + * + * + * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ + + + +#ifndef __SOT_TIME_STAMP__HH +#define __SOT_TIME_STAMP__HH + +/* --------------------------------------------------------------------- */ +/* --- INCLUDE --------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + + +/* Matrix */ +#include <MatrixAbstractLayer/boost.h> +namespace ml = maal::boost; + +/* Classes standards. */ +#ifndef WIN32 +#include <sys/time.h> +#else /*WIN32*/ +#include <Winsock2.h> +#include <sot/utils-windows.h> +#endif /*WIN32*/ + +/* SOT */ +#include <dynamic-graph/entity.h> +#include <dynamic-graph/all-signals.h> +#include <sot-core/debug.h> + +/* --------------------------------------------------------------------- */ +/* --- API ------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + +#if defined (WIN32) +# if defined (TimeStamp_EXPORTS) +# define TimeStamp_EXPORT __declspec(dllexport) +# else +# define TimeStamp_EXPORT __declspec(dllimport) +# endif +#else +# define TimeStamp_EXPORT +#endif + +/* --------------------------------------------------------------------- */ +/* --- CLASS ----------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + +namespace sot { +namespace dg = dynamicgraph; + +class TimeStamp_EXPORT TimeStamp +:public dg::Entity +{ + public: + static const std::string CLASS_NAME; + virtual const std::string& getClassName( void ) const { return CLASS_NAME; } + + protected: + + struct timeval val; + unsigned int offsetValue; + bool offsetSet; + + public: + + /* --- CONSTRUCTION --- */ + TimeStamp( const std::string& name ); + + public: /* --- DISPLAY --- */ + virtual void display( std::ostream& os ) const; + + public: /* --- SIGNALS --- */ + + /* These signals can be called several time per period, given + * each time a different results. Useful for chronos. */ + dg::Signal<ml::Vector,int> timeSOUT; + dg::Signal<double,int> timeDoubleSOUT; + + /* These signals can be called several time per period, but give + * always the same results different results. Useful for synchro. */ + dg::SignalTimeDependent<ml::Vector,int> timeOnceSOUT; + dg::SignalTimeDependent<double,int> timeOnceDoubleSOUT; + + + protected: /* --- SIGNAL FUNCTIONS --- */ + ml::Vector& getTimeStamp( ml::Vector& res,const int& time ); + double& getTimeStampDouble( const ml::Vector& vect,double& res ); + + public: /* --- COMMANDS --- */ + virtual void commandLine( const std::string& cmdLine, + std::istringstream& cmdArgs, + std::ostream& os ); + +}; + + +} // namespace sot + + +#endif /* #ifndef __SOT_SOT_HH */ diff --git a/include/sot-core/timer.h b/include/sot-core/timer.h new file mode 100644 index 0000000000000000000000000000000000000000..bb79fc9e6dd99ad1164d2ea3e569f61a56cfe8ba --- /dev/null +++ b/include/sot-core/timer.h @@ -0,0 +1,198 @@ +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * Copyright Projet JRL-Japan, 2007 + *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * + * File: Timer.h + * Project: SOT + * Author: Nicolas Mansard + * + * Version control + * =============== + * + * $Id$ + * + * Description + * ============ + * + * + * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ + + + +#ifndef __SOT_TIMER_HH +#define __SOT_TIMER_HH + +/* --------------------------------------------------------------------- */ +/* --- INCLUDE --------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + +/* Classes standards. */ +#include <list> /* Classe std::list */ +#ifndef WIN32 +#include <sys/time.h> +#else /*WIN32*/ +// When including Winsock2.h, the MAL must be included first +#include <MatrixAbstractLayer/boost.h> +#include <sot-core/utils-windows.h> +#include <Winsock2.h> +#endif /*WIN32*/ + +/* SOT */ +#include <dynamic-graph/entity.h> +#include <dynamic-graph/all-signals.h> +#include <sot-core/debug.h> +#include <dynamic-graph/interpreter.h> + +/* --------------------------------------------------------------------- */ +/* --- API ------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + +#if defined (WIN32) +# if defined (timer_EXPORTS) +# define Timer_EXPORT __declspec(dllexport) +# else +# define Timer_EXPORT __declspec(dllimport) +# endif +#else +# define Timer_EXPORT +#endif + +/* --------------------------------------------------------------------- */ +/* --- CLASS ----------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ +namespace dg = dynamicgraph; + +template< class T > +class Timer_EXPORT Timer +:public dg::Entity +{ + public: + static const std::string CLASS_NAME; + virtual const std::string& getClassName( void ) const { return CLASS_NAME; } + + protected: + + struct timeval t0,t1; + double dt; + + public: + + /* --- CONSTRUCTION --- */ + Timer( const std::string& name ); + + public: /* --- DISPLAY --- */ + virtual void display( std::ostream& os ) const; + Timer_EXPORT friend std::ostream& operator<< ( std::ostream& os,const Timer<T>& timer ) + { timer.display(os); return os; } + + public: /* --- SIGNALS --- */ + + dg::SignalPtr<T,int> sigSIN; + dg::SignalTimeDependent<T,int> sigSOUT; + dg::Signal<double,int> timerSOUT; + + + protected: /* --- SIGNAL FUNCTIONS --- */ + void plug( dg::Signal<T,int> &sig ) + { + sigSIN = &sig; dt=0.; + } + + T& compute( T& t,const int& time ) + { + sotDEBUGIN(15); + gettimeofday(&t0,NULL); + sotDEBUG(15) << "t0: "<< t0.tv_sec << " - " << t0.tv_usec << std::endl; + + t = sigSIN( time ); + + gettimeofday(&t1,NULL); + dt = ( (t1.tv_sec-t0.tv_sec) * 1000. + + (t1.tv_usec-t0.tv_usec+0.) / 1000. ); + sotDEBUG(15) << "t1: "<< t1.tv_sec << " - " << t1.tv_usec << std::endl; + + timerSOUT = dt; + + sotDEBUGOUT(15); + return t; + } + + double& getDt( double& res,const int& time ) + { + res=dt; + return res; + } + + + public: /* --- COMMANDS --- */ + virtual void commandLine( const std::string& cmdLine,std::istringstream& cmdArgs, + std::ostream& os ); + + +}; + +void cmdChrono( const std::string& cmd, + std::istringstream& args, + std::ostream& os ); + + + +/* --------------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + + +/* --- CONSTRUCTION ---------------------------------------------------- */ +template< class T > +Timer<T>:: +Timer( const std::string& name ) + :Entity(name) + ,t0(),t1() + ,dt(0.) + ,sigSIN( NULL,"Timer("+name+")::output(T)::in" ) + ,sigSOUT( boost::bind(&Timer::compute,this,_1,_2), + sigSIN, + "Timer("+name+")::output(T)::out" ) + ,timerSOUT( "Timer("+name+")::output(double)::timer" ) +{ + sotDEBUGIN(15); + timerSOUT.setFunction( boost::bind(&Timer::getDt,this,_1,_2) ); + + signalRegistration( sigSIN<<sigSOUT<<timerSOUT ); + sotDEBUGOUT(15); +} + +/* --- DISPLAY --------------------------------------------------------- */ +template< class T > +void Timer<T>:: +display( std::ostream& os ) const +{ + os << "Timer <"<< sigSIN << "> : " << dt << "ms." << std::endl; +} +/* --- COMMAND --------------------------------------------------------- */ +template< class T > +void Timer<T>:: +commandLine( const std::string& cmdLine,std::istringstream& cmdArgs, + std::ostream& os ) +{ + sotDEBUGIN(15); + + if( cmdLine == "help") + { + os << "Timer: "<<std::endl; + Entity::commandLine( cmdLine,cmdArgs,os ); + } + else + Entity::commandLine( cmdLine,cmdArgs,os ); + + + sotDEBUGOUT(15); +} + + + +#endif /* #ifndef __SOT_SOT_HH */ + + + + diff --git a/include/sot-core/utils-windows.h b/include/sot-core/utils-windows.h index 7a70dbafa6119e8414b2bf70d3b8d604e9f180ef..8f55e8ced0bec3bb9be21ddf2d3a93e76b2ad3b9 100644 --- a/include/sot-core/utils-windows.h +++ b/include/sot-core/utils-windows.h @@ -14,13 +14,13 @@ #include < time.h > -struct SOT_EXPORT timezone +struct SOT_CORE_EXPORT timezone { int tz_minuteswest; /* minutes W of Greenwich */ int tz_dsttime; /* type of dst correction */ }; -int SOT_EXPORT gettimeofday(struct timeval *tv, struct timezone *tz); +int SOT_CORE_EXPORT gettimeofday(struct timeval *tv, struct timezone *tz); #endif /*WIN32*/ diff --git a/include/sot-core/weighted-sot.h b/include/sot-core/weighted-sot.h index 016f3222ca8998bb5aef1a71b9e357f12ff3aef6..e1a298be5452b5daf50f95a31ce5cb26b50f6ddb 100644 --- a/include/sot-core/weighted-sot.h +++ b/include/sot-core/weighted-sot.h @@ -41,7 +41,7 @@ namespace ml = maal::boost; /* --------------------------------------------------------------------- */ #if defined (WIN32) -# if defined (sotWeightedSOT_CORE_EXPORTS) +# if defined (weighted_sot_EXPORTS) # define SOTWEIGHTEDSOT_CORE_EXPORT __declspec(dllexport) # else # define SOTWEIGHTEDSOT_CORE_EXPORT __declspec(dllimport) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index af8fc920c0663d2da363e1e381e08add62b0e821..3f5117840fab329114187fcc6b544cbd4f73310b 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -82,6 +82,11 @@ SET(plugins feature/feature-line-distance traces/reader + + tools/utils-windows + tools/periodic-call + tools/time-stamp + tools//timer ) #Build sot-core diff --git a/src/tools/periodic-call.cpp b/src/tools/periodic-call.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dc180f172b4b8f930e66294eb1a4b714093cf8b1 --- /dev/null +++ b/src/tools/periodic-call.cpp @@ -0,0 +1,243 @@ +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * Copyright Projet JRL-Japan, 2007 + *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * + * File: PeriodicCall.cpp + * Project: SOT + * Author: Nicolas Mansard + * + * Version control + * =============== + * + * $Id$ + * + * Description + * ============ + * + * + * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ + + +/* --------------------------------------------------------------------- */ +/* --- INCLUDE --------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + +/* --- SOT --- */ +#include <sot-core/periodic-call.h> +#include <dynamic-graph/pool.h> +#include <dynamic-graph/interpreter.h> +#include <sot-core/debug.h> + +using namespace std; +using namespace dynamicgraph; +using namespace sot; + +/* --------------------------------------------------------------------- */ +/* --- CLASS ----------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + + + +PeriodicCall:: +PeriodicCall( void ) + : signalMap() + ,cmdList() + ,innerTime( 0 ) +{ + +} + + +/* --------------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ +void PeriodicCall:: +addSignal( const std::string &name, SignalBase<int>& sig ) +{ + signalMap[ name ] = &sig; + return ; +} + +void PeriodicCall:: +addSignal( istringstream& args ) +{ + string signalName; args >> signalName; + istringstream sigISS( signalName ); + SignalBase<int>& signal = g_pool .getSignal( sigISS ); + addSignal( signalName,signal ); + return ; +} + +void PeriodicCall:: +rmSignal( const std::string &name ) +{ + signalMap.erase( name ); + return ; +} + +void PeriodicCall:: +rmSignal( istringstream& args ) +{ + string signalName; args >> signalName; + rmSignal( signalName ); + return ; +} + + + +/* --------------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ +void PeriodicCall:: +addCmd( istringstream& args ) +{ + stringbuf* pbuf=args.rdbuf(); + const unsigned int size = pbuf->in_avail(); + char *buffer = new char[ size+1 ]; + pbuf->sgetn( buffer,size ); + + buffer[size]='\0'; + cmdList.push_back( buffer ); + + delete buffer; + return ; +} + +void PeriodicCall:: +rmCmd( istringstream& args ) +{ + stringbuf* pbuf=args.rdbuf(); + const unsigned int size = pbuf->in_avail(); + char * buffer = new char [size+1]; + pbuf->sgetn( buffer,size ); + buffer[size]='\0'; + + CmdListType::iterator iter = cmdList.begin(); + while( cmdList.end()!=iter ) + { + const string& str = *iter; + if( 0==str.compare( 0,size,buffer ) ) + { iter = cmdList.erase( iter ); } + else { ++iter; } + //cout<<str << " <=> " << buffer << ": " << str.compare( 0,size,buffer )<<endl; + } + + delete buffer; + return ; +} + + + +/* --------------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ +void PeriodicCall:: +runSignals( const int& t ) +{ + for( SignalMapType::iterator iter = signalMap.begin(); + signalMap.end()!=iter; ++iter ) + { + (*iter).second ->recompute( t ); + } + return ; +} + +void PeriodicCall:: +runCmds( void ) +{ + ostringstream onull; onull.clear( ios::failbit ); + + for( CmdListType::const_iterator iter = cmdList.begin(); + cmdList.end()!=iter; ++iter ) + { + istringstream iss( *iter ); + string cmdName; iss >> cmdName; + g_shell.cmd( cmdName,iss,onull ); + } + return ; +} + + void PeriodicCall:: +run( const int & t ) +{ + runSignals( t ); runCmds(); + return ; +} + +/* --------------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + + +void PeriodicCall:: +display( std::ostream& os ) const +{ + + + os <<" (t=" << innerTime << ")" <<endl; + + os<<" -> SIGNALS:"<<endl; + for( SignalMapType::const_iterator iter = signalMap.begin(); + signalMap.end()!=iter; ++iter ) + { + os << " - " << (*iter).first << endl; + } + + os<<" -> CMDS:"<<endl; + for( CmdListType::const_iterator iter = cmdList.begin(); + cmdList.end()!=iter; ++iter ) + { + os << " - " << (*iter) << endl; + } + +} + + + + +bool PeriodicCall:: +commandLine( const std::string& cmdLine, + std::istringstream& cmdArgs, + std::ostream& os ) +{ + if( cmdLine == "help" ) + { + os << "PeriodicCall:"<<endl + <<" - addSignal/rmSignal <int> " <<endl + <<" - addCmd/rmCmd " <<endl + <<" - runSignal/runCmd " <<endl + <<" - run" <<endl + <<" - setTime t " << endl; + } + else if( cmdLine == "addSignal" ) + { addSignal( cmdArgs ); } + else if( cmdLine == "rmSignal" ) + { rmSignal( cmdArgs ); } + else if( cmdLine == "runSignals" ) + { runSignals( innerTime++ ); } + + else if( cmdLine == "addCmd" ) + { addCmd( cmdArgs ); } + else if( cmdLine == "rmCmd" ) + { rmCmd( cmdArgs ); } + else if( cmdLine == "runCmds" ) + { runCmds(); } + + else if( cmdLine == "run" ) + { run( innerTime++ ); } + else if( cmdLine == "clear" ) + { clear(); } + else if( cmdLine == "print" ) + { display(os) ; } + else { return false; } + return true; +} + + + +/* + * Local variables: + * c-basic-offset: 2 + * End: + */ + diff --git a/src/tools/time-stamp.cpp b/src/tools/time-stamp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9dd5bccd1e4775d0c44fa67b92a93e96c80a7ab6 --- /dev/null +++ b/src/tools/time-stamp.cpp @@ -0,0 +1,142 @@ +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * Copyright Projet JRL-Japan, 2007 + *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * + * File: TimeStamp.cpp + * Project: SOT + * Author: Paul Evrard + * + * Version control + * =============== + * + * $Id$ + * + * Description + * ============ + * + * + * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ + + +/* --------------------------------------------------------------------- */ +/* --- INCLUDE --------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + +/* SOT */ +#include <sot-core/time-stamp.h> +#include <sot-core/matrix-homogeneous.h> +#include <dynamic-graph/factory.h> +#include <sot-core/macros-signal.h> + +/* --------------------------------------------------------------------- */ +/* --- CLASS ----------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + +using namespace dynamicgraph; +using namespace sot; + +DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(TimeStamp,"TimeStamp"); + + +/* --- CONSTRUCTION ---------------------------------------------------- */ +TimeStamp:: +TimeStamp( const std::string& name ) + :Entity(name) + ,offsetValue( 0 ),offsetSet(false) + ,timeSOUT( "TimeStamp("+name+")::output(vector2)::time" ) + ,timeDoubleSOUT( "TimeStamp("+name+")::output(double)::timeDouble" ) + ,timeOnceSOUT( boost::bind(&TimeStamp::getTimeStamp,this,_1,_2), + sotNOSIGNAL, + "TimeStamp("+name+")::output(vector2)::synchro" ) + ,timeOnceDoubleSOUT( boost::bind(&TimeStamp::getTimeStampDouble,this, + SOT_CALL_SIG(timeSOUT,ml::Vector),_1), + timeSOUT, + "TimeStamp("+name+")::output(double)::synchroDouble" ) +{ + sotDEBUGIN(15); + + timeSOUT.setFunction( boost::bind(&TimeStamp::getTimeStamp,this,_1,_2) ); + timeDoubleSOUT.setFunction( boost::bind(&TimeStamp::getTimeStampDouble,this, + SOT_CALL_SIG(timeSOUT,ml::Vector),_1) ); + timeOnceSOUT.setNeedUpdateFromAllChildren( true ); + timeOnceDoubleSOUT.setNeedUpdateFromAllChildren( true ); + signalRegistration( timeSOUT << timeDoubleSOUT + << timeOnceSOUT << timeOnceDoubleSOUT ); + + gettimeofday( &val,NULL ); + + sotDEBUGOUT(15); +} + +/* --- DISPLAY --------------------------------------------------------- */ +void TimeStamp:: +display( std::ostream& os ) const +{ + os << "TimeStamp <> : " << val.tv_sec << "s; " + << val.tv_usec << "us." << std::endl; +} + +/* --------------------------------------------------------------------- */ +/* --- CONTROL --------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + +ml::Vector& TimeStamp:: +getTimeStamp( ml::Vector& res,const int& time ) +{ + sotDEBUGIN(15); + gettimeofday( &val,NULL ); + if( res.size()!=2 ) res.resize(2); + + + res(0) = val.tv_sec; + res(1) = val.tv_usec; + sotDEBUGOUT(15); + return res; +} + +double& TimeStamp:: +getTimeStampDouble( const ml::Vector& vect,double& res ) +{ + sotDEBUGIN(15); + + if( offsetSet ) res = (vect(0)-offsetValue)*1000; + else res = vect(0)*1000; + res += vect(1)/1000; + sotDEBUGOUT(15); + return res; +} + + +void TimeStamp:: +commandLine( const std::string& cmdLine, + std::istringstream& cmdArgs, + std::ostream& os ) +{ + if( cmdLine=="help" ) + { + os << "TimeStamp: "<<std::endl + << " - offset [{<value>|now}] : set/get the offset for double sig." << std::endl; + Entity::commandLine( cmdLine,cmdArgs,os ); + } + else if( cmdLine=="offset" ) + { + cmdArgs >> std::ws; + if( cmdArgs.good() ) + { + std::string offnow; + cmdArgs >> offnow; + if(offnow=="now") + { + gettimeofday( &val,NULL ); + offsetValue = val.tv_sec; + } + else { offsetValue = atoi(offnow.c_str()); } + offsetSet = ( offsetValue>0 ); + } else { + os << "offset = " << (offsetSet ? offsetValue : 0) << std::endl; + } + } + else { Entity::commandLine( cmdLine,cmdArgs,os ); } +} + + diff --git a/src/tools/timer.cpp b/src/tools/timer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2e4e23bacf884c25c577e7d016c01e7773bc4db4 --- /dev/null +++ b/src/tools/timer.cpp @@ -0,0 +1,103 @@ +/*+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * Copyright Projet JRL-Japan, 2007 + *+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ + * + * File: Timer.cpp + * Project: SOT + * Author: Nicolas Mansard + * + * Version control + * =============== + * + * $Id$ + * + * Description + * ============ + * + * + * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++*/ + + +/* --------------------------------------------------------------------- */ +/* --- INCLUDE --------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + +/* SOT */ +#include <sot-core/timer.h> +#include <MatrixAbstractLayer/boost.h> +#include <sot-core/matrix-homogeneous.h> +#include <sot-core/factory.h> + +using namespace sot; +using namespace dynamicgraph; + +/* --------------------------------------------------------------------- */ +/* --- CLASS ----------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + +typedef Timer<maal::boost::Vector> timevect; +template <> +DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(timevect,"Timer<Vector>"); + +typedef Timer<maal::boost::Matrix> timematrix; +template <> +DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(timematrix,"Timer<Matrix>"); + +typedef Timer<MatrixHomogeneous> timematrixhomo; +template <> +DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(timematrixhomo,"Timer<MatrixHomo>"); + +typedef Timer<double> timedouble; +template <> +DYNAMICGRAPH_FACTORY_ENTITY_PLUGIN(timedouble,"Timer<double>"); + + +/* --------------------------------------------------------------------- */ +void +cmdChrono( const std::string& cmdLine, + std::istringstream& cmdArg, + std::ostream& os ) +{ + sotDEBUGIN(15); + + if( cmdLine == "help" ) + { + os << " - chrono <cmd...>" + << "\t\t\t\tLaunch <cmd> and display the time spent in the operation." <<std::endl; + return; + } + + struct timeval t0,t1; + double dt; + + gettimeofday(&t0,NULL); + sotDEBUG(15) << "t0: "<< t0.tv_sec << " - " << t0.tv_usec << std::endl; + + std::string cmdLine2; cmdArg>>cmdLine2; + sotDEBUG(5)<<"Chrono <" <<cmdLine2<<">"<<std::endl; + g_shell.cmd(cmdLine2,cmdArg,os); + + gettimeofday(&t1,NULL); + dt = ( (t1.tv_sec-t0.tv_sec) * 1000. + + (t1.tv_usec-t0.tv_usec+0.) / 1000. ); + sotDEBUG(15) << "t1: "<< t1.tv_sec << " - " << t1.tv_usec << std::endl; + + os << "Time spent = " << dt << " ms " << std::endl; + + sotDEBUGOUT(15); +} + + + +extern "C" { + ShellFunctionRegisterer regTimer1 + ( "chrono",boost::bind(cmdChrono,_1,_2,_3) ); +} + + +/* --------------------------------------------------------------------- */ +/* --- CONTROL --------------------------------------------------------- */ +/* --------------------------------------------------------------------- */ + + + diff --git a/src/tools/utils-windows.cpp b/src/tools/utils-windows.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0969626229feaafdb5c9b34bed2fce6afee2447d --- /dev/null +++ b/src/tools/utils-windows.cpp @@ -0,0 +1,46 @@ +#ifdef WIN32 +#include <sot-core/utils-windows.h> + +#include < Windows.h > +#if defined(_MSC_VER) || defined(_MSC_EXTENSIONS) +#define DELTA_EPOCH_IN_MICROSECS 11644473600000000Ui64 +#else +#define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL +#endif + +int gettimeofday(struct timeval *tv, struct timezone *tz) +{ + FILETIME ft; + unsigned __int64 tmpres = 0; + static int tzflag; + + if (NULL != tv) + { + GetSystemTimeAsFileTime(&ft); + + tmpres |= ft.dwHighDateTime; + tmpres <<= 32; + tmpres |= ft.dwLowDateTime; + + /*converting file time to unix epoch*/ + tmpres /= 10; /*convert into microseconds*/ + tmpres -= DELTA_EPOCH_IN_MICROSECS; + tv->tv_sec = (long)(tmpres / 1000000UL); + tv->tv_usec = (long)(tmpres % 1000000UL); + } + + if (NULL != tz) + { + if (!tzflag) + { + _tzset(); + tzflag++; + } + tz->tz_minuteswest = _timezone / 60; + tz->tz_dsttime = _daylight; + } + + return 0; +} + +#endif /*WIN32*/