YARP
Yet Another Robot Platform
ImplementCurrentControl.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 (j >= castToMapper(helper)->axes()){yError("joint id out of bound"); return false;}
18 
20  iCurrentRaw(tq),
21  helper(nullptr),
22  intBuffManager(nullptr),
23  doubleBuffManager(nullptr)
24 {;}
25 
27 {
28  uninitialize();
29 }
30 
31 bool ImplementCurrentControl::initialize(int size, const int *amap, const double* ampsToSens)
32 {
33  if (helper!=nullptr)
34  return false;
35 
37  yAssert (intBuffManager != nullptr);
38 
40  yAssert (doubleBuffManager != nullptr);
41 
42  helper = (void *)(new ControlBoardHelper(size, amap, nullptr, nullptr, nullptr, ampsToSens, nullptr, nullptr));
43  yAssert (helper != nullptr);
44 
45  return true;
46 }
47 
49 {
50  if (helper!=nullptr)
51  {
52  delete castToMapper(helper);
53  helper=nullptr;
54  }
55 
56  if(intBuffManager)
57  {
58  delete intBuffManager;
59  intBuffManager=nullptr;
60  }
61 
63  {
64  delete doubleBuffManager;
65  doubleBuffManager=nullptr;
66  }
67 
68  return true;
69 }
70 
72 {
73  return iCurrentRaw->getNumberOfMotorsRaw(axes);
74 }
75 
77 {
79  int k;
80  bool ret;
81  double current;
82  k=castToMapper(helper)->toHw(j);
83  ret = iCurrentRaw->getRefCurrentRaw(k, &current);
84  *r = castToMapper(helper)->ampereS2A(current, k);
85  return ret;
86 }
87 
89 {
91  bool ret = iCurrentRaw->getRefCurrentsRaw(buffValues.getData());
92  castToMapper(helper)->ampereS2A(buffValues.getData(),t);
93  doubleBuffManager->releaseBuffer(buffValues);
94  return ret;
95 }
96 
98 {
100  castToMapper(helper)->ampereA2S(t, buffValues.getData());
101  bool ret = iCurrentRaw->setRefCurrentsRaw(buffValues.getData());
102  doubleBuffManager->releaseBuffer(buffValues);
103  return ret;
104 }
105 
107 {
109  int k;
110  double sens;
111  castToMapper(helper)->ampereA2S(t,j,sens,k);
112  return iCurrentRaw->setRefCurrentRaw(k, sens);
113 }
114 
116 {
118  bool ret = iCurrentRaw->getCurrentsRaw(buffValues.getData());
119  castToMapper(helper)->ampereS2A(buffValues.getData(), t);
120  doubleBuffManager->releaseBuffer(buffValues);
121  return ret;
122 }
123 
124 bool ImplementCurrentControl::setRefCurrents(const int n_joint, const int *joints, const double *t)
125 {
126  if(!castToMapper(helper)->checkAxesIds(n_joint, joints))
127  return false;
128 
131 
132  for(int idx=0; idx<n_joint; idx++)
133  {
134  buffJoints[idx] = castToMapper(helper)->toHw(joints[idx]);
135  buffValues[idx] = castToMapper(helper)->ampereA2S(t[idx], joints[idx]);
136  }
137 
138  bool ret = iCurrentRaw->setRefCurrentsRaw(n_joint, buffJoints.getData(), buffValues.getData());
139 
140  doubleBuffManager->releaseBuffer(buffValues);
141  intBuffManager->releaseBuffer(buffJoints);
142  return ret;
143 }
144 
146 {
148  int k;
149  bool ret;
150  double current;
151  k=castToMapper(helper)->toHw(j);
152  ret = iCurrentRaw->getCurrentRaw(k, &current);
153  *t = castToMapper(helper)->ampereS2A(current, k);
154  return ret;
155 }
156 
157 bool ImplementCurrentControl::getCurrentRanges(double *min, double *max)
158 {
161  bool ret = iCurrentRaw->getCurrentRangesRaw(b_min.getData(), b_max.getData());
162  castToMapper(helper)->ampereS2A(b_min.getData(), min);
163  castToMapper(helper)->ampereS2A(b_max.getData(), max);
166  return ret;
167 }
168 
169 bool ImplementCurrentControl::getCurrentRange(int j, double *min, double *max)
170 {
172  int k;
173  k=castToMapper(helper)->toHw(j);
174  double min_t, max_t;
175  bool ret = iCurrentRaw->getCurrentRangeRaw(k, &min_t, &max_t);
176  *min = castToMapper(helper)->ampereS2A(min_t, k);
177  *max = castToMapper(helper)->ampereS2A(max_t, k);
178  return ret;
179 }
yarp::dev::ControlBoardHelper::toHw
int toHw(int axis)
Definition: ControlBoardHelper.cpp:245
yarp::dev::ICurrentControlRaw::getRefCurrentsRaw
virtual bool getRefCurrentsRaw(double *currs)=0
Get the reference value of the currents for all motors.
yarp::dev::ImplementCurrentControl::helper
void * helper
Definition: ImplementCurrentControl.h:36
t
float t
Definition: FfmpegWriter.cpp:74
yarp::dev::ImplementCurrentControl::setRefCurrents
bool setRefCurrents(const double *t) override
Set the reference value of the currents for all motors.
Definition: ImplementCurrentControl.cpp:97
yarp::dev::ICurrentControlRaw::getCurrentRangeRaw
virtual bool getCurrentRangeRaw(int m, double *min, double *max)=0
Get the full scale of the current measurement for a given motor (e.g.
yarp::dev::ImplementCurrentControl::getRefCurrents
bool getRefCurrents(double *t) override
Get the reference value of the currents for all motors.
Definition: ImplementCurrentControl.cpp:88
yarp::dev::ICurrentControlRaw::getNumberOfMotorsRaw
virtual bool getNumberOfMotorsRaw(int *number)=0
Retrieves the number of controlled motors from the current physical interface.
yarp::dev::ControlBoardHelper::ampereS2A
void ampereS2A(const double *sens, double *ampere)
Definition: ControlBoardHelper.cpp:606
yarp::dev::impl::Buffer::getData
T * getData()
Return the data pointer.
Definition: FixedSizeBuffersManager-inl.h:29
yarp::dev::impl::FixedSizeBuffersManager< int >
yarp::dev::ImplementCurrentControl::getCurrent
bool getCurrent(int j, double *t) override
Get the instantaneous current measurement for a single motor.
Definition: ImplementCurrentControl.cpp:145
yarp::dev::ICurrentControlRaw::getCurrentRangesRaw
virtual bool getCurrentRangesRaw(double *min, double *max)=0
Get the full scale of the current measurements for all motors motor (e.g.
yarp::dev::impl::FixedSizeBuffersManager::getBuffer
Buffer< T > getBuffer()
Get a buffer and fill its information in @buffer.
Definition: FixedSizeBuffersManager-inl.h:87
yarp::dev::ICurrentControlRaw::setRefCurrentRaw
virtual bool setRefCurrentRaw(int m, double curr)=0
Set the reference value of the current for a single motor.
yarp::dev::ControlBoardHelper::ampereA2S
void ampereA2S(double ampere, int j, double &sens, int &k)
Definition: ControlBoardHelper.cpp:582
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
yarp::dev::ImplementCurrentControl::intBuffManager
yarp::dev::impl::FixedSizeBuffersManager< int > * intBuffManager
Definition: ImplementCurrentControl.h:37
yarp::dev::ImplementCurrentControl::~ImplementCurrentControl
virtual ~ImplementCurrentControl()
Destructor.
Definition: ImplementCurrentControl.cpp:26
yarp::dev::ImplementCurrentControl::iCurrentRaw
yarp::dev::ICurrentControlRaw * iCurrentRaw
Definition: ImplementCurrentControl.h:35
yarp::dev::ImplementCurrentControl::getCurrentRange
bool getCurrentRange(int j, double *min, double *max) override
Get the full scale of the current measurement for a given motor (e.g.
Definition: ImplementCurrentControl.cpp:169
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
yarp::dev::ICurrentControlRaw
Interface for control boards implementing current control.
Definition: ICurrentControl.h:114
yarp::dev::ImplementCurrentControl::getCurrentRanges
bool getCurrentRanges(double *min, double *max) override
Get the full scale of the current measurements for all motors motor (e.g.
Definition: ImplementCurrentControl.cpp:157
JOINTIDCHECK
#define JOINTIDCHECK
Definition: ImplementCurrentControl.cpp:17
yarp::dev::ICurrentControlRaw::getCurrentsRaw
virtual bool getCurrentsRaw(double *currs)=0
Get the instantaneous current measurement for all motors.
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::ICurrentControlRaw::getRefCurrentRaw
virtual bool getRefCurrentRaw(int m, double *curr)=0
Get the reference value of the current for a single motor.
yarp::dev::ImplementCurrentControl::getRefCurrent
bool getRefCurrent(int j, double *) override
Get the reference value of the current for a single motor.
Definition: ImplementCurrentControl.cpp:76
ControlBoardHelper.h
yarp::dev::ImplementCurrentControl::getNumberOfMotors
bool getNumberOfMotors(int *ax) override
Retrieves the number of controlled axes from the current physical interface.
Definition: ImplementCurrentControl.cpp:71
yarp::dev::ImplementCurrentControl::doubleBuffManager
yarp::dev::impl::FixedSizeBuffersManager< double > * doubleBuffManager
Definition: ImplementCurrentControl.h:38
yarp::dev::ImplementCurrentControl::getCurrents
bool getCurrents(double *t) override
Get the instantaneous current measurement for all motors.
Definition: ImplementCurrentControl.cpp:115
yarp::dev::impl::FixedSizeBuffersManager::releaseBuffer
void releaseBuffer(Buffer< T > &buffer)
Release a buffer.
Definition: FixedSizeBuffersManager-inl.h:156
yarp::dev::ImplementCurrentControl::initialize
bool initialize(int size, const int *amap, const double *ampsToSens)
Initialize the internal data and alloc memory.
Definition: ImplementCurrentControl.cpp:31
yarp::dev::ICurrentControlRaw::setRefCurrentsRaw
virtual bool setRefCurrentsRaw(const double *currs)=0
Set the reference value of the currents for all motors.
yarp::dev::ImplementCurrentControl::setRefCurrent
bool setRefCurrent(int j, double t) override
Set the reference value of the current for a single motor.
Definition: ImplementCurrentControl.cpp:106
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::ControlBoardHelper
Definition: ControlBoardHelper.h:60
ControlBoardInterfacesImpl.h
yarp::dev::ICurrentControlRaw::getCurrentRaw
virtual bool getCurrentRaw(int m, double *curr)=0
Get the instantaneous current measurement for a single motor.
yAssert
#define yAssert(x)
Definition: Log.h:297
yarp::dev::ImplementCurrentControl::uninitialize
bool uninitialize()
Clean up internal data and memory.
Definition: ImplementCurrentControl.cpp:48
yarp::dev::ImplementCurrentControl::ImplementCurrentControl
ImplementCurrentControl(yarp::dev::ICurrentControlRaw *y)
Definition: ImplementCurrentControl.cpp:19