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
17#include <yarp/os/Time.h>
18#include <yarp/os/Network.h>
20#include <yarp/os/Vocab.h>
21
22#include <yarp/dev/PolyDriver.h>
23#include <yarp/sig/Vector.h>
25
27
28#include <mutex>
29#include <string>
30#include <vector>
31#include <cstdarg>
32
33#ifdef MSVC
34 #pragma warning(disable:4355)
35#endif
36
37/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
38 TODO make more general
39 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
40
41
43// TODO add IVirtualAnalogSensor interface to have Channels number and status??
44
45
47{
48public:
51
52 bool attach(yarp::dev::PolyDriver* driver, const std::string& key);
53 void detach();
54
55 bool configure(int map0, int map1, const std::string& key);
56
57 bool isAttached() { return mIsAttached; }
58
59 void setTorque(int joint, double torque)
60 {
61 if (joint < mMap0 || mMap1 < joint) {
62 return;
63 }
64
65 mTorques[joint - mMap0] = torque;
66 }
67
69 {
70 mTorques.zero();
71 }
72
79
80 const std::string& getKey() { return mKey; }
81
82protected:
83 std::string mKey;
84
86
88
91 double lastRecvMsg{ 0.0 };
94};
95
109 public yarp::os::Thread,
111{
112public:
118
120 {
121 close();
122 }
123
124 // DeviceDriver //////////////////////////////////////////////////////////
125 bool open(yarp::os::Searchable& config) override;
126 bool close() override;
128
129 // Thread ////////////////////////////////////////////////////////////////
130 void run() override;
132
133 // IMultipleWrapper //////////////////////////////////////////////////////
134 bool attachAll(const yarp::dev::PolyDriverList &p) override;
135 bool detachAll() override;
137
138 // Utility
139 bool perform_first_check(int elems);
140
141protected:
142 std::mutex mMutex;
143
144 bool mIsVerbose{false};
145
146 int mNSubdevs{0};
147
148 std::vector<int> mChan2Board;
149 std::vector<int> mChan2BAddr;
150 double lastRecv{0.0};
151 bool first_check{false};
152
153 std::vector<AnalogSubDevice> mSubdevices;
155};
156
157#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()
Zero the elements of the vector.
Definition Vector.h:344