YARP
Yet Another Robot Platform
ImplementAmplifierControl.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 {
23  iAmplifier= y;
24  helper = nullptr;
25  dTemp=nullptr;
26  iTemp=nullptr;
27 }
28 
30 {
31  uninitialize();
32 }
33 
34 bool ImplementAmplifierControl:: initialize (int size, const int *amap, const double *enc, const double *zos, const double *ampereFactor, const double *voltFactor)
35 {
36  if (helper!=nullptr)
37  return false;
38 
39  helper=(void *)(new ControlBoardHelper(size, amap, enc, zos,nullptr, ampereFactor, voltFactor));
40  yAssert (helper != nullptr);
41  dTemp=new double[size];
42  yAssert (dTemp != nullptr);
43  iTemp=new int[size];
44  yAssert (iTemp != nullptr);
45 
46  return true;
47 }
48 
54 {
55  if (helper!=nullptr)
56  delete castToMapper(helper);
57 
58  delete [] dTemp;
59  delete [] iTemp;
60 
61  helper=nullptr;
62  dTemp=nullptr;
63  iTemp=nullptr;
64  return true;
65 }
66 
68 {
69  int k=castToMapper(helper)->toHw(j);
70 
71  return iAmplifier->enableAmpRaw(k);
72 }
73 
75 {
76  int k=castToMapper(helper)->toHw(j);
77 
78  return iAmplifier->disableAmpRaw(k);
79 }
80 
82 {
85  return ret;
86 }
87 
89 {
90  double temp = 0;
91  int k = castToMapper(helper)->toHw(j);
92  bool ret = iAmplifier->getCurrentRaw(k, &temp);
93  castToMapper(helper)->ampereS2A(temp, k, *c, j);
94  return ret;
95 }
96 
98 {
101 
102  return ret;
103 }
104 
106 {
107  int j=castToMapper(helper)->toHw(k);
108  bool ret=iAmplifier->getAmpStatusRaw(j, st);
109 
110  return ret;
111 }
112 
114 {
115  int k;
116  double curr;
117  castToMapper(helper)->ampereA2S(v, m, curr, k);
118  return iAmplifier->setMaxCurrentRaw(k, curr);
119 }
120 
122 {
123  double val;
124  int k=castToMapper(helper)->toHw(j);
125  bool ret = iAmplifier->getMaxCurrentRaw(k, &val);
126  *v = castToMapper(helper)->ampereS2A(val, k);
127  return ret;
128 }
129 
131 {
132  int k;
133  bool ret;
134  double tmp;
135 
136  k=castToMapper(helper)->toHw(m);
138  *curr=castToMapper(helper)->ampereS2A(tmp, k);
139  return ret;
140 }
141 
143 {
144  int k;
145  bool ret;
146  double tmp;
147 
148  k=castToMapper(helper)->toHw(m);
149  ret=iAmplifier->getPeakCurrentRaw(k, &tmp);
150  *curr=castToMapper(helper)->ampereS2A(tmp, k);
151  return ret;
152 }
153 
154 bool ImplementAmplifierControl::setPeakCurrent(int m, const double curr)
155 {
156  int k;
157  double val;
158  castToMapper(helper)->ampereA2S(curr, m, val, k);
159  return iAmplifier->setPeakCurrentRaw(k, val);
160 }
161 
162 bool ImplementAmplifierControl::setNominalCurrent(int m, const double curr)
163 {
164  int k;
165  double val;
166  castToMapper(helper)->ampereA2S(curr, m, val, k);
167  return iAmplifier->setNominalCurrentRaw(k, val);
168 }
169 
170 bool ImplementAmplifierControl::getPWM(int m, double* pwm)
171 {
172  int k;
173  k=castToMapper(helper)->toHw(m);
174  return iAmplifier->getPWMRaw(k, pwm);
175 }
176 
177 bool ImplementAmplifierControl::getPWMLimit(int m, double* limit)
178 {
179  int k;
180  k=castToMapper(helper)->toHw(m);
181  return iAmplifier->getPWMLimitRaw(k, limit);
182 }
183 
184 bool ImplementAmplifierControl::setPWMLimit(int m, const double limit)
185 {
186  int k;
187  k=castToMapper(helper)->toHw(m);
188  return iAmplifier->setPWMLimitRaw(k, limit);
189 }
190 
192 {
193  int k;
194  k=castToMapper(helper)->toHw(m);
195  return iAmplifier->getPowerSupplyVoltageRaw(k, voltage);
196 }
yarp::dev::ControlBoardHelper * castToMapper(void *p)
bool ret
#define yAssert(x)
Definition: Log.h:297
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.
ImplementAmplifierControl(yarp::dev::IAmplifierControlRaw *y)
bool setPWMLimit(int j, const double val) override
bool getPWMLimit(int j, double *val) override
An interface for the device drivers.