YARP
Yet Another Robot Platform
ImplementVirtualAnalogSensor.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006-2020 Istituto Italiano di Tecnologia (IIT)
3  * All rights reserved.
4  *
5  * This software may be modified and distributed under the terms of the
6  * BSD-3-Clause license. See the accompanying LICENSE file for details.
7  */
8 
11 #include "yarp/sig/Vector.h"
12 #include <cstdio>
13 
14 using namespace yarp::dev;
15 #define JOINTIDCHECK if (ch >= castToMapper(helper)->axes()){yError("channel id out of bound"); return false;}
16 
18 {
19  iVASRaw = virt;
20  helper=nullptr;
21 }
22 
24 {
25  uninitialize();
26 }
27 
28 bool ImplementVirtualAnalogSensor::initialize(int size, const int *amap, const double *userToRaw)
29 {
30  if (helper!=nullptr)
31  return false;
32 
33  helper=(void *)(new ControlBoardHelper(size, amap, nullptr, nullptr, nullptr, nullptr, userToRaw, nullptr));
34  yAssert (helper != nullptr);
35 
36  return true;
37 }
38 
40 {
41  if (helper!=nullptr)
42  {
43  delete castToMapper(helper);
44  helper=nullptr;
45  }
46  return true;
47 }
48 
50 {
51  if (ch >= castToMapper(helper)->axes())
52  {
53  return yarp::dev::VAS_status::VAS_ERROR;
54  }
55  else
56  {
57  int ch_raw = castToMapper(helper)->toHw(ch);
58  return iVASRaw->getVirtualAnalogSensorStatusRaw(ch_raw);
59  }
60 }
61 
63 {
64  return iVASRaw->getVirtualAnalogSensorChannelsRaw();
65 }
66 
68 {
69  yarp::sig::Vector measure_raw;
70  castToMapper(helper)->voltageV2S(measure.data(), measure_raw.data());
71  bool ret = iVASRaw->updateVirtualAnalogSensorMeasureRaw(measure_raw);
72  return ret;
73 }
74 
76 {
78  int ch_raw;
79  bool ret;
80  double measure_raw;
81  castToMapper(helper)->voltageV2S(measure, ch, measure_raw, ch_raw);
82  ret = iVASRaw->updateVirtualAnalogSensorMeasureRaw(ch_raw, measure_raw);
83  return ret;
84 }
yarp::dev::IVirtualAnalogSensorRaw::updateVirtualAnalogSensorMeasureRaw
virtual bool updateVirtualAnalogSensorMeasureRaw(yarp::sig::Vector &measure)=0
Set a vector of torque values for virtual sensor.
yarp::dev::ControlBoardHelper::toHw
int toHw(int axis)
Definition: ControlBoardHelper.cpp:245
yarp::dev::ImplementVirtualAnalogSensor::~ImplementVirtualAnalogSensor
~ImplementVirtualAnalogSensor()
Definition: ImplementVirtualAnalogSensor.cpp:23
Vector.h
contains the definition of a Vector type
yarp::dev::ImplementVirtualAnalogSensor::uninitialize
bool uninitialize()
Definition: ImplementVirtualAnalogSensor.cpp:39
yarp::dev::ImplementVirtualAnalogSensor::getVirtualAnalogSensorStatus
VAS_status getVirtualAnalogSensorStatus(int ch) override
Check the status of a given channel.
Definition: ImplementVirtualAnalogSensor.cpp:49
yarp::dev::IVirtualAnalogSensorRaw::getVirtualAnalogSensorStatusRaw
virtual VAS_status getVirtualAnalogSensorStatusRaw(int ch)=0
Check the status of a given channel.
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
yarp::dev::IVirtualAnalogSensorRaw
A generic interface to a virtual sensors.
Definition: IVirtualAnalogSensor.h:84
yarp::dev::ImplementVirtualAnalogSensor::updateVirtualAnalogSensorMeasure
bool updateVirtualAnalogSensorMeasure(yarp::sig::Vector &measure) override
Set a vector of torque values for virtual sensor.
Definition: ImplementVirtualAnalogSensor.cpp:67
yarp::dev::ImplementVirtualAnalogSensor::ImplementVirtualAnalogSensor
ImplementVirtualAnalogSensor(IVirtualAnalogSensorRaw *virt)
Definition: ImplementVirtualAnalogSensor.cpp:17
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
yarp::dev::ImplementVirtualAnalogSensor::getVirtualAnalogSensorChannels
int getVirtualAnalogSensorChannels() override
Get the number of channels of the virtual sensor.
Definition: ImplementVirtualAnalogSensor.cpp:62
yarp::sig::VectorOf< double >
ImplementVirtualAnalogSensor.h
yarp::dev::ControlBoardHelper::voltageV2S
void voltageV2S(double voltage, int j, double &sens, int &k)
Definition: ControlBoardHelper.cpp:631
yarp::dev::IVirtualAnalogSensorRaw::getVirtualAnalogSensorChannelsRaw
virtual int getVirtualAnalogSensorChannelsRaw()=0
Get the number of channels of the virtual sensor.
ControlBoardHelper.h
yarp::sig::VectorOf::data
T * data()
Return a pointer to the first element of the vector.
Definition: Vector.h:239
yarp::dev::VAS_status
VAS_status
Definition: IVirtualAnalogSensor.h:31
yarp::dev::ImplementVirtualAnalogSensor::initialize
bool initialize(int k, const int *amap, const double *userToRaw)
Definition: ImplementVirtualAnalogSensor.cpp:28
castToMapper
yarp::dev::ControlBoardHelper * castToMapper(void *p)
Definition: ControlBoardHelper.h:180
yarp::dev::ControlBoardHelper
Definition: ControlBoardHelper.h:60
JOINTIDCHECK
#define JOINTIDCHECK
Definition: ImplementVirtualAnalogSensor.cpp:15
yAssert
#define yAssert(x)
Definition: Log.h:297