YARP
Yet Another Robot Platform
ImplementMotorEncoders.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 
17 #define JOINTIDCHECK if (m >= castToMapper(helper)->axes()){yError("motor id out of bound"); return false;}
18 
20 // Encoder Interface Timed Implementation
22  iMotorEncoders(y),
23  helper(nullptr),
24  buffManager(nullptr)
25 {;}
26 
28 {
29  uninitialize();
30 }
31 
32 bool ImplementMotorEncoders:: initialize (int size, const int *amap, const double *enc, const double *zos)
33 {
34  if (helper!=nullptr)
35  return false;
36 
37  helper=(void *)(new ControlBoardHelper(size, amap, enc, zos));
38  yAssert (helper != nullptr);
39 
41  yAssert (buffManager != nullptr);
42  return true;
43 }
44 
50 {
51  if (helper!=nullptr)
52  {
53  delete castToMapper(helper);
54  helper=nullptr;
55  }
56 
57  if(buffManager)
58  {
59  delete buffManager;
60  buffManager=nullptr;
61  }
62 
63  return true;
64 }
65 
67 {
68  (*num)=castToMapper(helper)->axes();
69  return true;
70 }
71 
73 {
75  int k;
76  k=castToMapper(helper)->toHw(m);
77 
79 }
80 
82 {
84 }
85 
86 bool ImplementMotorEncoders::setMotorEncoder(int m, const double val)
87 {
89  int k;
90  double enc;
91 
92  castToMapper(helper)->posA2E(val, m, enc, k);
93 
94  return iMotorEncoders->setMotorEncoderRaw(k, enc);
95 }
96 
98 {
100  bool ret;
101  int k=castToMapper(helper)->toHw(m);
102 
104 
105  return ret;
106 }
107 
109 {
111  int k;
112 
113  k=castToMapper(helper)->toHw(m);
114 
116 }
117 
119 {
121  castToMapper(helper)->posA2E(val, buffValues.getData());
122 
123  bool ret = iMotorEncoders->setMotorEncodersRaw(buffValues.getData());
124  buffManager->releaseBuffer(buffValues);
125  return ret;
126 }
127 
129 {
131  int k;
132  double enc;
133  bool ret;
134 
135  k=castToMapper(helper)->toHw(m);
136 
138 
139  *v=castToMapper(helper)->posE2A(enc, k);
140 
141  return ret;
142 }
143 
145 {
147  bool ret=iMotorEncoders->getMotorEncodersRaw(buffValues.getData());
148  castToMapper(helper)->posE2A(buffValues.getData(), v);
149  buffManager->releaseBuffer(buffValues);
150  return ret;
151 }
152 
154 {
156  int k;
157  double enc;
158  bool ret;
159 
160  k=castToMapper(helper)->toHw(m);
161 
163 
164  *v=castToMapper(helper)->velE2A(enc, k);
165 
166  return ret;
167 }
168 
170 {
173  castToMapper(helper)->velE2A(buffValues.getData(), v);
174  buffManager->releaseBuffer(buffValues);
175  return ret;
176 }
177 
179 {
181  int k;
182  double enc;
183  bool ret;
184 
185  k=castToMapper(helper)->toHw(m);
186 
188 
189  *v=castToMapper(helper)->accE2A(enc, k);
190 
191  return ret;
192 }
193 
195 {
198  castToMapper(helper)->accE2A(buffValues.getData(), v);
199  buffManager->releaseBuffer(buffValues);
200  return ret;
201 }
202 
203 bool ImplementMotorEncoders::getMotorEncoderTimed(int m, double *v, double *t)
204 {
206  int k;
207  double enc;
208  bool ret;
209 
210  k=castToMapper(helper)->toHw(m);
211 
213 
214  *v=castToMapper(helper)->posE2A(enc, k);
215 
216  return ret;
217 }
218 
219 
221 {
225  castToMapper(helper)->posE2A(b_v.getData(), v);
226  castToMapper(helper)->toUser(b_t.getData(), t);
229  return ret;
230 }
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)
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.