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::IMotorEncodersRaw
Control board, encoder interface.
Definition: IMotorEncoders.h:28
yarp::dev::IMotorEncodersRaw::setMotorEncoderCountsPerRevolutionRaw
virtual bool setMotorEncoderCountsPerRevolutionRaw(int m, const double cpr)=0
Sets number of counts per revolution for motor encoder m.
yarp::dev::ImplementMotorEncoders::getMotorEncodersTimed
bool getMotorEncodersTimed(double *encs, double *time) override
Read the instantaneous position of all motor encoders.
Definition: ImplementMotorEncoders.cpp:220
yarp::dev::IMotorEncodersRaw::setMotorEncodersRaw
virtual bool setMotorEncodersRaw(const double *vals)=0
Set the value of all motor encoders.
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::IMotorEncodersRaw::getMotorEncoderSpeedRaw
virtual bool getMotorEncoderSpeedRaw(int m, double *sp)=0
Read the istantaneous speed of a motor encoder.
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::ImplementMotorEncoders::setMotorEncoders
bool setMotorEncoders(const double *vals) override
Set the value of all motor encoders.
Definition: ImplementMotorEncoders.cpp:118
t
float t
Definition: FfmpegWriter.cpp:74
yarp::dev::ImplementMotorEncoders::setMotorEncoder
bool setMotorEncoder(int m, const double val) override
Set the value of the motor encoder for a given motor.
Definition: ImplementMotorEncoders.cpp:86
yarp::dev::ImplementMotorEncoders::~ImplementMotorEncoders
virtual ~ImplementMotorEncoders()
Definition: ImplementMotorEncoders.cpp:27
yarp::dev::IMotorEncodersRaw::getMotorEncoderTimedRaw
virtual bool getMotorEncoderTimedRaw(int m, double *encs, double *stamp)=0
Read the instantaneous position of a motor encoder.
yarp::dev::IMotorEncodersRaw::getMotorEncoderRaw
virtual bool getMotorEncoderRaw(int m, double *v)=0
Read the value of a motor encoder.
yarp::dev::ImplementMotorEncoders::getMotorEncoderAccelerations
bool getMotorEncoderAccelerations(double *accs) override
Read the instantaneous acceleration of all motor encoders.
Definition: ImplementMotorEncoders.cpp:194
yarp::dev::impl::Buffer::getData
T * getData()
Return the data pointer.
Definition: FixedSizeBuffersManager-inl.h:29
yarp::dev::ImplementMotorEncoders::getMotorEncoderSpeeds
bool getMotorEncoderSpeeds(double *spds) override
Read the instantaneous speed of all motor encoders.
Definition: ImplementMotorEncoders.cpp:169
yarp::dev::ImplementMotorEncoders::getMotorEncoderCountsPerRevolution
bool getMotorEncoderCountsPerRevolution(int m, double *cpr) override
Gets number of counts per revolution for motor encoder m.
Definition: ImplementMotorEncoders.cpp:97
yarp::dev::impl::FixedSizeBuffersManager< double >
yarp::dev::impl::FixedSizeBuffersManager::getBuffer
Buffer< T > getBuffer()
Get a buffer and fill its information in @buffer.
Definition: FixedSizeBuffersManager-inl.h:87
yarp::dev::ImplementMotorEncoders::getMotorEncoderAcceleration
bool getMotorEncoderAcceleration(int m, double *spds) override
Read the instantaneous acceleration of a motor encoder.
Definition: ImplementMotorEncoders.cpp:178
yarp::dev::ImplementMotorEncoders::resetMotorEncoder
bool resetMotorEncoder(int m) override
Reset motor encoder, single motor.
Definition: ImplementMotorEncoders.cpp:72
yarp::dev::ImplementMotorEncoders::getNumberOfMotorEncoders
bool getNumberOfMotorEncoders(int *num) override
Get the number of available motor encoders.
Definition: ImplementMotorEncoders.cpp:66
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
yarp::dev::ImplementMotorEncoders::setMotorEncoderCountsPerRevolution
bool setMotorEncoderCountsPerRevolution(int m, const double cpr) override
Sets number of counts per revolution for motor encoder m.
Definition: ImplementMotorEncoders.cpp:108
yarp::dev::ImplementMotorEncoders::helper
void * helper
Definition: ImplementMotorEncoders.h:35
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
yarp::dev::ImplementMotorEncoders::iMotorEncoders
IMotorEncodersRaw * iMotorEncoders
Definition: ImplementMotorEncoders.h:34
yarp::dev::IMotorEncodersRaw::getMotorEncodersRaw
virtual bool getMotorEncodersRaw(double *encs)=0
Read the position of all motor encoders.
yarp::dev::IMotorEncodersRaw::getMotorEncoderAccelerationRaw
virtual bool getMotorEncoderAccelerationRaw(int m, double *spds)=0
Read the instantaneous acceleration of a motor encoder.
yarp::dev::ImplementMotorEncoders::getMotorEncoderTimed
bool getMotorEncoderTimed(int m, double *v, double *t) override
Read the instantaneous position of a motor encoder.
Definition: ImplementMotorEncoders.cpp:203
yarp::dev::ImplementMotorEncoders::getMotorEncoders
bool getMotorEncoders(double *encs) override
Read the position of all motor encoders.
Definition: ImplementMotorEncoders.cpp:144
yarp::dev::ControlBoardHelper::posA2E
void posA2E(double ang, int j, double &enc, int &k)
Definition: ControlBoardHelper.cpp:279
yarp::dev::IMotorEncodersRaw::getMotorEncoderSpeedsRaw
virtual bool getMotorEncoderSpeedsRaw(double *spds)=0
Read the instantaneous speed of all motor encoders.
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::ImplementMotorEncoders::ImplementMotorEncoders
ImplementMotorEncoders(yarp::dev::IMotorEncodersRaw *y)
Definition: ImplementMotorEncoders.cpp:21
yarp::dev::ImplementMotorEncoders::resetMotorEncoders
bool resetMotorEncoders() override
Reset motor encoders.
Definition: ImplementMotorEncoders.cpp:81
ControlBoardHelper.h
yarp::dev::IMotorEncodersRaw::resetMotorEncoderRaw
virtual bool resetMotorEncoderRaw(int m)=0
Reset motor encoder, single motor.
yarp::dev::impl::FixedSizeBuffersManager::releaseBuffer
void releaseBuffer(Buffer< T > &buffer)
Release a buffer.
Definition: FixedSizeBuffersManager-inl.h:156
yarp::dev::ImplementMotorEncoders::getMotorEncoderSpeed
bool getMotorEncoderSpeed(int m, double *spds) override
Read the istantaneous speed of a motor encoder.
Definition: ImplementMotorEncoders.cpp:153
JOINTIDCHECK
#define JOINTIDCHECK
Definition: ImplementMotorEncoders.cpp:17
yarp::dev::IMotorEncodersRaw::getMotorEncodersTimedRaw
virtual bool getMotorEncodersTimedRaw(double *encs, double *stamps)=0
Read the instantaneous position of all motor encoders.
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::IMotorEncodersRaw::getMotorEncoderCountsPerRevolutionRaw
virtual bool getMotorEncoderCountsPerRevolutionRaw(int m, double *cpr)=0
Gets number of counts per revolution for motor encoder m.
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::IMotorEncodersRaw::setMotorEncoderRaw
virtual bool setMotorEncoderRaw(int m, const double val)=0
Set the value of the motor encoder for a given motor.
yarp::dev::ControlBoardHelper::axes
int axes()
Definition: ControlBoardHelper.cpp:762
yAssert
#define yAssert(x)
Definition: Log.h:297
yarp::dev::ImplementMotorEncoders::initialize
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
Definition: ImplementMotorEncoders.cpp:32
yarp::dev::IMotorEncodersRaw::getMotorEncoderAccelerationsRaw
virtual bool getMotorEncoderAccelerationsRaw(double *accs)=0
Read the instantaneous acceleration of all motor encoders.
yarp::dev::ImplementMotorEncoders::uninitialize
bool uninitialize()
Clean up internal data and memory.
Definition: ImplementMotorEncoders.cpp:49
yarp::dev::ImplementMotorEncoders::buffManager
yarp::dev::impl::FixedSizeBuffersManager< double > * buffManager
Definition: ImplementMotorEncoders.h:36
yarp::dev::ImplementMotorEncoders::getMotorEncoder
bool getMotorEncoder(int m, double *v) override
Read the value of a motor encoder.
Definition: ImplementMotorEncoders.cpp:128
yarp::dev::IMotorEncodersRaw::resetMotorEncodersRaw
virtual bool resetMotorEncodersRaw()=0
Reset motor encoders.