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