YARP
Yet Another Robot Platform
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
9
10#include <cmath>
11
12// Be careful: this file contains template implementations and is included by translation
13// units that use the template (e.g. .cpp files). Avoid putting here non-template functions to
14// avoid multiple definitions.
15
16using namespace yarp::dev;
17
18ImplementAmplifierControl::ImplementAmplifierControl(yarp::dev::IAmplifierControlRaw *y)
19{
20 iAmplifier= y;
21 helper = nullptr;
22 dTemp=nullptr;
23 iTemp=nullptr;
24}
25
27{
29}
30
31bool ImplementAmplifierControl:: initialize (int size, const int *amap, const double *enc, const double *zos, const double *ampereFactor, const double *voltFactor)
32{
33 if (helper != nullptr) {
34 return false;
35 }
36
37 helper=(void *)(new ControlBoardHelper(size, amap, enc, zos,nullptr, ampereFactor, voltFactor));
38 yAssert (helper != nullptr);
39 dTemp=new double[size];
40 yAssert (dTemp != nullptr);
41 iTemp=new int[size];
42 yAssert (iTemp != nullptr);
43
44 return true;
45}
46
52{
53 if (helper != nullptr) {
54 delete castToMapper(helper);
55 }
56
57 delete [] dTemp;
58 delete [] iTemp;
59
60 helper=nullptr;
61 dTemp=nullptr;
62 iTemp=nullptr;
63 return true;
64}
65
67{
68 int k=castToMapper(helper)->toHw(j);
69
70 return iAmplifier->enableAmpRaw(k);
71}
72
74{
75 int k=castToMapper(helper)->toHw(j);
76
77 return iAmplifier->disableAmpRaw(k);
78}
79
81{
84 return ret;
85}
86
88{
89 double temp = 0;
90 int k = castToMapper(helper)->toHw(j);
91 bool ret = iAmplifier->getCurrentRaw(k, &temp);
92 castToMapper(helper)->ampereS2A(temp, k, *c, j);
93 return ret;
94}
95
97{
100
101 return ret;
102}
103
105{
106 int j=castToMapper(helper)->toHw(k);
107 bool ret=iAmplifier->getAmpStatusRaw(j, st);
108
109 return ret;
110}
111
113{
114 int k;
115 double curr;
116 castToMapper(helper)->ampereA2S(v, m, curr, k);
117 return iAmplifier->setMaxCurrentRaw(k, curr);
118}
119
121{
122 double val;
123 int k=castToMapper(helper)->toHw(j);
124 bool ret = iAmplifier->getMaxCurrentRaw(k, &val);
125 *v = castToMapper(helper)->ampereS2A(val, k);
126 return ret;
127}
128
130{
131 int k;
132 bool ret;
133 double tmp;
134
135 k=castToMapper(helper)->toHw(m);
137 *curr=castToMapper(helper)->ampereS2A(tmp, k);
138 return ret;
139}
140
142{
143 int k;
144 bool ret;
145 double tmp;
146
147 k=castToMapper(helper)->toHw(m);
149 *curr=castToMapper(helper)->ampereS2A(tmp, k);
150 return ret;
151}
152
153bool ImplementAmplifierControl::setPeakCurrent(int m, const double curr)
154{
155 int k;
156 double val;
157 castToMapper(helper)->ampereA2S(curr, m, val, k);
158 return iAmplifier->setPeakCurrentRaw(k, val);
159}
160
162{
163 int k;
164 double val;
165 castToMapper(helper)->ampereA2S(curr, m, val, k);
166 return iAmplifier->setNominalCurrentRaw(k, val);
167}
168
169bool ImplementAmplifierControl::getPWM(int m, double* pwm)
170{
171 int k;
172 k=castToMapper(helper)->toHw(m);
173 return iAmplifier->getPWMRaw(k, pwm);
174}
175
177{
178 int k;
179 k=castToMapper(helper)->toHw(m);
180 return iAmplifier->getPWMLimitRaw(k, limit);
181}
182
183bool ImplementAmplifierControl::setPWMLimit(int m, const double limit)
184{
185 int k;
186 k=castToMapper(helper)->toHw(m);
187 return iAmplifier->setPWMLimitRaw(k, limit);
188}
189
191{
192 int k;
193 k=castToMapper(helper)->toHw(m);
194 return iAmplifier->getPowerSupplyVoltageRaw(k, voltage);
195}
yarp::dev::ControlBoardHelper * castToMapper(void *p)
bool ret
#define yAssert(x)
Definition: Log.h:383
void ampereA2S(double ampere, int j, double &sens, int &k)
void ampereS2A(const double *sens, double *ampere)
Interface for control devices, amplifier commands.
virtual bool setMaxCurrentRaw(int j, double v)=0
virtual bool getPeakCurrentRaw(int m, double *val)
virtual bool getCurrentsRaw(double *vals)=0
virtual bool disableAmpRaw(int j)=0
Disable the amplifier on a specific joint.
virtual bool setNominalCurrentRaw(int m, const double val)
virtual bool getPowerSupplyVoltageRaw(int j, double *val)
virtual bool getAmpStatusRaw(int *st)=0
virtual bool getMaxCurrentRaw(int j, double *v)=0
Returns the maximum electric current allowed for a given motor.
virtual bool getPWMLimitRaw(int j, double *val)
virtual bool getPWMRaw(int j, double *val)
virtual bool enableAmpRaw(int j)=0
Enable the amplifier on a specific joint.
virtual bool getCurrentRaw(int j, double *val)=0
virtual bool getNominalCurrentRaw(int m, double *val)
virtual bool setPWMLimitRaw(int j, const double val)
virtual bool setPeakCurrentRaw(int m, const double val)
bool setPeakCurrent(int m, const double val) override
bool setNominalCurrent(int m, const double val) override
bool setMaxCurrent(int j, double v) override
bool getCurrent(int j, 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.
bool enableAmp(int j) override
Enable the amplifier on a specific joint.
bool getNominalCurrent(int m, double *val) override
bool getPeakCurrent(int m, double *val) override
bool getPowerSupplyVoltage(int j, double *val) override
bool disableAmp(int j) override
Disable the amplifier on a specific joint.
bool getPWM(int j, double *val) override
bool getMaxCurrent(int j, double *v) override
Returns the maximum electric current allowed for a given motor.
bool uninitialize()
Clean up internal data and memory.
bool setPWMLimit(int j, const double val) override
bool getPWMLimit(int j, double *val) override
For streams capable of holding different kinds of content, check what they actually have.