YARP
Yet Another Robot Platform
fakeIMU.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
9 #include <string>
10 #include <yarp/dev/DeviceDriver.h>
11 #include <yarp/os/PeriodicThread.h>
14 #include <yarp/os/Stamp.h>
16 #include <yarp/math/Math.h>
17 
18 
19 
35 class fakeIMU :
44 {
45 public:
46  fakeIMU();
47  fakeIMU(const fakeIMU&) = delete;
48  fakeIMU(fakeIMU&&) = delete;
49  fakeIMU& operator=(const fakeIMU&) = delete;
50  fakeIMU& operator=(fakeIMU&&) = delete;
51 
52  ~fakeIMU() override;
53 
54  // Device Driver interface
55  bool open(yarp::os::Searchable &config) override;
56  bool close() override;
57 
58  // IGenericSensor interface.
59  bool read(yarp::sig::Vector &out) override;
60  bool getChannels(int *nc) override;
61  bool calibrate(int ch, double v) override;
62 
63  // IPreciselyTimed interface
65 
66  /* IThreeAxisGyroscopes methods */
67  size_t getNrOfThreeAxisGyroscopes() const override;
68  yarp::dev::MAS_status getThreeAxisGyroscopeStatus(size_t sens_index) const override;
69  bool getThreeAxisGyroscopeName(size_t sens_index, std::string &name) const override;
70  bool getThreeAxisGyroscopeFrameName(size_t sens_index, std::string &frameName) const override;
71  bool getThreeAxisGyroscopeMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const override;
72 
73  /* IThreeAxisLinearAccelerometers methods */
74  size_t getNrOfThreeAxisLinearAccelerometers() const override;
75  yarp::dev::MAS_status getThreeAxisLinearAccelerometerStatus(size_t sens_index) const override;
76  bool getThreeAxisLinearAccelerometerName(size_t sens_index, std::string &name) const override;
77  bool getThreeAxisLinearAccelerometerFrameName(size_t sens_index, std::string &frameName) const override;
78  bool getThreeAxisLinearAccelerometerMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const override;
79 
80  /* IThreeAxisMagnetometers methods */
81  size_t getNrOfThreeAxisMagnetometers() const override;
82  yarp::dev::MAS_status getThreeAxisMagnetometerStatus(size_t sens_index) const override;
83  bool getThreeAxisMagnetometerName(size_t sens_index, std::string &name) const override;
84  bool getThreeAxisMagnetometerFrameName(size_t sens_index, std::string &frameName) const override;
85  bool getThreeAxisMagnetometerMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const override;
86 
87  /* IOrientationSensors methods */
88  size_t getNrOfOrientationSensors() const override;
89  yarp::dev::MAS_status getOrientationSensorStatus(size_t sens_index) const override;
90  bool getOrientationSensorName(size_t sens_index, std::string &name) const override;
91  bool getOrientationSensorFrameName(size_t sens_index, std::string &frameName) const override;
92  bool getOrientationSensorMeasureAsRollPitchYaw(size_t sens_index, yarp::sig::Vector& rpy, double& timestamp) const override;
93 
94 private:
95  yarp::dev::MAS_status genericGetStatus(size_t sens_index) const;
96  bool genericGetSensorName(size_t sens_index, std::string &name) const;
97  bool genericGetFrameName(size_t sens_index, std::string &frameName) const;
98 
99  bool threadInit() override;
100  void run() override;
101 
102  yarp::sig::Vector rpy;
103  yarp::sig::Vector gravity;
104  yarp::sig::Matrix dcm;
105  yarp::sig::Vector accels;
106 
107  unsigned int nchannels;
108  double dummy_value;
109  yarp::os::Stamp lastStamp;
110  std::string m_sensorName;
111  std::string m_frameName;
112  bool constantValue;
113 };
fakeIMU : fake device implementing the device interface typically implemented by an Inertial Measurem...
Definition: fakeIMU.h:44
fakeIMU & operator=(const fakeIMU &)=delete
size_t getNrOfOrientationSensors() const override
Get the number of orientation sensors exposed by this device.
Definition: fakeIMU.cpp:304
fakeIMU & operator=(fakeIMU &&)=delete
bool getThreeAxisGyroscopeFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame of the specified sensor.
Definition: fakeIMU.cpp:205
bool getThreeAxisMagnetometerName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
Definition: fakeIMU.cpp:276
fakeIMU(const fakeIMU &)=delete
bool getThreeAxisGyroscopeName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
Definition: fakeIMU.cpp:200
bool close() override
Close the DeviceDriver.
Definition: fakeIMU.cpp:75
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: fakeIMU.cpp:59
yarp::dev::MAS_status getThreeAxisGyroscopeStatus(size_t sens_index) const override
Get the status of the specified sensor.
Definition: fakeIMU.cpp:195
size_t getNrOfThreeAxisMagnetometers() const override
Get the number of magnetometers exposed by this device.
Definition: fakeIMU.cpp:266
bool getThreeAxisLinearAccelerometerFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame of the specified sensor.
Definition: fakeIMU.cpp:243
yarp::dev::MAS_status getThreeAxisMagnetometerStatus(size_t sens_index) const override
Get the status of the specified sensor.
Definition: fakeIMU.cpp:271
bool getOrientationSensorMeasureAsRollPitchYaw(size_t sens_index, yarp::sig::Vector &rpy, double &timestamp) const override
Get the last reading of the orientation sensor as roll pitch yaw.
Definition: fakeIMU.cpp:324
bool getOrientationSensorFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame of the specified sensor.
Definition: fakeIMU.cpp:319
bool getThreeAxisMagnetometerMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const override
Get the last reading of the specified sensor.
Definition: fakeIMU.cpp:286
yarp::dev::MAS_status getThreeAxisLinearAccelerometerStatus(size_t sens_index) const override
Get the status of the specified sensor.
Definition: fakeIMU.cpp:233
bool getChannels(int *nc) override
Get the number of channels of the sensor.
Definition: fakeIMU.cpp:115
~fakeIMU() override
Definition: fakeIMU.cpp:54
fakeIMU(fakeIMU &&)=delete
bool read(yarp::sig::Vector &out) override
Read a vector from the sensor.
Definition: fakeIMU.cpp:81
fakeIMU()
This device implements a fake analog sensor emulating an IMU.
Definition: fakeIMU.cpp:40
bool getThreeAxisLinearAccelerometerMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const override
Get the last reading of the specified sensor.
Definition: fakeIMU.cpp:248
size_t getNrOfThreeAxisLinearAccelerometers() const override
Get the number of three axis linear accelerometers exposed by this device.
Definition: fakeIMU.cpp:228
bool getThreeAxisGyroscopeMeasure(size_t sens_index, yarp::sig::Vector &out, double &timestamp) const override
Get the last reading of the gyroscope.
Definition: fakeIMU.cpp:210
bool getOrientationSensorName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
Definition: fakeIMU.cpp:314
bool getThreeAxisLinearAccelerometerName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
Definition: fakeIMU.cpp:238
yarp::dev::MAS_status getOrientationSensorStatus(size_t sens_index) const override
Get the status of the specified sensor.
Definition: fakeIMU.cpp:309
bool getThreeAxisMagnetometerFrameName(size_t sens_index, std::string &frameName) const override
Get the name of the frame of the specified sensor.
Definition: fakeIMU.cpp:281
yarp::os::Stamp getLastInputStamp() override
Return the time stamp relative to the last acquisition.
Definition: fakeIMU.cpp:156
bool calibrate(int ch, double v) override
Calibrate the sensor, single channel.
Definition: fakeIMU.cpp:121
size_t getNrOfThreeAxisGyroscopes() const override
Get the number of three axis gyroscopes exposed by this sensor.
Definition: fakeIMU.cpp:190
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
A generic interface to sensors – gyro, a/d converters etc.
Device interface to one or multiple orientation sensors, such as IMUs with on board estimation algori...
Device interface to one or multiple three axis gyroscopes.
Device interface to one or multiple three axis linear accelerometers.
Device interface to one or multiple three axis magnetometers.
An abstraction for a periodic thread.
A base class for nested structures that can be searched.
Definition: Searchable.h:69
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25
A class for a Matrix.
Definition: Matrix.h:46
MAS_status
Status of a given analog sensor exposed by a multiple analog sensors interface.