YARP
Yet Another Robot Platform
ImplementEncodersTimed.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 
12 
13 #include <cstdio>
14 using namespace yarp::dev;
15 using namespace yarp::os;
16 #define JOINTIDCHECK if (j >= castToMapper(helper)->axes()){yError("joint id out of bound"); return false;}
17 
19 // Encoder Interface Timed Implementation
21  iEncoders(y),
22  helper(nullptr),
23  buffManager(nullptr)
24 {;}
25 
27 {
28  uninitialize();
29 }
30 
31 bool ImplementEncodersTimed:: initialize (int size, const int *amap, const double *enc, const double *zos)
32 {
33  if (helper!=nullptr)
34  return false;
35 
36  helper=(void *)(new ControlBoardHelper(size, amap, enc, zos));
37  yAssert (helper != nullptr);
38 
40  yAssert (buffManager != nullptr);
41  return true;
42 }
43 
49 {
50  if (helper!=nullptr)
51  {
52  delete castToMapper(helper);
53  helper=nullptr;
54  }
55 
56  if (buffManager!=nullptr)
57  {
58  delete buffManager;
59  buffManager=nullptr;
60  }
61  return true;
62 }
63 
65 {
66  (*ax)=castToMapper(helper)->axes();
67  return true;
68 }
69 
71 {
73  int k;
74  k=castToMapper(helper)->toHw(j);
75 
76  return iEncoders->resetEncoderRaw(k);
77 }
78 
80 {
81  return iEncoders->resetEncodersRaw();
82 }
83 
84 bool ImplementEncodersTimed::setEncoder(int j, double val)
85 {
87  int k;
88  double enc;
89 
90  castToMapper(helper)->posA2E(val, j, enc, k);
91 
92  return iEncoders->setEncoderRaw(k, enc);
93 }
94 
95 bool ImplementEncodersTimed::setEncoders(const double *val)
96 {
98  castToMapper(helper)->posA2E(val, buffValues.getData());
99  bool ret = iEncoders->setEncodersRaw(buffValues.getData());
100  buffManager->releaseBuffer(buffValues);
101  return ret;
102 }
103 
105 {
107  int k;
108  double enc;
109  bool ret;
110 
111  k=castToMapper(helper)->toHw(j);
112 
113  ret=iEncoders->getEncoderRaw(k, &enc);
114 
115  *v=castToMapper(helper)->posE2A(enc, k);
116 
117  return ret;
118 }
119 
121 {
123  bool ret = iEncoders->getEncodersRaw(buffValues.getData());
124  castToMapper(helper)->posE2A(buffValues.getData(), v);
125  buffManager->releaseBuffer(buffValues);
126  return ret;
127 }
128 
130 {
132  int k;
133  double enc;
134  bool ret;
135 
136  k=castToMapper(helper)->toHw(j);
137 
138  ret=iEncoders->getEncoderSpeedRaw(k, &enc);
139 
140  *v=castToMapper(helper)->velE2A(enc, k);
141 
142  return ret;
143 }
144 
146 {
148  bool ret=iEncoders->getEncoderSpeedsRaw(buffValues.getData());
149  castToMapper(helper)->velE2A(buffValues.getData(), v);
150  buffManager->releaseBuffer(buffValues);
151  return ret;
152 }
153 
155 {
157  int k;
158  double enc;
159  bool ret;
160 
161  k=castToMapper(helper)->toHw(j);
162 
164 
165  *v=castToMapper(helper)->accE2A(enc, k);
166 
167  return ret;
168 }
169 
171 {
173  bool ret = iEncoders->getEncoderAccelerationsRaw(buffValues.getData());
174  castToMapper(helper)->accE2A(buffValues.getData(), v);
175  buffManager->releaseBuffer(buffValues);
176  return ret;
177 }
178 
179 bool ImplementEncodersTimed::getEncoderTimed(int j, double *v, double *t)
180 {
182  int k;
183  double enc;
184  bool ret;
185 
186  k=castToMapper(helper)->toHw(j);
187 
188  ret=iEncoders->getEncoderTimedRaw(k, &enc, t);
189 
190  *v=castToMapper(helper)->posE2A(enc, k);
191 
192  return ret;
193 }
194 
195 
197 {
200  bool ret=iEncoders->getEncodersTimedRaw(b_v.getData(), b_t.getData());
201 
202  castToMapper(helper)->posE2A(b_v.getData(), v);
203  castToMapper(helper)->toUser(b_t.getData(), t);
204 
207  return ret;
208 }
yarp::dev::ControlBoardHelper * castToMapper(void *p)
float t
bool ret
#define JOINTIDCHECK
#define yAssert(x)
Definition: Log.h:297
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.
ImplementEncodersTimed(yarp::dev::IEncodersTimedRaw *y)
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.
An interface for the device drivers.
An interface to the operating system, including Port based communication.