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 
34 class fakeIMU :
43 {
44 public:
45  fakeIMU();
46  fakeIMU(const fakeIMU&) = delete;
47  fakeIMU(fakeIMU&&) = delete;
48  fakeIMU& operator=(const fakeIMU&) = delete;
49  fakeIMU& operator=(fakeIMU&&) = delete;
50 
51  ~fakeIMU() override;
52 
53  // Device Driver interface
54  bool open(yarp::os::Searchable &config) override;
55  bool close() override;
56 
57  // IGenericSensor interface.
58  bool read(yarp::sig::Vector &out) override;
59  bool getChannels(int *nc) override;
60  bool calibrate(int ch, double v) override;
61 
62  // IPreciselyTimed interface
64 
65  /* IThreeAxisGyroscopes methods */
66  size_t getNrOfThreeAxisGyroscopes() const override;
67  yarp::dev::MAS_status getThreeAxisGyroscopeStatus(size_t sens_index) const override;
68  bool getThreeAxisGyroscopeName(size_t sens_index, std::string &name) const override;
69  bool getThreeAxisGyroscopeFrameName(size_t sens_index, std::string &frameName) const override;
70  bool getThreeAxisGyroscopeMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const override;
71 
72  /* IThreeAxisLinearAccelerometers methods */
73  size_t getNrOfThreeAxisLinearAccelerometers() const override;
74  yarp::dev::MAS_status getThreeAxisLinearAccelerometerStatus(size_t sens_index) const override;
75  bool getThreeAxisLinearAccelerometerName(size_t sens_index, std::string &name) const override;
76  bool getThreeAxisLinearAccelerometerFrameName(size_t sens_index, std::string &frameName) const override;
77  bool getThreeAxisLinearAccelerometerMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const override;
78 
79  /* IThreeAxisMagnetometers methods */
80  size_t getNrOfThreeAxisMagnetometers() const override;
81  yarp::dev::MAS_status getThreeAxisMagnetometerStatus(size_t sens_index) const override;
82  bool getThreeAxisMagnetometerName(size_t sens_index, std::string &name) const override;
83  bool getThreeAxisMagnetometerFrameName(size_t sens_index, std::string &frameName) const override;
84  bool getThreeAxisMagnetometerMeasure(size_t sens_index, yarp::sig::Vector& out, double& timestamp) const override;
85 
86  /* IOrientationSensors methods */
87  size_t getNrOfOrientationSensors() const override;
88  yarp::dev::MAS_status getOrientationSensorStatus(size_t sens_index) const override;
89  bool getOrientationSensorName(size_t sens_index, std::string &name) const override;
90  bool getOrientationSensorFrameName(size_t sens_index, std::string &frameName) const override;
91  bool getOrientationSensorMeasureAsRollPitchYaw(size_t sens_index, yarp::sig::Vector& rpy, double& timestamp) const override;
92 
93 private:
94  yarp::dev::MAS_status genericGetStatus(size_t sens_index) const;
95  bool genericGetSensorName(size_t sens_index, std::string &name) const;
96  bool genericGetFrameName(size_t sens_index, std::string &frameName) const;
97 
98  bool threadInit() override;
99  void run() override;
100 
101  yarp::sig::Vector rpy;
102  yarp::sig::Vector gravity;
103  yarp::sig::Matrix dcm;
104  yarp::sig::Vector accels;
105 
106  unsigned int nchannels;
107  double dummy_value;
108  yarp::os::Stamp lastStamp;
109  std::string m_sensorName;
110  std::string m_frameName;
111  bool constantValue;
112 };
fakeIMU::getOrientationSensorFrameName
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
yarp::dev::IGenericSensor
A generic interface to sensors – gyro, a/d converters etc.
Definition: IGenericSensor.h:25
yarp::os::Searchable
A base class for nested structures that can be searched.
Definition: Searchable.h:69
IPreciselyTimed.h
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
yarp::dev::IThreeAxisMagnetometers
Device interface to one or multiple three axis magnetometers.
Definition: MultipleAnalogSensorsInterfaces.h:165
yarp::dev::IThreeAxisGyroscopes
Device interface to one or multiple three axis gyroscopes.
Definition: MultipleAnalogSensorsInterfaces.h:64
yarp::dev::IOrientationSensors
Device interface to one or multiple orientation sensors, such as IMUs with on board estimation algori...
Definition: MultipleAnalogSensorsInterfaces.h:274
fakeIMU::getNrOfThreeAxisGyroscopes
size_t getNrOfThreeAxisGyroscopes() const override
Get the number of three axis gyroscopes exposed by this sensor.
Definition: fakeIMU.cpp:190
fakeIMU::operator=
fakeIMU & operator=(const fakeIMU &)=delete
MultipleAnalogSensorsInterfaces.h
fakeIMU::getThreeAxisMagnetometerMeasure
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
fakeIMU::getLastInputStamp
yarp::os::Stamp getLastInputStamp() override
Return the time stamp relative to the last acquisition.
Definition: fakeIMU.cpp:156
fakeIMU::getThreeAxisGyroscopeFrameName
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
fakeIMU::getNrOfOrientationSensors
size_t getNrOfOrientationSensors() const override
Get the number of orientation sensors exposed by this device.
Definition: fakeIMU.cpp:304
fakeIMU::close
bool close() override
Close the DeviceDriver.
Definition: fakeIMU.cpp:75
yarp::sig::VectorOf< double >
fakeIMU::calibrate
bool calibrate(int ch, double v) override
Calibrate the sensor, single channel.
Definition: fakeIMU.cpp:121
fakeIMU::getThreeAxisGyroscopeMeasure
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
fakeIMU::operator=
fakeIMU & operator=(fakeIMU &&)=delete
fakeIMU::fakeIMU
fakeIMU(fakeIMU &&)=delete
fakeIMU::getThreeAxisLinearAccelerometerName
bool getThreeAxisLinearAccelerometerName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
Definition: fakeIMU.cpp:238
fakeIMU::getNrOfThreeAxisMagnetometers
size_t getNrOfThreeAxisMagnetometers() const override
Get the number of magnetometers exposed by this device.
Definition: fakeIMU.cpp:266
fakeIMU::read
bool read(yarp::sig::Vector &out) override
Read a vector from the sensor.
Definition: fakeIMU.cpp:81
Math.h
fakeIMU::fakeIMU
fakeIMU()
This device implements a fake analog sensor emulating an IMU.
Definition: fakeIMU.cpp:40
Stamp.h
fakeIMU::~fakeIMU
~fakeIMU() override
Definition: fakeIMU.cpp:54
yarp::dev::IThreeAxisLinearAccelerometers
Device interface to one or multiple three axis linear accelerometers.
Definition: MultipleAnalogSensorsInterfaces.h:118
fakeIMU::getOrientationSensorStatus
yarp::dev::MAS_status getOrientationSensorStatus(size_t sens_index) const override
Get the status of the specified sensor.
Definition: fakeIMU.cpp:309
fakeIMU::getThreeAxisGyroscopeName
bool getThreeAxisGyroscopeName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
Definition: fakeIMU.cpp:200
fakeIMU::getThreeAxisMagnetometerName
bool getThreeAxisMagnetometerName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
Definition: fakeIMU.cpp:276
fakeIMU::getThreeAxisLinearAccelerometerMeasure
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
yarp::os::PeriodicThread
An abstraction for a periodic thread.
Definition: PeriodicThread.h:25
fakeIMU::getNrOfThreeAxisLinearAccelerometers
size_t getNrOfThreeAxisLinearAccelerometers() const override
Get the number of three axis linear accelerometers exposed by this device.
Definition: fakeIMU.cpp:228
PeriodicThread.h
yarp::os::Stamp
An abstraction for a time stamp and/or sequence number.
Definition: Stamp.h:25
fakeIMU::fakeIMU
fakeIMU(const fakeIMU &)=delete
fakeIMU::open
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
Definition: fakeIMU.cpp:59
fakeIMU::getThreeAxisGyroscopeStatus
yarp::dev::MAS_status getThreeAxisGyroscopeStatus(size_t sens_index) const override
Get the status of the specified sensor.
Definition: fakeIMU.cpp:195
fakeIMU::getOrientationSensorMeasureAsRollPitchYaw
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
fakeIMU::getThreeAxisLinearAccelerometerFrameName
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
MAS_status
Status of a given analog sensor exposed by a multiple analog sensors interface.
Definition: MultipleAnalogSensorsInterfaces.h:37
IGenericSensor.h
fakeIMU::getThreeAxisLinearAccelerometerStatus
yarp::dev::MAS_status getThreeAxisLinearAccelerometerStatus(size_t sens_index) const override
Get the status of the specified sensor.
Definition: fakeIMU.cpp:233
fakeIMU::getThreeAxisMagnetometerFrameName
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::dev::IPreciselyTimed
Definition: IPreciselyTimed.h:21
fakeIMU
fakeIMU : fake device implementing the device interface typically implemented by an Inertial Measurem...
Definition: fakeIMU.h:43
DeviceDriver.h
fakeIMU::getChannels
bool getChannels(int *nc) override
Get the number of channels of the sensor.
Definition: fakeIMU.cpp:115
yarp::sig::Matrix
A class for a Matrix.
Definition: Matrix.h:46
fakeIMU::getOrientationSensorName
bool getOrientationSensorName(size_t sens_index, std::string &name) const override
Get the name of the specified sensor.
Definition: fakeIMU.cpp:314
fakeIMU::getThreeAxisMagnetometerStatus
yarp::dev::MAS_status getThreeAxisMagnetometerStatus(size_t sens_index) const override
Get the status of the specified sensor.
Definition: fakeIMU.cpp:271