yarp-devices
Loading...
Searching...
No Matches
PhidgetSpatial.hpp
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3#ifndef __PHIDGET_SPATIAL_HPP__
4#define __PHIDGET_SPATIAL_HPP__
5
6#include <mutex>
7
8#include <yarp/dev/DeviceDriver.h>
9#include <yarp/dev/MultipleAnalogSensorsInterfaces.h>
10
11#include <phidget21.h>
12
13constexpr auto NUM_SENSORS = 1;
14
15#define CHECK_SENSOR(n) do { if ((n) < 0 || (n) > NUM_SENSORS - 1) return false; } while (0)
16
27class PhidgetSpatial : public yarp::dev::DeviceDriver,
28 public yarp::dev::IThreeAxisLinearAccelerometers,
29 public yarp::dev::IThreeAxisGyroscopes,
30 public yarp::dev::IThreeAxisMagnetometers
31{
32public:
33 // -------- DeviceDriver declarations. Implementation in DeviceDriverImpl.cpp --------
34 bool open(yarp::os::Searchable & config) override;
35 bool close() override;
36
37 // --------- IThreeAxisLinearAccelerometers Declarations. Implementation in IThreeAxisLinearAccelerometersImpl.cpp ---------
38 size_t getNrOfThreeAxisLinearAccelerometers() const;
39 yarp::dev::MAS_status getThreeAxisLinearAccelerometerStatus(size_t sens_index) const;
40 bool getThreeAxisLinearAccelerometerName(size_t sens_index, std::string & name) const;
41 bool getThreeAxisLinearAccelerometerFrameName(size_t sens_index, std::string & frameName) const;
42 bool getThreeAxisLinearAccelerometerMeasure(size_t sens_index, yarp::sig::Vector & out, double & timestamp) const;
43
44 // --------- IThreeAxisGyroscopes Declarations. Implementation in IThreeAxisGyroscopesImpl.cpp ---------
45 size_t getNrOfThreeAxisGyroscopes() const;
46 yarp::dev::MAS_status getThreeAxisGyroscopeStatus(size_t sens_index) const;
47 bool getThreeAxisGyroscopeName(size_t sens_index, std::string & name) const;
48 bool getThreeAxisGyroscopeFrameName(size_t sens_index, std::string & frameName) const;
49 bool getThreeAxisGyroscopeMeasure(size_t sens_index, yarp::sig::Vector & out, double & timestamp) const;
50
51 // --------- IThreeAxisMagnetometers Declarations. Implementation in IThreeAxisMagnetometersImpl.cpp ---------
52 size_t getNrOfThreeAxisMagnetometers() const;
53 yarp::dev::MAS_status getThreeAxisMagnetometerStatus(size_t sens_index) const;
54 bool getThreeAxisMagnetometerName(size_t sens_index, std::string & name) const;
55 bool getThreeAxisMagnetometerFrameName(size_t sens_index, std::string & frameName) const;
56 bool getThreeAxisMagnetometerMeasure(size_t sens_index, yarp::sig::Vector & out, double & timestamp) const;
57
58private:
59 // -- Helper Funcion declarations. Implementation in PhidgetSpatial.cpp --
60
62 // The following six functions have been extracted and modified from the - Spatial simple -
63 // example ((creates an Spatial handle, hooks the event handlers, and then waits for an
64 // encoder is attached. Once it is attached, the program will wait for user input so that
65 // we can see the event data on the screen when using the encoder. Legal info:
66 // Copyright 2008 Phidgets Inc. All rights reserved.
67 // This work is licensed under the Creative Commons Attribution 2.5 Canada License.
68 // view a copy of this license, visit http://creativecommons.org/licenses/by/2.5/ca/
69 static int AttachHandler(CPhidgetHandle ENC, void * userptr);
70 static int DetachHandler(CPhidgetHandle ENC, void * userptr);
71 static int ErrorHandler(CPhidgetHandle ENC, void * userptr, int ErrorCode, const char * Description);
72 static int SpatialDataHandler(CPhidgetSpatialHandle spatial, void * userptr, CPhidgetSpatial_SpatialEventDataHandle * data, int count);
73 static int display_properties(CPhidgetSpatialHandle phid);
75
76 CPhidgetSpatialHandle hSpatial0;
77 mutable std::mutex mtx;
78
79 double acceleration[3];
80 double angularRate[3];
81 double magneticField[3];
82
83 double timestamp {0.0};
84};
85
86#endif // __PHIDGET_SPATIAL_HPP__
Implementation of a Phidgets device.
Definition PhidgetSpatial.hpp:31