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
28
29namespace armarx
30{
31 using namespace IMU;
32
38
39 void
41 {
42
43 std::vector<float> offset(3, 0.0);
44
45 int count = 0;
46
47 IceUtil::Time startTime = armarx::TimeUtil::GetTime();
48
49 if (getProperty<bool>("EnableSimpleCalibration").getValue())
50 {
51 ARMARX_WARNING << "Estimation of the offset for the IMU, please do not move the IMU";
52 while (((armarx::TimeUtil::GetTime() - startTime) < IceUtil::Time::seconds(5)) &&
53 !sensorTask->isStopped())
54 {
55
56 while (HasPendingEvents())
57 {
59
60 offset[0] += m_GyroscopeRotation[0];
61 offset[1] += m_GyroscopeRotation[1];
62 offset[2] += m_GyroscopeRotation[2];
63
64 count++;
65 }
66 }
67
68 offset[0] /= count;
69 offset[1] /= count;
70 offset[2] /= count;
71 }
72
73
74 while (!sensorTask->isStopped())
75 {
76
77 while (HasPendingEvents())
78 {
79
81
83 IMUData data;
84
85 data.acceleration.push_back(m_Accelaration[0]);
86 data.acceleration.push_back(m_Accelaration[1]);
87 data.acceleration.push_back(m_Accelaration[2]);
88
89 data.gyroscopeRotation.push_back(m_GyroscopeRotation[0] - offset[0]);
90 data.gyroscopeRotation.push_back(m_GyroscopeRotation[1] - offset[1]);
91 data.gyroscopeRotation.push_back(m_GyroscopeRotation[2] - offset[2]);
92
93
94 data.magneticRotation.push_back(m_MagneticRotation[0]);
95 data.magneticRotation.push_back(m_MagneticRotation[1]);
96 data.magneticRotation.push_back(m_MagneticRotation[2]);
97
98
99 data.orientationQuaternion.push_back(m_OrientationQuaternion[0]);
100 data.orientationQuaternion.push_back(m_OrientationQuaternion[1]);
101 data.orientationQuaternion.push_back(m_OrientationQuaternion[2]);
102 data.orientationQuaternion.push_back(m_OrientationQuaternion[3]);
103
104 IMUTopicPrx->reportSensorValues("XsensIMU", "XsensIMU", data, now);
105 }
106
107 usleep(10000);
108 }
109 }
110
111 /*
112 void XsensIMU::OnIMUCycle(const timeval& TimeStamp, const CIMUDevice* pIMUDevice)
113 {
114 const IMUState CurrentState = pIMUDevice->GetIMUState();
115
116 TimestampVariantPtr now = TimestampVariant::nowPtr();
117 IMUData data;
118
119 data.acceleration.push_back(CurrentState.m_PhysicalData.m_Acceleration[0]);
120 data.acceleration.push_back(CurrentState.m_PhysicalData.m_Acceleration[1]);
121 data.acceleration.push_back(CurrentState.m_PhysicalData.m_Acceleration[2]);
122
123 data.gyroscopeRotation.push_back(CurrentState.m_PhysicalData.m_GyroscopeRotation[0]);
124 data.gyroscopeRotation.push_back(CurrentState.m_PhysicalData.m_GyroscopeRotation[1]);
125 data.gyroscopeRotation.push_back(CurrentState.m_PhysicalData.m_GyroscopeRotation[2]);
126
127 data.magneticRotation.push_back(CurrentState.m_PhysicalData.m_MagneticRotation[0]);
128 data.magneticRotation.push_back(CurrentState.m_PhysicalData.m_MagneticRotation[1]);
129 data.magneticRotation.push_back(CurrentState.m_PhysicalData.m_MagneticRotation[2]);
130
131 data.orientationQuaternion.push_back(CurrentState.m_PhysicalData.m_OrientationQuaternion[0]);
132 data.orientationQuaternion.push_back(CurrentState.m_PhysicalData.m_OrientationQuaternion[1]);
133 data.orientationQuaternion.push_back(CurrentState.m_PhysicalData.m_OrientationQuaternion[2]);
134 data.orientationQuaternion.push_back(CurrentState.m_PhysicalData.m_OrientationQuaternion[3]);
135
136 IMUTopicPrx->reportSensorValues("XsensIMU", pIMUDevice->GetDeviceId(), data, now);
137
138 }
139
140 */
141
142 void
144 {
146
149
150 //IMUDevice.SetFusion(IMU::CIMUDevice::eGaussianFusion, 2);
151 IMUDevice.RegisterEventDispatcher(this);
152
153 IMUDevice.Connect(_IMU_DEVICE_DEFAUL_CONNECTION_,
155 }
156
157 void
159 {
160 IMUDevice.Start(false);
161 sensorTask->start();
162 }
163
164 void
166 {
167 IMUDevice.Stop();
168 sensorTask->stop();
169 }
170
172} // namespace armarx
#define ARMARX_REGISTER_COMPONENT_EXECUTABLE(ComponentT, applicationName)
Definition Decoupled.h:29
#define _IMU_DEVICE_DEFAUL_CONNECTION_
Definition IMUDevice.h:23
@ eSamplingFrequency_120HZ
Definition IMUDevice.h:83
void SetMaximalPendingEvents(const uint32_t MaximalPendingEvents)
void SetDispatchingMode(const DispatchingMode Mode)
std::string getConfigIdentifier()
Retrieve config identifier for this component as set in constructor.
Definition Component.cpp:90
Property< PropertyType > getProperty(const std::string &name)
InertialMeasurementUnitListenerPrx IMUTopicPrx
static IceUtil::Time GetTime(TimeMode timeMode=TimeMode::VirtualTime)
Get the current time.
Definition TimeUtil.cpp:42
static TimestampVariantPtr nowPtr()
A brief description.
Definition XsensIMU.h:65
void frameAcquisitionTaskLoop()
Definition XsensIMU.cpp:40
void onExitIMU() override
Definition XsensIMU.cpp:165
void onStartIMU() override
Definition XsensIMU.cpp:158
void onInitIMU() override
Definition XsensIMU.cpp:143
PropertyDefinitionsPtr createPropertyDefinitions() override
Definition XsensIMU.cpp:34
#define ARMARX_WARNING
The logging level for unexpected behaviour, but not a serious problem.
Definition Logging.h:193
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
IceInternal::Handle< TimestampVariant > TimestampVariantPtr