YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
VirtualAnalogWrapper.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#ifndef YARP_DEV_VIRTUALANALOGWRAPPER_VIRTUALANALOGWRAPPER_H
7#define YARP_DEV_VIRTUALANALOGWRAPPER_VIRTUALANALOGWRAPPER_H
8
9
10// VirtualAnalogWrapper
11// A server that opens an input port getting externally measured analog values
12// and it is able to attach to a one or more virtual analog sensor through
13// IVirtualAnalogSensor interface.
14
16#include <yarp/os/Time.h>
17#include <yarp/os/Network.h>
19#include <yarp/os/Vocab.h>
20
21#include <yarp/dev/PolyDriver.h>
22#include <yarp/sig/Vector.h>
24
26
27#include <mutex>
28#include <string>
29#include <vector>
30#include <cstdarg>
31
32#ifdef MSVC
33 #pragma warning(disable:4355)
34#endif
35
36/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
37 TODO make more general
38 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
39
40
42// TODO add IVirtualAnalogSensor interface to have Channels number and status??
43
44
46{
47public:
50
51 bool attach(yarp::dev::PolyDriver* driver, const std::string& key);
52 void detach();
53
54 bool configure(int map0, int map1, const std::string& key);
55
56 bool isAttached() { return mIsAttached; }
57
58 void setTorque(int joint, double torque)
59 {
60 if (joint < mMap0 || mMap1 < joint) {
61 return;
62 }
63
64 mTorques[joint - mMap0] = torque;
65 }
66
68 {
69 mTorques.zero();
70 }
71
78
79 const std::string& getKey() { return mKey; }
80
81protected:
82 std::string mKey;
83
85
87
90 double lastRecvMsg{ 0.0 };
93};
94
108 public yarp::os::Thread,
110{
111public:
117
119 {
120 close();
121 }
122
123 // DeviceDriver //////////////////////////////////////////////////////////
124 bool open(yarp::os::Searchable& config) override;
125 bool close() override;
127
128 // Thread ////////////////////////////////////////////////////////////////
129 void run() override;
131
132 // IMultipleWrapper //////////////////////////////////////////////////////
133 bool attachAll(const yarp::dev::PolyDriverList &p) override;
134 bool detachAll() override;
136
137 // Utility
138 bool perform_first_check(int elems);
139
140protected:
141 std::mutex mMutex;
142
143 bool mIsVerbose{false};
144
145 int mNSubdevs{0};
146
147 std::vector<int> mChan2Board;
148 std::vector<int> mChan2BAddr;
149 double lastRecv{0.0};
150 bool first_check{false};
151
152 std::vector<AnalogSubDevice> mSubdevices;
154};
155
156#endif // YARP_DEV_VIRTUALANALOGWRAPPER_VIRTUALANALOGWRAPPER_H
virtual analog sensor interface
contains the definition of a Vector type
const std::string & getKey()
yarp::sig::Vector mTorques
yarp::dev::IVirtualAnalogSensor * mpSensor
yarp::dev::PolyDriver * mpDevice
bool configure(int map0, int map1, const std::string &key)
void setTorque(int joint, double torque)
bool attach(yarp::dev::PolyDriver *driver, const std::string &key)
virtualAnalogServer: An analog wrapper for virtual device A virtual device is a software emulated dev...
VirtualAnalogWrapper()=default
VirtualAnalogWrapper & operator=(const VirtualAnalogWrapper &)=delete
VirtualAnalogWrapper & operator=(VirtualAnalogWrapper &&)=delete
std::vector< AnalogSubDevice > mSubdevices
VirtualAnalogWrapper(VirtualAnalogWrapper &&)=delete
std::vector< int > mChan2Board
bool close() override
Close the DeviceDriver.
std::vector< int > mChan2BAddr
bool attachAll(const yarp::dev::PolyDriverList &p) override
Attach to a list of objects.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
VirtualAnalogWrapper(const VirtualAnalogWrapper &)=delete
bool detachAll() override
Detach the object (you must have first called attach).
void run() override
Main body of the new thread.
yarp::os::BufferedPort< yarp::os::Bottle > mPortInputTorques
bool perform_first_check(int elems)
Interface implemented by all device drivers.
Interface for an object that can wrap/attach to to another.
A generic interface to a virtual sensors.
virtual bool updateVirtualAnalogSensorMeasure(yarp::sig::Vector &measure)=0
Set a vector of torque values for virtual sensor.
A container for a device driver.
Definition PolyDriver.h:23
A mini-server for performing network communication in the background.
A base class for nested structures that can be searched.
Definition Searchable.h:31
An abstraction for a thread of execution.
Definition Thread.h:21
void zero()
Set to zero the elements of the vector.
Definition VectorBase.h:296