XsensIMU.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of ArmarX.
3  *
4  * Copyright (C) 2012-2016, High Performance Humanoid Technologies (H2T), Karlsruhe Institute of Technology (KIT), all rights reserved.
5  *
6  * ArmarX is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * ArmarX is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * @package RobotAPI::ArmarXObjects::XsensIMU
19  * @author Markus Grotz ( markus-grotz at web dot de )
20  * @date 2015
21  * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
22  * GNU General Public License
23  */
24 
25 #include "XsensIMU.h"
26 
27 
28 namespace armarx
29 {
30  using namespace IMU;
31 
33  {
34  return PropertyDefinitionsPtr(new XsensIMUPropertyDefinitions(getConfigIdentifier()));
35  }
36 
38  {
39 
40  std::vector<float> offset(3, 0.0);
41 
42  int count = 0;
43 
45 
46  if (getProperty<bool>("EnableSimpleCalibration").getValue())
47  {
48  ARMARX_WARNING << "Estimation of the offset for the IMU, please do not move the IMU";
49  while (((armarx::TimeUtil::GetTime() - startTime) < IceUtil::Time::seconds(5)) && !sensorTask->isStopped())
50  {
51 
52  while (HasPendingEvents())
53  {
54  ProcessPendingEvent();
55 
56  offset[0] += m_GyroscopeRotation[0];
57  offset[1] += m_GyroscopeRotation[1];
58  offset[2] += m_GyroscopeRotation[2];
59 
60  count ++;
61  }
62  }
63 
64  offset[0] /= count;
65  offset[1] /= count;
66  offset[2] /= count;
67 
68  }
69 
70 
71  while (!sensorTask->isStopped())
72  {
73 
74  while (HasPendingEvents())
75  {
76 
77  ProcessPendingEvent();
78 
80  IMUData data;
81 
82  data.acceleration.push_back(m_Accelaration[0]);
83  data.acceleration.push_back(m_Accelaration[1]);
84  data.acceleration.push_back(m_Accelaration[2]);
85 
86  data.gyroscopeRotation.push_back(m_GyroscopeRotation[0] - offset[0]);
87  data.gyroscopeRotation.push_back(m_GyroscopeRotation[1] - offset[1]);
88  data.gyroscopeRotation.push_back(m_GyroscopeRotation[2] - offset[2]);
89 
90 
91  data.magneticRotation.push_back(m_MagneticRotation[0]);
92  data.magneticRotation.push_back(m_MagneticRotation[1]);
93  data.magneticRotation.push_back(m_MagneticRotation[2]);
94 
95 
96  data.orientationQuaternion.push_back(m_OrientationQuaternion[0]);
97  data.orientationQuaternion.push_back(m_OrientationQuaternion[1]);
98  data.orientationQuaternion.push_back(m_OrientationQuaternion[2]);
99  data.orientationQuaternion.push_back(m_OrientationQuaternion[3]);
100 
101  IMUTopicPrx->reportSensorValues("XsensIMU", "XsensIMU", data, now);
102 
103  }
104 
105  usleep(10000);
106  }
107  }
108 
109 
110  /*
111  void XsensIMU::OnIMUCycle(const timeval& TimeStamp, const CIMUDevice* pIMUDevice)
112  {
113  const IMUState CurrentState = pIMUDevice->GetIMUState();
114 
115  TimestampVariantPtr now = TimestampVariant::nowPtr();
116  IMUData data;
117 
118  data.acceleration.push_back(CurrentState.m_PhysicalData.m_Acceleration[0]);
119  data.acceleration.push_back(CurrentState.m_PhysicalData.m_Acceleration[1]);
120  data.acceleration.push_back(CurrentState.m_PhysicalData.m_Acceleration[2]);
121 
122  data.gyroscopeRotation.push_back(CurrentState.m_PhysicalData.m_GyroscopeRotation[0]);
123  data.gyroscopeRotation.push_back(CurrentState.m_PhysicalData.m_GyroscopeRotation[1]);
124  data.gyroscopeRotation.push_back(CurrentState.m_PhysicalData.m_GyroscopeRotation[2]);
125 
126  data.magneticRotation.push_back(CurrentState.m_PhysicalData.m_MagneticRotation[0]);
127  data.magneticRotation.push_back(CurrentState.m_PhysicalData.m_MagneticRotation[1]);
128  data.magneticRotation.push_back(CurrentState.m_PhysicalData.m_MagneticRotation[2]);
129 
130  data.orientationQuaternion.push_back(CurrentState.m_PhysicalData.m_OrientationQuaternion[0]);
131  data.orientationQuaternion.push_back(CurrentState.m_PhysicalData.m_OrientationQuaternion[1]);
132  data.orientationQuaternion.push_back(CurrentState.m_PhysicalData.m_OrientationQuaternion[2]);
133  data.orientationQuaternion.push_back(CurrentState.m_PhysicalData.m_OrientationQuaternion[3]);
134 
135  IMUTopicPrx->reportSensorValues("XsensIMU", pIMUDevice->GetDeviceId(), data, now);
136 
137  }
138 
139  */
140 
142  {
144 
145  SetDispatchingMode(IMU::IIMUEventDispatcher::eDecoupled);
146  SetMaximalPendingEvents(5);
147 
148  //IMUDevice.SetFusion(IMU::CIMUDevice::eGaussianFusion, 2);
149  IMUDevice.RegisterEventDispatcher(this);
150 
152  }
153 
155  {
156  IMUDevice.Start(false);
157  sensorTask->start();
158  }
159 
161  {
162  IMUDevice.Stop();
163  sensorTask->stop();
164  }
165 }
IMU::IIMUEventDispatcher::eDecoupled
@ eDecoupled
Definition: IIMUEventDispatcher.h:24
_IMU_DEVICE_DEFAUL_CONNECTION_
#define _IMU_DEVICE_DEFAUL_CONNECTION_
Definition: IMUDevice.h:23
armarx::XsensIMU::onInitIMU
void onInitIMU() override
Definition: XsensIMU.cpp:141
IMU::CIMUDevice::eSamplingFrequency_120HZ
@ eSamplingFrequency_120HZ
Definition: IMUDevice.h:81
armarx::XsensIMU::onExitIMU
void onExitIMU() override
Definition: XsensIMU.cpp:160
armarx::RunningTask
Definition: ArmarXMultipleObjectsScheduler.h:35
armarx::TimestampVariant::nowPtr
static TimestampVariantPtr nowPtr()
Definition: TimestampVariant.h:111
IceInternal::Handle< TimestampVariant >
XsensIMU.h
armarx::XsensIMU::frameAcquisitionTaskLoop
void frameAcquisitionTaskLoop()
Definition: XsensIMU.cpp:37
armarx::XsensIMU::onStartIMU
void onStartIMU() override
Definition: XsensIMU.cpp:154
data
uint8_t data[1]
Definition: EtherCATFrame.h:68
armarx::XsensIMU::createPropertyDefinitions
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition: XsensIMU.cpp:32
armarx::armem::Time
armarx::core::time::DateTime Time
Definition: forward_declarations.h:13
IMU
Definition: IIMUEventDispatcher.cpp:12
armarx::TimeUtil::GetTime
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition: TimeUtil.cpp:42
IceUtil::Handle< class PropertyDefinitionContainer >
armarx::XsensIMUPropertyDefinitions
Definition: XsensIMU.h:43
ARMARX_WARNING
#define ARMARX_WARNING
Definition: Logging.h:186
armarx::PropertyDefinitionsPtr
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
Definition: forward_declarations.h:34
armarx
This file offers overloads of toIce() and fromIce() functions for STL container types.
Definition: ArmarXTimeserver.cpp:28