YARP
Yet Another Robot Platform
ImplementVirtualAnalogSensor.cpp
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 
8 #include "yarp/sig/Vector.h"
9 #include <cstdio>
10 
11 using namespace yarp::dev;
12 #define JOINTIDCHECK if (ch >= castToMapper(helper)->axes()){yError("channel id out of bound"); return false;}
13 
15 {
16  iVASRaw = virt;
17  helper=nullptr;
18 }
19 
21 {
22  uninitialize();
23 }
24 
25 bool ImplementVirtualAnalogSensor::initialize(int size, const int *amap, const double *userToRaw)
26 {
27  if (helper != nullptr) {
28  return false;
29  }
30 
31  helper=(void *)(new ControlBoardHelper(size, amap, nullptr, nullptr, nullptr, nullptr, userToRaw, nullptr));
32  yAssert (helper != nullptr);
33 
34  return true;
35 }
36 
38 {
39  if (helper!=nullptr)
40  {
41  delete castToMapper(helper);
42  helper=nullptr;
43  }
44  return true;
45 }
46 
48 {
49  if (ch >= castToMapper(helper)->axes())
50  {
52  }
53  else
54  {
55  int ch_raw = castToMapper(helper)->toHw(ch);
56  return iVASRaw->getVirtualAnalogSensorStatusRaw(ch_raw);
57  }
58 }
59 
61 {
62  return iVASRaw->getVirtualAnalogSensorChannelsRaw();
63 }
64 
66 {
67  yarp::sig::Vector measure_raw;
68  castToMapper(helper)->voltageV2S(measure.data(), measure_raw.data());
69  bool ret = iVASRaw->updateVirtualAnalogSensorMeasureRaw(measure_raw);
70  return ret;
71 }
72 
74 {
76  int ch_raw;
77  bool ret;
78  double measure_raw;
79  castToMapper(helper)->voltageV2S(measure, ch, measure_raw, ch_raw);
80  ret = iVASRaw->updateVirtualAnalogSensorMeasureRaw(ch_raw, measure_raw);
81  return ret;
82 }
yarp::dev::ControlBoardHelper * castToMapper(void *p)
bool ret
#define JOINTIDCHECK
#define yAssert(x)
Definition: Log.h:294
contains the definition of a Vector type
void voltageV2S(double voltage, int j, double &sens, int &k)
A generic interface to a virtual sensors.
virtual int getVirtualAnalogSensorChannelsRaw()=0
Get the number of channels of the virtual sensor.
virtual bool updateVirtualAnalogSensorMeasureRaw(yarp::sig::Vector &measure)=0
Set a vector of torque values for virtual sensor.
virtual VAS_status getVirtualAnalogSensorStatusRaw(int ch)=0
Check the status of a given channel.
int getVirtualAnalogSensorChannels() override
Get the number of channels of the virtual sensor.
ImplementVirtualAnalogSensor(IVirtualAnalogSensorRaw *virt)
bool updateVirtualAnalogSensorMeasure(yarp::sig::Vector &measure) override
Set a vector of torque values for virtual sensor.
VAS_status getVirtualAnalogSensorStatus(int ch) override
Check the status of a given channel.
bool initialize(int k, const int *amap, const double *userToRaw)
T * data()
Return a pointer to the first element of the vector.
Definition: Vector.h:207
An interface for the device drivers.