YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
FakeAnalogSensor.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
6#include "FakeAnalogSensor.h"
7
8#include <yarp/os/Time.h>
10#include <yarp/os/LogStream.h>
11
12using namespace yarp::dev;
13
14namespace {
15YARP_LOG_COMPONENT(FAKEANALOGSENSOR, "yarp.device.fakeAnalogSensor")
16}
17
18FakeAnalogSensor::FakeAnalogSensor(double period) : PeriodicThread(period),
19 mutex(),
20 status(IAnalogSensor::AS_OK)
21{
22 yCTrace(FAKEANALOGSENSOR);
23 timeStamp = yarp::os::Time::now();
24}
25
27{
28 yCTrace(FAKEANALOGSENSOR);
29}
30
31
33{
34 if (!this->parseParams(config)) {return false;}
35
36 yCTrace(FAKEANALOGSENSOR);
37
38 double period= m_period / 1000.0;
39 setPeriod(period);
40
41 //create the data vector:
43 data.zero();
44
45 return PeriodicThread::start();
46}
47
49{
50 yCTrace(FAKEANALOGSENSOR);
51 //stop the thread
52 PeriodicThread::stop();
53
54 return true;
55}
56
58{
59 mutex.lock();
60 out[0] = yarp::os::Time::now();
61 mutex.unlock();
62
63 return status;
64}
65
67{
68 yCTrace(FAKEANALOGSENSOR);
69 // Always ok for now
70 return status;
71}
72
74{
75 yCTrace(FAKEANALOGSENSOR);
76 return m_channelsNum;
77}
78
80{
81 yCTrace(FAKEANALOGSENSOR);
82 //NOT YET IMPLEMENTED
83 return 0;
84}
85
87{
88 yCTrace(FAKEANALOGSENSOR);
89 //NOT YET IMPLEMENTED
90 return 0;
91}
92
94{
95 yCTrace(FAKEANALOGSENSOR);
96 //NOT YET IMPLEMENTED
97 return 0;
98}
99
101{
102 yCTrace(FAKEANALOGSENSOR);
103 //NOT YET IMPLEMENTED
104 return 0;
105}
106
108{
109 yCTrace(FAKEANALOGSENSOR);
110 return true;
111}
112
114{
115 mutex.lock();
116
117 // Do fake stuff
118 double timeNow = yarp::os::Time::now();
119
120 //if 100ms have passed since the last received message
121 if (timeNow > timeStamp + 10) {
123 } else {
124 status = IAnalogSensor::AS_OK;
125 }
126
127 timeStamp = timeNow;
128 mutex.unlock();
129}
130
132{
133 yCTrace(FAKEANALOGSENSOR);
134}
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
bool threadInit() override
Initialization method.
void run() override
Loop function.
int calibrateChannel(int ch) override
Calibrates one single channel.
bool close() override
Close the DeviceDriver.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
int getChannels() override
Get the number of channels of the sensor.
int calibrateSensor() override
Calibrates the whole sensor.
int read(yarp::sig::Vector &out) override
Read a vector from the sensor.
void threadRelease() override
Release method.
int getState(int ch) override
Check the state value of a given channel.
FakeAnalogSensor(double period=0.02)
A generic interface to sensors (gyro, a/d converters).
bool setPeriod(double period)
Set the (new) period of the thread.
A base class for nested structures that can be searched.
Definition Searchable.h:31
void resize(size_t size) override
Resize the vector.
Definition Vector.h:221
void zero()
Zero the elements of the vector.
Definition Vector.h:363
#define yCTrace(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.
double now()
Return the current time in seconds, relative to an arbitrary starting point.
Definition Time.cpp:121