yarp-devices
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 <yarp/os/all.h>
7 #include <yarp/dev/Drivers.h>
8 #include <yarp/dev/PolyDriver.h>
9 #include <yarp/dev/IAnalogSensor.h>
10 
11 #include <vector>
12 #include <math.h>
13 
14 #include <phidget21.h>
15 
16 namespace roboticslab
17 {
18 
29 class PhidgetSpatial : public yarp::dev::DeviceDriver,
30  public yarp::dev::IAnalogSensor
31 {
32 public:
33 
34  // -------- DeviceDriver declarations. Implementation in DeviceDriverImpl.cpp --------
35 
40  bool open(yarp::os::Searchable& config) override;
41  bool close() override;
42 
46  ~PhidgetSpatial() override = default;
47 
48  // --------- IAnalogSensor Declarations. Implementation in IAnalogSensorImpl.cpp ---------
49 
55  int read(yarp::sig::Vector &out) override;
56 
62  int getState(int ch) override;
63 
68  int getChannels() override;
69 
74  int calibrateSensor() override;
75 
81  int calibrateSensor(const yarp::sig::Vector& value) override;
82 
88  int calibrateChannel(int ch) override;
89 
96  int calibrateChannel(int ch, double value) override;
97 
98 
99  // -- Helper Funcion declarations. Implementation in PhidgetSpatial.cpp --
100 
102  // The following six functions have been extracted and modified from the - Spatial simple -
103  // example ((creates an Spatial handle, hooks the event handlers, and then waits for an
104  // encoder is attached. Once it is attached, the program will wait for user input so that
105  // we can see the event data on the screen when using the encoder. Legal info:
106  // Copyright 2008 Phidgets Inc. All rights reserved.
107  // This work is licensed under the Creative Commons Attribution 2.5 Canada License.
108  // view a copy of this license, visit http://creativecommons.org/licenses/by/2.5/ca/
109  static int AttachHandler(CPhidgetHandle ENC, void *userptr);
110  static int DetachHandler(CPhidgetHandle ENC, void *userptr);
111  static int ErrorHandler(CPhidgetHandle ENC, void *userptr, int ErrorCode, const char *Description);
112  static int SpatialDataHandler(CPhidgetSpatialHandle spatial, void *userptr, CPhidgetSpatial_SpatialEventDataHandle *data, int count);
113  int display_properties(CPhidgetSpatialHandle phid);
115 
116 // ------------------------------- Private -------------------------------------
117 
118 private:
119 
120  CPhidgetSpatialHandle hSpatial0;
121  yarp::os::Semaphore hSemaphore;
122  double acceleration[3];
123  double angularRate[3];
124  double magneticField[3];
125 };
126 
127 } // namespace roboticslab
128 
129 #endif // __PHIDGET_SPATIAL_HPP__
Implementation of a Phidgets device.
Definition: PhidgetSpatial.hpp:31
~PhidgetSpatial() override=default
bool open(yarp::os::Searchable &config) override
Definition: DeviceDriverImpl.cpp:9
int getState(int ch) override
Definition: IAnalogSensorImpl.cpp:52
int calibrateSensor() override
Definition: IAnalogSensorImpl.cpp:66
int getChannels() override
Definition: IAnalogSensorImpl.cpp:59
static int SpatialDataHandler(CPhidgetSpatialHandle spatial, void *userptr, CPhidgetSpatial_SpatialEventDataHandle *data, int count)
Definition: PhidgetSpatial.cpp:58
int read(yarp::sig::Vector &out) override
Definition: IAnalogSensorImpl.cpp:11
int calibrateChannel(int ch) override
Definition: IAnalogSensorImpl.cpp:80
The main, catch-all namespace for Robotics Lab UC3M.
Definition: groups.dox:6