YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
ImplementAmplifierControl.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-FileCopyrightText: 2006-2010 RobotCub Consortium
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
10
11#include <cmath>
12
13// Be careful: this file contains template implementations and is included by translation
14// units that use the template (e.g. .cpp files). Avoid putting here non-template functions to
15// avoid multiple definitions.
16
17using namespace yarp::dev;
18
19namespace {
20YARP_LOG_COMPONENT(IMPLEMENT_LAYER_COMPONENT, "yarp.ImplementAmplifierControl")
21}
22
28
33
34bool ImplementAmplifierControl:: initialize (int size, const int *amap, const double *enc, const double *zos, const double *ampereFactor, const double *voltFactor)
35{
36 if (m_helper != nullptr) {
37 return false;
38 }
39
40 m_helper=(void *)(new ControlBoardHelper(size, amap, enc, zos,nullptr, ampereFactor, voltFactor));
41 yAssert (m_helper != nullptr);
42
43 m_buffer_ints.resize (size);
44 m_buffer_doubles.resize(size);
45
46 return true;
47}
48
54{
55 if (m_helper != nullptr) {
56 delete castToMapper(m_helper);
57 }
58
59 m_helper=nullptr;
60 return true;
61}
62
64{
65 std::lock_guard lock(m_imp_mutex);
66 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,j)
67
68 int k=castToMapper(m_helper)->toHw(j);
69
70 return m_iraw->enableAmpRaw(k);
71}
72
74{
75 std::lock_guard lock(m_imp_mutex);
76 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,j)
77
78 int k=castToMapper(m_helper)->toHw(j);
79
80 return m_iraw->disableAmpRaw(k);
81}
82
84{
85 std::lock_guard lock(m_imp_mutex);
86 POINTERCHECK(IMPLEMENT_LAYER_COMPONENT,currs)
87
90 return ret;
91}
92
94{
95 std::lock_guard lock(m_imp_mutex);
96 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,j)
97 POINTERCHECK(IMPLEMENT_LAYER_COMPONENT,c)
98
99 double temp = 0;
100 int k = castToMapper(m_helper)->toHw(j);
101 ReturnValue ret = m_iraw->getCurrentRaw(k, &temp);
102 castToMapper(m_helper)->ampereS2A(temp, k, *c, j);
103 return ret;
104}
105
107{
108 std::lock_guard lock(m_imp_mutex);
109 POINTERCHECK(IMPLEMENT_LAYER_COMPONENT,st)
110
113
114 return ret;
115}
116
118{
119 std::lock_guard lock(m_imp_mutex);
120 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,k)
121 POINTERCHECK(IMPLEMENT_LAYER_COMPONENT,st)
122
123 int j=castToMapper(m_helper)->toHw(k);
125
126 return ret;
127}
128
130{
131 std::lock_guard lock(m_imp_mutex);
132 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,m)
133
134 int k;
135 double curr;
136 castToMapper(m_helper)->ampereA2S(v, m, curr, k);
137 return m_iraw->setMaxCurrentRaw(k, curr);
138}
139
141{
142 std::lock_guard lock(m_imp_mutex);
143 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,j)
144 POINTERCHECK(IMPLEMENT_LAYER_COMPONENT,v)
145
146 double val;
147 int k=castToMapper(m_helper)->toHw(j);
148 ReturnValue ret = m_iraw->getMaxCurrentRaw(k, &val);
149 *v = castToMapper(m_helper)->ampereS2A(val, k);
150 return ret;
151}
152
154{
155 std::lock_guard lock(m_imp_mutex);
156 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,m)
157 POINTERCHECK(IMPLEMENT_LAYER_COMPONENT,curr)
158
159 int k;
160 ReturnValue ret;
161 double tmp;
162
164 ret=m_iraw->getNominalCurrentRaw(k, &tmp);
165 *curr=castToMapper(m_helper)->ampereS2A(tmp, k);
166 return ret;
167}
168
170{
171 std::lock_guard lock(m_imp_mutex);
172 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,m)
173 POINTERCHECK(IMPLEMENT_LAYER_COMPONENT,curr)
174
175 int k;
176 ReturnValue ret;
177 double tmp;
178
180 ret=m_iraw->getPeakCurrentRaw(k, &tmp);
181 *curr=castToMapper(m_helper)->ampereS2A(tmp, k);
182 return ret;
183}
184
186{
187 std::lock_guard lock(m_imp_mutex);
188 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,m)
189
190 int k;
191 double val;
192 castToMapper(m_helper)->ampereA2S(curr, m, val, k);
193 return m_iraw->setPeakCurrentRaw(k, val);
194}
195
197{
198 std::lock_guard lock(m_imp_mutex);
199 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,m)
200
201 int k;
202 double val;
203 castToMapper(m_helper)->ampereA2S(curr, m, val, k);
204 return m_iraw->setNominalCurrentRaw(k, val);
205}
206
208{
209 std::lock_guard lock(m_imp_mutex);
210 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,m)
211 POINTERCHECK(IMPLEMENT_LAYER_COMPONENT,pwm)
212
213 int k;
215 return m_iraw->getPWMRaw(k, pwm);
216}
217
219{
220 std::lock_guard lock(m_imp_mutex);
221 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,m)
222 POINTERCHECK(IMPLEMENT_LAYER_COMPONENT,limit)
223
224 int k;
226 return m_iraw->getPWMLimitRaw(k, limit);
227}
228
230{
231 std::lock_guard lock(m_imp_mutex);
232 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,m)
233
234 int k;
236 return m_iraw->setPWMLimitRaw(k, limit);
237}
238
240{
241 std::lock_guard lock(m_imp_mutex);
242 JOINTIDCHECK(IMPLEMENT_LAYER_COMPONENT,m)
243 POINTERCHECK(IMPLEMENT_LAYER_COMPONENT,voltage)
244
245 int k;
247 return m_iraw->getPowerSupplyVoltageRaw(k, voltage);
248}
yarp::dev::ControlBoardHelper * castToMapper(void *p)
#define yAssert(x)
Definition Log.h:388
void ampereA2S(double ampere, int j, double &sens, int &k)
void ampereS2A(const double *sens, double *ampere)
Interface for control devices, amplifier commands.
virtual yarp::dev::ReturnValue setMaxCurrentRaw(int j, double v)=0
virtual yarp::dev::ReturnValue getPowerSupplyVoltageRaw(int j, double *val)=0
virtual yarp::dev::ReturnValue disableAmpRaw(int j)=0
Disable the amplifier on a specific joint.
virtual yarp::dev::ReturnValue setPWMLimitRaw(int j, const double val)=0
virtual yarp::dev::ReturnValue setNominalCurrentRaw(int m, const double val)=0
virtual yarp::dev::ReturnValue getMaxCurrentRaw(int j, double *v)=0
Returns the maximum electric current allowed for a given motor.
virtual yarp::dev::ReturnValue getCurrentRaw(int j, double *val)=0
virtual yarp::dev::ReturnValue getPeakCurrentRaw(int m, double *val)=0
virtual yarp::dev::ReturnValue setPeakCurrentRaw(int m, const double val)=0
virtual yarp::dev::ReturnValue getPWMRaw(int j, double *val)=0
virtual yarp::dev::ReturnValue enableAmpRaw(int j)=0
Enable the amplifier on a specific joint.
virtual yarp::dev::ReturnValue getAmpStatusRaw(int *st)=0
virtual yarp::dev::ReturnValue getCurrentsRaw(double *vals)=0
virtual yarp::dev::ReturnValue getNominalCurrentRaw(int m, double *val)=0
virtual yarp::dev::ReturnValue getPWMLimitRaw(int j, double *val)=0
yarp::dev::ReturnValue disableAmp(int j) override
Disable the amplifier on a specific joint.
yarp::dev::ReturnValue getPWM(int j, double *val) override
yarp::dev::ReturnValue getPWMLimit(int j, double *val) override
yarp::dev::ReturnValue setPeakCurrent(int m, const double val) override
yarp::dev::ReturnValue setNominalCurrent(int m, const double val) override
bool initialize(int size, const int *amap, const double *enc, const double *zos, const double *ampereFactor=NULL, const double *voltFactor=NULL)
Initialize the internal data and alloc memory.
yarp::dev::ReturnValue getCurrent(int j, double *val) override
yarp::dev::ReturnValue getPowerSupplyVoltage(int j, double *val) override
yarp::dev::ReturnValue setMaxCurrent(int j, double v) override
yarp::dev::ReturnValue enableAmp(int j) override
Enable the amplifier on a specific joint.
yarp::dev::ReturnValue getAmpStatus(int *st) override
bool uninitialize()
Clean up internal data and memory.
ImplementAmplifierControl(yarp::dev::IAmplifierControlRaw *y)
yarp::dev::ReturnValue getCurrents(double *vals) override
yarp::dev::ReturnValue getPeakCurrent(int m, double *val) override
yarp::dev::ReturnValue getMaxCurrent(int j, double *v) override
Returns the maximum electric current allowed for a given motor.
yarp::dev::ReturnValue getNominalCurrent(int m, double *val) override
yarp::dev::ReturnValue setPWMLimit(int j, const double val) override
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.