YARP
Yet Another Robot Platform
ImplementEncodersTimed.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
9
10#include <cstdio>
11using namespace yarp::dev;
12using namespace yarp::os;
13#define JOINTIDCHECK if (j >= castToMapper(helper)->axes()){yError("joint id out of bound"); return false;}
14
16// Encoder Interface Timed Implementation
17ImplementEncodersTimed::ImplementEncodersTimed(IEncodersTimedRaw *y):
18 iEncoders(y),
19 helper(nullptr),
20 buffManager(nullptr)
21{;}
22
24{
26}
27
28bool ImplementEncodersTimed:: initialize (int size, const int *amap, const double *enc, const double *zos)
29{
30 if (helper != nullptr) {
31 return false;
32 }
33
34 helper=(void *)(new ControlBoardHelper(size, amap, enc, zos));
35 yAssert (helper != nullptr);
36
38 yAssert (buffManager != nullptr);
39 return true;
40}
41
47{
48 if (helper!=nullptr)
49 {
50 delete castToMapper(helper);
51 helper=nullptr;
52 }
53
54 if (buffManager!=nullptr)
55 {
56 delete buffManager;
57 buffManager=nullptr;
58 }
59 return true;
60}
61
63{
64 (*ax)=castToMapper(helper)->axes();
65 return true;
66}
67
69{
71 int k;
73
74 return iEncoders->resetEncoderRaw(k);
75}
76
78{
80}
81
83{
85 int k;
86 double enc;
87
88 castToMapper(helper)->posA2E(val, j, enc, k);
89
90 return iEncoders->setEncoderRaw(k, enc);
91}
92
94{
96 castToMapper(helper)->posA2E(val, buffValues.getData());
97 bool ret = iEncoders->setEncodersRaw(buffValues.getData());
98 buffManager->releaseBuffer(buffValues);
99 return ret;
100}
101
103{
105 int k;
106 double enc;
107 bool ret;
108
109 k=castToMapper(helper)->toHw(j);
110
111 ret=iEncoders->getEncoderRaw(k, &enc);
112
113 *v=castToMapper(helper)->posE2A(enc, k);
114
115 return ret;
116}
117
119{
121 bool ret = iEncoders->getEncodersRaw(buffValues.getData());
122 castToMapper(helper)->posE2A(buffValues.getData(), v);
123 buffManager->releaseBuffer(buffValues);
124 return ret;
125}
126
128{
130 int k;
131 double enc;
132 bool ret;
133
134 k=castToMapper(helper)->toHw(j);
135
137
138 *v=castToMapper(helper)->velE2A(enc, k);
139
140 return ret;
141}
142
144{
146 bool ret=iEncoders->getEncoderSpeedsRaw(buffValues.getData());
147 castToMapper(helper)->velE2A(buffValues.getData(), v);
148 buffManager->releaseBuffer(buffValues);
149 return ret;
150}
151
153{
155 int k;
156 double enc;
157 bool ret;
158
159 k=castToMapper(helper)->toHw(j);
160
162
163 *v=castToMapper(helper)->accE2A(enc, k);
164
165 return ret;
166}
167
169{
171 bool ret = iEncoders->getEncoderAccelerationsRaw(buffValues.getData());
172 castToMapper(helper)->accE2A(buffValues.getData(), v);
173 buffManager->releaseBuffer(buffValues);
174 return ret;
175}
176
177bool ImplementEncodersTimed::getEncoderTimed(int j, double *v, double *t)
178{
180 int k;
181 double enc;
182 bool ret;
183
184 k=castToMapper(helper)->toHw(j);
185
187
188 *v=castToMapper(helper)->posE2A(enc, k);
189
190 return ret;
191}
192
193
195{
198 bool ret=iEncoders->getEncodersTimedRaw(b_v.getData(), b_t.getData());
199
200 castToMapper(helper)->posE2A(b_v.getData(), v);
202
205 return ret;
206}
yarp::dev::ControlBoardHelper * castToMapper(void *p)
float t
bool ret
#define JOINTIDCHECK
#define yAssert(x)
Definition: Log.h:383
void accE2A(double enc, int j, double &ang, int &k)
void velE2A(double enc, int j, double &ang, int &k)
void posE2A(double enc, int j, double &ang, int &k)
void posA2E(double ang, int j, double &enc, int &k)
virtual bool getEncoderSpeedsRaw(double *spds)=0
Read the instantaneous acceleration of an axis.
virtual bool resetEncoderRaw(int j)=0
Reset encoder, single joint.
virtual bool setEncoderRaw(int j, double val)=0
Set the value of the encoder for a given joint.
virtual bool getEncoderSpeedRaw(int j, double *sp)=0
Read the instantaneous speed of an axis.
virtual bool getEncoderAccelerationsRaw(double *accs)=0
Read the instantaneous acceleration of all axes.
virtual bool getEncodersRaw(double *encs)=0
Read the position of all axes.
virtual bool getEncoderRaw(int j, double *v)=0
Read the value of an encoder.
virtual bool getEncoderAccelerationRaw(int j, double *spds)=0
Read the instantaneous acceleration of an axis.
virtual bool resetEncodersRaw()=0
Reset encoders.
virtual bool setEncodersRaw(const double *vals)=0
Set the value of all encoders.
Control board, extend encoder raw interface adding timestamps.
virtual bool getEncoderTimedRaw(int j, double *encs, double *stamp)=0
Read the instantaneous acceleration of all axes.
virtual bool getEncodersTimedRaw(double *encs, double *stamps)=0
Read the instantaneous acceleration of all axes.
bool getEncoder(int j, double *v) override
Read the value of an encoder.
bool getEncoderSpeed(int j, double *spds) override
Read the istantaneous speed of an axis.
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
bool getEncoderAcceleration(int j, double *spds) override
Read the instantaneous acceleration of an axis.
bool uninitialize()
Clean up internal data and memory.
bool setEncoders(const double *vals) override
Set the value of all encoders.
bool resetEncoders() override
Reset encoders.
bool setEncoder(int j, double val) override
Set the value of the encoder for a given joint.
bool getEncoderAccelerations(double *accs) override
Read the instantaneous acceleration of all axes.
bool getEncoderTimed(int j, double *v, double *t) override
Read the instantaneous acceleration of all axes.
bool resetEncoder(int j) override
Reset encoder, single joint.
bool getEncodersTimed(double *encs, double *time) override
Read the instantaneous acceleration of all axes.
yarp::dev::impl::FixedSizeBuffersManager< double > * buffManager
bool getEncoders(double *encs) override
Read the position of all axes.
bool getAxes(int *ax) override
Get the number of controlled axes.
bool getEncoderSpeeds(double *spds) override
Read the instantaneous speed of all axes.
Buffer contains info about a buffer of type T and it is used to exchange information with yarp::dev::...
T * getData()
Return the data pointer.
Buffer< T > getBuffer()
Get a buffer and fill its information in @buffer.
void releaseBuffer(Buffer< T > &buffer)
Release a buffer.
For streams capable of holding different kinds of content, check what they actually have.
An interface to the operating system, including Port based communication.