YARP
Yet Another Robot Platform
ImplementMotorEncoders.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>
11 using namespace yarp::dev;
12 using namespace yarp::os;
13 
14 #define JOINTIDCHECK if (m >= castToMapper(helper)->axes()){yError("motor id out of bound"); return false;}
15 
17 // Encoder Interface Timed Implementation
19  iMotorEncoders(y),
20  helper(nullptr),
21  buffManager(nullptr)
22 {;}
23 
25 {
26  uninitialize();
27 }
28 
29 bool ImplementMotorEncoders:: initialize (int size, const int *amap, const double *enc, const double *zos)
30 {
31  if (helper != nullptr) {
32  return false;
33  }
34 
35  helper=(void *)(new ControlBoardHelper(size, amap, enc, zos));
36  yAssert (helper != nullptr);
37 
39  yAssert (buffManager != nullptr);
40  return true;
41 }
42 
48 {
49  if (helper!=nullptr)
50  {
51  delete castToMapper(helper);
52  helper=nullptr;
53  }
54 
55  if(buffManager)
56  {
57  delete buffManager;
58  buffManager=nullptr;
59  }
60 
61  return true;
62 }
63 
65 {
66  (*num)=castToMapper(helper)->axes();
67  return true;
68 }
69 
71 {
73  int k;
74  k=castToMapper(helper)->toHw(m);
75 
77 }
78 
80 {
82 }
83 
84 bool ImplementMotorEncoders::setMotorEncoder(int m, const double val)
85 {
87  int k;
88  double enc;
89 
90  castToMapper(helper)->posA2E(val, m, enc, k);
91 
92  return iMotorEncoders->setMotorEncoderRaw(k, enc);
93 }
94 
96 {
98  bool ret;
99  int k=castToMapper(helper)->toHw(m);
100 
102 
103  return ret;
104 }
105 
107 {
109  int k;
110 
111  k=castToMapper(helper)->toHw(m);
112 
114 }
115 
117 {
119  castToMapper(helper)->posA2E(val, buffValues.getData());
120 
121  bool ret = iMotorEncoders->setMotorEncodersRaw(buffValues.getData());
122  buffManager->releaseBuffer(buffValues);
123  return ret;
124 }
125 
127 {
129  int k;
130  double enc;
131  bool ret;
132 
133  k=castToMapper(helper)->toHw(m);
134 
136 
137  *v=castToMapper(helper)->posE2A(enc, k);
138 
139  return ret;
140 }
141 
143 {
145  bool ret=iMotorEncoders->getMotorEncodersRaw(buffValues.getData());
146  castToMapper(helper)->posE2A(buffValues.getData(), v);
147  buffManager->releaseBuffer(buffValues);
148  return ret;
149 }
150 
152 {
154  int k;
155  double enc;
156  bool ret;
157 
158  k=castToMapper(helper)->toHw(m);
159 
161 
162  *v=castToMapper(helper)->velE2A(enc, k);
163 
164  return ret;
165 }
166 
168 {
171  castToMapper(helper)->velE2A(buffValues.getData(), v);
172  buffManager->releaseBuffer(buffValues);
173  return ret;
174 }
175 
177 {
179  int k;
180  double enc;
181  bool ret;
182 
183  k=castToMapper(helper)->toHw(m);
184 
186 
187  *v=castToMapper(helper)->accE2A(enc, k);
188 
189  return ret;
190 }
191 
193 {
196  castToMapper(helper)->accE2A(buffValues.getData(), v);
197  buffManager->releaseBuffer(buffValues);
198  return ret;
199 }
200 
201 bool ImplementMotorEncoders::getMotorEncoderTimed(int m, double *v, double *t)
202 {
204  int k;
205  double enc;
206  bool ret;
207 
208  k=castToMapper(helper)->toHw(m);
209 
211 
212  *v=castToMapper(helper)->posE2A(enc, k);
213 
214  return ret;
215 }
216 
217 
219 {
223  castToMapper(helper)->posE2A(b_v.getData(), v);
224  castToMapper(helper)->toUser(b_t.getData(), t);
227  return ret;
228 }
yarp::dev::ControlBoardHelper * castToMapper(void *p)
float t
bool ret
#define JOINTIDCHECK
#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.
virtual bool setMotorEncoderCountsPerRevolutionRaw(int m, const double cpr)=0
Sets number of counts per revolution for motor encoder m.
virtual bool getMotorEncoderRaw(int m, double *v)=0
Read the value of a motor encoder.
virtual bool getMotorEncoderAccelerationsRaw(double *accs)=0
Read the instantaneous acceleration of all motor encoders.
virtual bool resetMotorEncodersRaw()=0
Reset motor encoders.
virtual bool getMotorEncoderCountsPerRevolutionRaw(int m, double *cpr)=0
Gets number of counts per revolution for motor encoder m.
virtual bool getMotorEncoderSpeedRaw(int m, double *sp)=0
Read the istantaneous speed of a motor encoder.
virtual bool getMotorEncodersTimedRaw(double *encs, double *stamps)=0
Read the instantaneous position of all motor encoders.
virtual bool getMotorEncodersRaw(double *encs)=0
Read the position of all motor encoders.
virtual bool getMotorEncoderSpeedsRaw(double *spds)=0
Read the instantaneous speed of all motor encoders.
virtual bool setMotorEncodersRaw(const double *vals)=0
Set the value of all motor encoders.
virtual bool setMotorEncoderRaw(int m, const double val)=0
Set the value of the motor encoder for a given motor.
virtual bool resetMotorEncoderRaw(int m)=0
Reset motor encoder, single motor.
virtual bool getMotorEncoderTimedRaw(int m, double *encs, double *stamp)=0
Read the instantaneous position of a motor encoder.
virtual bool getMotorEncoderAccelerationRaw(int m, double *spds)=0
Read the instantaneous acceleration of a motor encoder.
bool getMotorEncoderAccelerations(double *accs) override
Read the instantaneous acceleration of all motor encoders.
bool setMotorEncoderCountsPerRevolution(int m, const double cpr) override
Sets number of counts per revolution for motor encoder m.
ImplementMotorEncoders(yarp::dev::IMotorEncodersRaw *y)
bool getMotorEncodersTimed(double *encs, double *time) override
Read the instantaneous position of all motor encoders.
bool uninitialize()
Clean up internal data and memory.
bool getMotorEncoderSpeeds(double *spds) override
Read the instantaneous speed of all motor encoders.
bool getMotorEncoderTimed(int m, double *v, double *t) override
Read the instantaneous position of a motor encoder.
bool getMotorEncoder(int m, double *v) override
Read the value of a motor encoder.
bool getMotorEncoderSpeed(int m, double *spds) override
Read the istantaneous speed of a motor encoder.
bool setMotorEncoder(int m, const double val) override
Set the value of the motor encoder for a given motor.
yarp::dev::impl::FixedSizeBuffersManager< double > * buffManager
bool getMotorEncoderAcceleration(int m, double *spds) override
Read the instantaneous acceleration of a motor encoder.
bool setMotorEncoders(const double *vals) override
Set the value of all motor encoders.
bool getMotorEncoderCountsPerRevolution(int m, double *cpr) override
Gets number of counts per revolution for motor encoder m.
bool resetMotorEncoder(int m) override
Reset motor encoder, single motor.
bool resetMotorEncoders() override
Reset motor encoders.
bool getMotorEncoders(double *encs) override
Read the position of all motor encoders.
bool getNumberOfMotorEncoders(int *num) override
Get the number of available motor encoders.
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
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.