yarp-devices
Loading...
Searching...
No Matches
SpaceNavigator.hpp
1// -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2
3#ifndef __SPACE_NAVIGATOR_HPP__
4#define __SPACE_NAVIGATOR_HPP__
5
6#include <mutex>
7
8#include <yarp/conf/version.h>
9
10#include <yarp/os/Thread.h>
11
12#include <yarp/dev/DeviceDriver.h>
13#include <yarp/dev/IJoypadController.h>
14
15#include <spnav.h>
16
17#include "SpaceNavigator_ParamsParser.h"
18
38class SpaceNavigator : public yarp::dev::DeviceDriver,
39 public yarp::dev::IJoypadController,
40 public yarp::os::Thread, // not using PeriodicThread for performance reasons
42{
43public:
44 // --------- DeviceDriver Declarations. Implementation in DeviceDriverImpl.cpp ---------
45 bool open(yarp::os::Searchable & config) override;
46 bool close() override;
47
48 // --------- Thread Declarations. Implementation in ThreadImpl.cpp ---------
49 void run() override;
50
51 // --------- IAnalogSensor Declarations. Implementation in IJoypadControllerImpl.cpp ---------
52#if YARP_VERSION_COMPARE(>=, 4, 0, 0)
53 yarp::dev::ReturnValue getAxisCount(std::size_t & axis_count) override;
54 yarp::dev::ReturnValue getButtonCount(std::size_t & button_count) override;
55 yarp::dev::ReturnValue getTrackballCount(std::size_t & trackball_count) override;
56 yarp::dev::ReturnValue getHatCount(std::size_t & hat_count) override;
57 yarp::dev::ReturnValue getTouchSurfaceCount(std::size_t & touch_count) override;
58 yarp::dev::ReturnValue getStickCount(std::size_t & stick_count) override;
59 yarp::dev::ReturnValue getButton(std::size_t button_id, double & value) override;
60 yarp::dev::ReturnValue getTrackball(std::size_t trackball_id, yarp::dev::TrackballData & value) override;
61 yarp::dev::ReturnValue getHat(std::size_t hat_id, unsigned char & value) override;
62 yarp::dev::ReturnValue getAxis(std::size_t axis_id, double & value) override;
63 yarp::dev::ReturnValue getAllAxes(std::vector<double> & values) override;
64 yarp::dev::ReturnValue getStick(std::size_t stick_id, yarp::dev::StickData & value, yarp::dev::IJoypadController::JoypadCtrl_coordinateMode coordinate_mode) override;
65 yarp::dev::ReturnValue getTouch(std::size_t touch_id, std::vector<yarp::dev::TouchData> & value) override;
66#else
67 bool getAxisCount(unsigned int & axis_count) override;
68 bool getButtonCount(unsigned int & button_count) override;
69 bool getTrackballCount(unsigned int & trackball_count) override;
70 bool getHatCount(unsigned int & hat_count) override;
71 bool getTouchSurfaceCount(unsigned int & touch_count) override;
72 bool getStickCount(unsigned int & stick_count) override;
73 bool getStickDoF(unsigned int stick_id, unsigned int & DoF) override;
74 bool getButton(unsigned int button_id, float & value) override;
75 bool getTrackball(unsigned int trackball_id, yarp::sig::Vector & value) override;
76 bool getHat(unsigned int hat_id, unsigned char & value) override;
77 bool getAxis(unsigned int axis_id, double & value) override;
78 bool getStick(unsigned int stick_id, yarp::sig::Vector & value, yarp::dev::IJoypadController::JoypadCtrl_coordinateMode coordinate_mode) override;
79 bool getTouch(unsigned int touch_id, yarp::sig::Vector & value) override;
80#endif
81
82private:
83 double dx {0.0};
84 double dy {0.0};
85 double dz {0.0};
86
87 double drx {0.0};
88 double dry {0.0};
89 double drz {0.0};
90
91 float button1 {0.f};
92 float button2 {0.f};
93
94 double deadband {0.0};
95
96 mutable std::mutex mtx;
97};
98
99#endif // __SPACE_NAVIGATOR_HPP__
Definition SpaceNavigator_ParamsParser.h:49
Implementation for the SpaceNavigator 3D mouse.
Definition SpaceNavigator.hpp:42