YARP
Yet Another Robot Platform
ImplementEncoders.cpp
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
9 
10 #include <cmath>
11 
12 // Be careful: this file contains template implementations and is included by translation
13 // units that use the template (e.g. .cpp files). Avoid putting here non-template functions to
14 // avoid multiple definitions.
15 
16 using namespace yarp::dev;
17 
19 // Encoder Interface Implementation
21 {
22  iEncoders= y;
23  helper = nullptr;
24  temp=nullptr;
25 }
26 
28 {
29  uninitialize();
30 }
31 
32 bool ImplementEncoders:: initialize (int size, const int *amap, const double *enc, const double *zos)
33 {
34  if (helper != nullptr) {
35  return false;
36  }
37 
38  helper=(void *)(new ControlBoardHelper(size, amap, enc, zos));
39  yAssert (helper != nullptr);
40  temp=new double [size];
41  yAssert (temp != nullptr);
42  return true;
43 }
44 
50 {
51  if (helper!=nullptr)
52  {
53  delete castToMapper(helper);
54  helper=nullptr;
55  }
56 
58 
59  return true;
60 }
61 
63 {
64  (*ax)=castToMapper(helper)->axes();
65  return true;
66 }
67 
69 {
70  int k;
71  k=castToMapper(helper)->toHw(j);
72 
73  return iEncoders->resetEncoderRaw(k);
74 }
75 
76 
78 {
79  return iEncoders->resetEncodersRaw();
80 }
81 
82 bool ImplementEncoders::setEncoder(int j, double val)
83 {
84  int k;
85  double enc;
86 
87  castToMapper(helper)->posA2E(val, j, enc, k);
88 
89  return iEncoders->setEncoderRaw(k, enc);
90 }
91 
92 bool ImplementEncoders::setEncoders(const double *val)
93 {
95 
96  return iEncoders->setEncodersRaw(temp);
97 }
98 
99 bool ImplementEncoders::getEncoder(int j, double *v)
100 {
101  int k;
102  double enc;
103  bool ret;
104 
105  k=castToMapper(helper)->toHw(j);
106 
107  ret=iEncoders->getEncoderRaw(k, &enc);
108 
109  *v=castToMapper(helper)->posE2A(enc, k);
110 
111  return ret;
112 }
113 
115 {
116  bool ret;
118 
120 
122 
123  return ret;
124 }
125 
127 {
128  int k;
129  double enc;
130  bool ret;
131 
132  k=castToMapper(helper)->toHw(j);
133 
134  ret=iEncoders->getEncoderSpeedRaw(k, &enc);
135 
136  *v=castToMapper(helper)->velE2A(enc, k);
137 
138  return ret;
139 }
140 
142 {
143  bool ret;
145 
147 
148  return ret;
149 }
150 
152 {
153  int k;
154  double enc;
155  bool ret;
156 
157  k=castToMapper(helper)->toHw(j);
158 
160 
161  *v=castToMapper(helper)->accE2A(enc, k);
162 
163  return ret;
164 }
165 
167 {
168  bool ret;
170 
172 
173  return ret;
174 }
void checkAndDestroy(T *&p)
yarp::dev::ControlBoardHelper * castToMapper(void *p)
bool ret
#define yAssert(x)
Definition: Log.h:294
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)
Control board, encoder interface.
Definition: IEncoders.h:25
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.
bool getAxes(int *ax) override
Get the number of controlled axes.
bool getEncoders(double *encs) override
Read the position of all axes.
bool getEncoder(int j, double *v) override
Read the value of an encoder.
bool getEncoderAccelerations(double *accs) override
Read the instantaneous acceleration of all axes.
bool resetEncoders() override
Reset encoders.
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
bool resetEncoder(int j) override
Reset encoder, single joint.
bool setEncoders(const double *vals) override
Set the value of all encoders.
bool getEncoderSpeed(int j, double *spds) override
Read the instantaneous speed of an axis.
ImplementEncoders(yarp::dev::IEncodersRaw *y)
virtual ~ImplementEncoders()
Destructor.
bool getEncoderAcceleration(int j, double *spds) override
Read the instantaneous acceleration of an axis.
bool uninitialize()
Clean up internal data and memory.
bool setEncoder(int j, double val) override
Set the value of the encoder for a given joint.
bool getEncoderSpeeds(double *spds) override
Read the instantaneous speed of all axes.
An interface for the device drivers.