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::IEncodersRaw::setEncoderRaw
virtual bool setEncoderRaw(int j, double val)=0
Set the value of the encoder for a given joint.
yarp::dev::ImplementEncodersTimed::getEncoderTimed
bool getEncoderTimed(int j, double *v, double *t) override
Read the instantaneous acceleration of all axes.
Definition: ImplementEncodersTimed.cpp:179
yarp::dev::ControlBoardHelper::velE2A
void velE2A(double enc, int j, double &ang, int &k)
Definition: ControlBoardHelper.cpp:414
yarp::dev::ControlBoardHelper::toHw
int toHw(int axis)
Definition: ControlBoardHelper.cpp:245
yarp::dev::ImplementEncodersTimed::getEncoderAccelerations
bool getEncoderAccelerations(double *accs) override
Read the instantaneous acceleration of all axes.
Definition: ImplementEncodersTimed.cpp:170
yarp::dev::ControlBoardHelper::posE2A
void posE2A(double enc, int j, double &ang, int &k)
Definition: ControlBoardHelper.cpp:290
yarp::dev::ControlBoardHelper::toUser
int toUser(int axis)
Definition: ControlBoardHelper.cpp:248
yarp::dev::IEncodersRaw::getEncoderAccelerationRaw
virtual bool getEncoderAccelerationRaw(int j, double *spds)=0
Read the instantaneous acceleration of an axis.
yarp::dev::ImplementEncodersTimed::getEncodersTimed
bool getEncodersTimed(double *encs, double *time) override
Read the instantaneous acceleration of all axes.
Definition: ImplementEncodersTimed.cpp:196
t
float t
Definition: FfmpegWriter.cpp:74
yarp::dev::ImplementEncodersTimed::getAxes
bool getAxes(int *ax) override
Get the number of controlled axes.
Definition: ImplementEncodersTimed.cpp:64
yarp::dev::impl::Buffer::getData
T * getData()
Return the data pointer.
Definition: FixedSizeBuffersManager-inl.h:29
yarp::dev::ImplementEncodersTimed::setEncoder
bool setEncoder(int j, double val) override
Set the value of the encoder for a given joint.
Definition: ImplementEncodersTimed.cpp:84
yarp::dev::impl::FixedSizeBuffersManager< double >
yarp::dev::ImplementEncodersTimed::ImplementEncodersTimed
ImplementEncodersTimed(yarp::dev::IEncodersTimedRaw *y)
Definition: ImplementEncodersTimed.cpp:20
yarp::dev::impl::FixedSizeBuffersManager::getBuffer
Buffer< T > getBuffer()
Get a buffer and fill its information in @buffer.
Definition: FixedSizeBuffersManager-inl.h:87
yarp::dev::ImplementEncodersTimed::uninitialize
bool uninitialize()
Clean up internal data and memory.
Definition: ImplementEncodersTimed.cpp:48
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
yarp::dev::IEncodersTimedRaw::getEncoderTimedRaw
virtual bool getEncoderTimedRaw(int j, double *encs, double *stamp)=0
Read the instantaneous acceleration of all axes.
yarp::dev::ImplementEncodersTimed::getEncoderSpeeds
bool getEncoderSpeeds(double *spds) override
Read the instantaneous speed of all axes.
Definition: ImplementEncodersTimed.cpp:145
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
yarp::dev::ImplementEncodersTimed::setEncoders
bool setEncoders(const double *vals) override
Set the value of all encoders.
Definition: ImplementEncodersTimed.cpp:95
yarp::dev::IEncodersRaw::getEncoderAccelerationsRaw
virtual bool getEncoderAccelerationsRaw(double *accs)=0
Read the instantaneous acceleration of all axes.
yarp::dev::IEncodersTimedRaw::getEncodersTimedRaw
virtual bool getEncodersTimedRaw(double *encs, double *stamps)=0
Read the instantaneous acceleration of all axes.
yarp::dev::ImplementEncodersTimed::iEncoders
IEncodersTimedRaw * iEncoders
Definition: ImplementEncodersTimed.h:34
yarp::dev::IEncodersRaw::getEncoderSpeedsRaw
virtual bool getEncoderSpeedsRaw(double *spds)=0
Read the instantaneous acceleration of an axis.
yarp::dev::ImplementEncodersTimed::getEncoder
bool getEncoder(int j, double *v) override
Read the value of an encoder.
Definition: ImplementEncodersTimed.cpp:104
yarp::dev::ControlBoardHelper::posA2E
void posA2E(double ang, int j, double &enc, int &k)
Definition: ControlBoardHelper.cpp:279
yarp::dev::ImplementEncodersTimed::getEncoders
bool getEncoders(double *encs) override
Read the position of all axes.
Definition: ImplementEncodersTimed.cpp:120
yarp::dev::ImplementEncodersTimed::buffManager
yarp::dev::impl::FixedSizeBuffersManager< double > * buffManager
Definition: ImplementEncodersTimed.h:36
yarp::dev::IEncodersRaw::getEncodersRaw
virtual bool getEncodersRaw(double *encs)=0
Read the position of all axes.
yarp::dev::ImplementEncodersTimed::~ImplementEncodersTimed
virtual ~ImplementEncodersTimed()
Definition: ImplementEncodersTimed.cpp:26
FixedSizeBuffersManager.h
yarp::dev::impl::Buffer
Buffer contains info about a buffer of type T and it is used to exchange information with yarp::dev::...
Definition: FixedSizeBuffersManager.h:27
yarp::dev::ImplementEncodersTimed::getEncoderAcceleration
bool getEncoderAcceleration(int j, double *spds) override
Read the instantaneous acceleration of an axis.
Definition: ImplementEncodersTimed.cpp:154
ControlBoardHelper.h
yarp::dev::ImplementEncodersTimed::resetEncoder
bool resetEncoder(int j) override
Reset encoder, single joint.
Definition: ImplementEncodersTimed.cpp:70
yarp::dev::impl::FixedSizeBuffersManager::releaseBuffer
void releaseBuffer(Buffer< T > &buffer)
Release a buffer.
Definition: FixedSizeBuffersManager-inl.h:156
yarp::dev::IEncodersRaw::getEncoderRaw
virtual bool getEncoderRaw(int j, double *v)=0
Read the value of an encoder.
yarp::dev::IEncodersTimedRaw
Control board, extend encoder raw interface adding timestamps.
Definition: IEncodersTimed.h:28
yarp::dev::IEncodersRaw::resetEncodersRaw
virtual bool resetEncodersRaw()=0
Reset encoders.
yarp::dev::IEncodersRaw::setEncodersRaw
virtual bool setEncodersRaw(const double *vals)=0
Set the value of all encoders.
yarp::dev::IEncodersRaw::getEncoderSpeedRaw
virtual bool getEncoderSpeedRaw(int j, double *sp)=0
Read the instantaneous speed of an axis.
yarp::os
An interface to the operating system, including Port based communication.
Definition: AbstractCarrier.h:17
castToMapper
yarp::dev::ControlBoardHelper * castToMapper(void *p)
Definition: ControlBoardHelper.h:180
yarp::dev::ImplementEncodersTimed::getEncoderSpeed
bool getEncoderSpeed(int j, double *spds) override
Read the istantaneous speed of an axis.
Definition: ImplementEncodersTimed.cpp:129
yarp::dev::IEncodersRaw::resetEncoderRaw
virtual bool resetEncoderRaw(int j)=0
Reset encoder, single joint.
yarp::dev::ControlBoardHelper
Definition: ControlBoardHelper.h:60
yarp::dev::ControlBoardHelper::accE2A
void accE2A(double enc, int j, double &ang, int &k)
Definition: ControlBoardHelper.cpp:436
ControlBoardInterfacesImpl.h
yarp::dev::ImplementEncodersTimed::resetEncoders
bool resetEncoders() override
Reset encoders.
Definition: ImplementEncodersTimed.cpp:79
yarp::dev::ControlBoardHelper::axes
int axes()
Definition: ControlBoardHelper.cpp:762
yarp::dev::ImplementEncodersTimed::initialize
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
Definition: ImplementEncodersTimed.cpp:31
JOINTIDCHECK
#define JOINTIDCHECK
Definition: ImplementEncodersTimed.cpp:16
yAssert
#define yAssert(x)
Definition: Log.h:297
yarp::dev::ImplementEncodersTimed::helper
void * helper
Definition: ImplementEncodersTimed.h:35