imu_offset_compensation.hh 4.59 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/*
 * Copyright 2017, Andrea Del Prete, LAAS-CNRS
 *
 * This file is part of sot-torque-control.
 * sot-torque-control is free software: you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public License
 * as published by the Free Software Foundation, either version 3 of
 * the License, or (at your option) any later version.
 * sot-torque-control is distributed in the hope that it will be
 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.  You should
 * have received a copy of the GNU Lesser General Public License along
 * with sot-torque-control.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef __sot_torque_control_imu_offset_compensation_H__
#define __sot_torque_control_imu_offset_compensation_H__

/* --------------------------------------------------------------------- */
/* --- API ------------------------------------------------------------- */
/* --------------------------------------------------------------------- */

#if defined (WIN32)
#  if defined (imu_offset_compensation_EXPORTS)
#    define SOTIMUOFFSETCOMPENSATION_EXPORT __declspec(dllexport)
#  else
#    define SOTIMUOFFSETCOMPENSATION_EXPORT __declspec(dllimport)
#  endif
#else
#  define SOTIMUOFFSETCOMPENSATION_EXPORT
#endif


/* --------------------------------------------------------------------- */
/* --- INCLUDE --------------------------------------------------------- */
/* --------------------------------------------------------------------- */

#include <map>
#include "boost/assign.hpp"

42
43
44
45
46
47
#include <dynamic-graph/signal-helper.h>
#include <sot/core/matrix-geometry.hh>
#include <sot/core/robot-utils.hh>
#include <sot/torque_control/utils/vector-conversions.hh>


48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
namespace dynamicgraph {
  namespace sot {
    namespace torque_control {

      /* --------------------------------------------------------------------- */
      /* --- CLASS ----------------------------------------------------------- */
      /* --------------------------------------------------------------------- */

      class SOTIMUOFFSETCOMPENSATION_EXPORT ImuOffsetCompensation
          :public::dynamicgraph::Entity
      {
        typedef ImuOffsetCompensation EntityClassName;
        DYNAMIC_GRAPH_ENTITY_DECL();
        typedef Eigen::Vector3d Vector3;

      public:
        EIGEN_MAKE_ALIGNED_OPERATOR_NEW

        /* --- CONSTRUCTOR ---- */
        ImuOffsetCompensation( const std::string & name );

        /* --- COMMANDS --- */
        void init(const double& dt);
        void update_offset(const double & duration);
72
        void setGyroDCBlockerParameter(const double & alpha);
73
74
75
76
77
78
79
80
81
        /* --- SIGNALS --- */
        DECLARE_SIGNAL_IN(accelerometer_in,          dynamicgraph::Vector);  /// raw accelerometer data
        DECLARE_SIGNAL_IN(gyrometer_in,              dynamicgraph::Vector);  /// raw gyrometer data
        DECLARE_SIGNAL_OUT(accelerometer_out,        dynamicgraph::Vector);  /// compensated accelerometer data
        DECLARE_SIGNAL_OUT(gyrometer_out,            dynamicgraph::Vector);  /// compensated gyrometer data

      protected:
        /* --- ENTITY INHERITANCE --- */
        virtual void display( std::ostream& os ) const;
Guilhem Saurel's avatar
Guilhem Saurel committed
82

83
84
85
86
        /* --- METHODS --- */
        void update_offset_impl(int iter);
        void sendMsg(const std::string& msg, MsgType t=MSG_TYPE_INFO, const char* file="", int line=0)
        {
87
	  Entity::sendMsg("[ImuOffsetCompensation-"+name+"] "+msg, t, file, line);
88
89
90
91
92
93
94
        }

      protected:
        bool            m_initSucceeded;      /// true if the entity has been successfully initialized
        float           m_dt;		      /// sampling time in seconds
        int             m_update_cycles_left; /// number of update cycles left
        int             m_update_cycles;      /// total number of update cycles to perform
95
        double          m_a_gyro_DC_blocker;  /// filter parameter to remove DC from gyro online (should be close to <1.0 and equal to 1.0 for disabling)
96
97
98
99
100
101
102
103
104
105
106
107
        Vector3         m_gyro_offset;        /// gyrometer offset
        Vector3         m_acc_offset;         /// accelerometer offset

        Vector3         m_gyro_sum;           /// tmp variable to store the sum of the gyro measurements during update phase
        Vector3         m_acc_sum;            /// tmp variable to store the sum of the acc measurements during update phase

      }; // class ImuOffsetCompensation
    }    // namespace torque_control
  }      // namespace sot
}        // namespace dynamicgraph

#endif // #ifndef __sot_torque_control_imu_offset_compensation_H__