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::ImplementAmplifierControl::getPWMLimit
bool getPWMLimit(int j, double *val) override
Definition: ImplementAmplifierControl.cpp:177
yarp::dev::IAmplifierControlRaw::enableAmpRaw
virtual bool enableAmpRaw(int j)=0
Enable the amplifier on a specific joint.
yarp::dev::ControlBoardHelper::toHw
int toHw(int axis)
Definition: ControlBoardHelper.cpp:245
yarp::dev::ControlBoardHelper::toUser
int toUser(int axis)
Definition: ControlBoardHelper.cpp:248
yarp::dev::IAmplifierControlRaw::setNominalCurrentRaw
virtual bool setNominalCurrentRaw(int m, const double val)
Definition: IAmplifierControl.h:264
yarp::dev::IAmplifierControlRaw::setPWMLimitRaw
virtual bool setPWMLimitRaw(int j, const double val)
Definition: IAmplifierControl.h:310
yarp::dev::ControlBoardHelper::ampereS2A
void ampereS2A(const double *sens, double *ampere)
Definition: ControlBoardHelper.cpp:606
yarp::dev::IAmplifierControlRaw::getAmpStatusRaw
virtual bool getAmpStatusRaw(int *st)=0
yarp::dev::ImplementAmplifierControl::setNominalCurrent
bool setNominalCurrent(int m, const double val) override
Definition: ImplementAmplifierControl.cpp:162
yarp::dev::ImplementAmplifierControl::ImplementAmplifierControl
ImplementAmplifierControl(yarp::dev::IAmplifierControlRaw *y)
Definition: ImplementAmplifierControl.cpp:21
yarp::dev::ImplementAmplifierControl::dTemp
double * dTemp
Definition: ImplementAmplifierControl.h:28
yarp::dev::IAmplifierControlRaw::getCurrentsRaw
virtual bool getCurrentsRaw(double *vals)=0
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::ImplementAmplifierControl::uninitialize
bool uninitialize()
Clean up internal data and memory.
Definition: ImplementAmplifierControl.cpp:53
yarp::dev::ImplementAmplifierControl::getCurrent
bool getCurrent(int j, double *val) override
Definition: ImplementAmplifierControl.cpp:88
yarp::dev::ImplementAmplifierControl::setMaxCurrent
bool setMaxCurrent(int j, double v) override
Definition: ImplementAmplifierControl.cpp:113
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
yarp::dev::ImplementAmplifierControl::iTemp
int * iTemp
Definition: ImplementAmplifierControl.h:29
ImplementAmplifierControl.h
yarp::dev::ImplementAmplifierControl::getPowerSupplyVoltage
bool getPowerSupplyVoltage(int j, double *val) override
Definition: ImplementAmplifierControl.cpp:191
yarp::dev::ImplementAmplifierControl::getCurrents
bool getCurrents(double *vals) override
Definition: ImplementAmplifierControl.cpp:81
yarp::dev::IAmplifierControlRaw::getMaxCurrentRaw
virtual bool getMaxCurrentRaw(int j, double *v)=0
Returns the maximum electric current allowed for a given motor.
yarp::dev::ImplementAmplifierControl::disableAmp
bool disableAmp(int j) override
Disable the amplifier on a specific joint.
Definition: ImplementAmplifierControl.cpp:74
yarp::dev::ImplementAmplifierControl::getNominalCurrent
bool getNominalCurrent(int m, double *val) override
Definition: ImplementAmplifierControl.cpp:130
ControlBoardHelper.h
yarp::dev::ImplementAmplifierControl::getAmpStatus
bool getAmpStatus(int *st) override
Definition: ImplementAmplifierControl.cpp:97
yarp::dev::IAmplifierControlRaw::getPowerSupplyVoltageRaw
virtual bool getPowerSupplyVoltageRaw(int j, double *val)
Definition: IAmplifierControl.h:317
yarp::dev::ImplementAmplifierControl::setPeakCurrent
bool setPeakCurrent(int m, const double val) override
Definition: ImplementAmplifierControl.cpp:154
yarp::dev::ImplementAmplifierControl::getMaxCurrent
bool getMaxCurrent(int j, double *v) override
Returns the maximum electric current allowed for a given motor.
Definition: ImplementAmplifierControl.cpp:121
yarp::dev::ImplementAmplifierControl::iAmplifier
IAmplifierControlRaw * iAmplifier
Definition: ImplementAmplifierControl.h:26
yarp::dev::IAmplifierControlRaw::getPWMRaw
virtual bool getPWMRaw(int j, double *val)
Definition: IAmplifierControl.h:294
yarp::dev::ImplementAmplifierControl::enableAmp
bool enableAmp(int j) override
Enable the amplifier on a specific joint.
Definition: ImplementAmplifierControl.cpp:67
yarp::dev::ImplementAmplifierControl::getPeakCurrent
bool getPeakCurrent(int m, double *val) override
Definition: ImplementAmplifierControl.cpp:142
yarp::dev::IAmplifierControlRaw::getCurrentRaw
virtual bool getCurrentRaw(int j, double *val)=0
yarp::dev::IAmplifierControlRaw::setPeakCurrentRaw
virtual bool setPeakCurrentRaw(int m, const double val)
Definition: IAmplifierControl.h:286
castToMapper
yarp::dev::ControlBoardHelper * castToMapper(void *p)
Definition: ControlBoardHelper.h:180
yarp::dev::ControlBoardHelper
Definition: ControlBoardHelper.h:60
yarp::dev::IAmplifierControlRaw::getPWMLimitRaw
virtual bool getPWMLimitRaw(int j, double *val)
Definition: IAmplifierControl.h:302
yarp::dev::IAmplifierControlRaw::disableAmpRaw
virtual bool disableAmpRaw(int j)=0
Disable the amplifier on a specific joint.
yarp::dev::ImplementAmplifierControl::helper
void * helper
Definition: ImplementAmplifierControl.h:27
yarp::dev::IAmplifierControlRaw::getPeakCurrentRaw
virtual bool getPeakCurrentRaw(int m, double *val)
Definition: IAmplifierControl.h:275
yarp::dev::ImplementAmplifierControl::setPWMLimit
bool setPWMLimit(int j, const double val) override
Definition: ImplementAmplifierControl.cpp:184
yarp::dev::IAmplifierControlRaw
Interface for control devices, amplifier commands.
Definition: IAmplifierControl.h:179
yarp::dev::IAmplifierControlRaw::getNominalCurrentRaw
virtual bool getNominalCurrentRaw(int m, double *val)
Definition: IAmplifierControl.h:253
yAssert
#define yAssert(x)
Definition: Log.h:297
yarp::dev::ImplementAmplifierControl::~ImplementAmplifierControl
virtual ~ImplementAmplifierControl()
Destructor.
Definition: ImplementAmplifierControl.cpp:29
yarp::dev::ImplementAmplifierControl::initialize
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.
Definition: ImplementAmplifierControl.cpp:34
yarp::dev::IAmplifierControlRaw::setMaxCurrentRaw
virtual bool setMaxCurrentRaw(int j, double v)=0
yarp::dev::ImplementAmplifierControl::getPWM
bool getPWM(int j, double *val) override
Definition: ImplementAmplifierControl.cpp:170