YARP
Yet Another Robot Platform
ImplementControlLimits.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 
9 #include <cstdio>
10 
13 
14 using namespace yarp::dev;
15 
16 
18  iLimits2(y),
19  helper(nullptr)
20 {;}
21 
22 
24 {
25  uninitialize();
26 }
27 
33 {
34  if(helper != nullptr)
35  {
36  delete castToMapper(helper);
37  helper = nullptr;
38  }
39  return true;
40 }
41 
42 bool ImplementControlLimits::initialize(int size, const int *amap, const double *enc, const double *zos)
43 {
44  if(helper != nullptr)
45  return false;
46 
47  helper=(void *)(new ControlBoardHelper(size, amap, enc, zos));
48  yAssert(helper != nullptr);
49  return true;
50 }
51 
52 
53 bool ImplementControlLimits::setLimits(int axis, double min, double max)
54 {
55  double minEnc=0;
56  double maxEnc=0;
57 
58  int k=0;
59  castToMapper(helper)->posA2E(min, axis, minEnc, k);
60  castToMapper(helper)->posA2E(max, axis, maxEnc, k);
61 
62  if( (max > min) && (minEnc > maxEnc)) //angle to encoder conversion factor is negative
63  {
64  double temp; // exchange max and min limits
65  temp = minEnc;
66  minEnc = maxEnc;
67  maxEnc = temp;
68  }
69 
70  return iLimits2->setLimitsRaw(k, minEnc, maxEnc);
71 }
72 
73 
74 bool ImplementControlLimits::getLimits(int axis, double *min, double *max)
75 {
76  double minEnc=0;
77  double maxEnc=0;
78 
79  int k=castToMapper(helper)->toHw(axis);
80  bool ret=iLimits2->getLimitsRaw(k, &minEnc, &maxEnc);
81 
82  *min=castToMapper(helper)->posE2A(minEnc, k);
83  *max=castToMapper(helper)->posE2A(maxEnc, k);
84 
85  if( (*max < *min) && (minEnc < maxEnc)) //angle to encoder conversion factor is negative
86  {
87  double temp; // exchange max and min limits
88  temp = *min;
89  *min = *max;
90  *max = temp;
91  }
92  return ret;
93 }
94 
95 bool ImplementControlLimits::setVelLimits(int axis, double min, double max)
96 {
97  double minEnc=0;
98  double maxEnc=0;
99 
100  int k=0;
101  castToMapper(helper)->velA2E_abs(min, axis, minEnc, k);
102  castToMapper(helper)->velA2E_abs(max, axis, maxEnc, k);
103 
104  return iLimits2->setVelLimitsRaw(k, minEnc, maxEnc);
105 }
106 
107 bool ImplementControlLimits::getVelLimits(int axis, double *min, double *max)
108 {
109  double minEnc=0;
110  double maxEnc=0;
111 
112  int k=castToMapper(helper)->toHw(axis);
113  bool ret=iLimits2->getVelLimitsRaw(k, &minEnc, &maxEnc);
114 
115  *min = castToMapper(helper)->velE2A_abs(minEnc, k);
116  *max = castToMapper(helper)->velE2A_abs(maxEnc, k);
117 
118  return ret;
119 }
yarp::dev::IControlLimitsRaw::setVelLimitsRaw
virtual bool setVelLimitsRaw(int axis, double min, double max)=0
Set the software speed limits for a particular axis, the behavior of the control card when these limi...
yarp::dev::ControlBoardHelper::toHw
int toHw(int axis)
Definition: ControlBoardHelper.cpp:245
yarp::dev::ControlBoardHelper::posE2A
void posE2A(double enc, int j, double &ang, int &k)
Definition: ControlBoardHelper.cpp:290
yarp::dev::ControlBoardHelper::velA2E_abs
void velA2E_abs(double ang, int j, double &enc, int &k)
Definition: ControlBoardHelper.cpp:408
yarp::dev::ImplementControlLimits::getLimits
bool getLimits(int axis, double *min, double *max) override
Get the software limits for a particular axis.
Definition: ImplementControlLimits.cpp:74
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
yarp::dev::ImplementControlLimits::setLimits
bool setLimits(int axis, double min, double max) override
Set the software limits for a particular axis, the behavior of the control card when these limits are...
Definition: ImplementControlLimits.cpp:53
yarp::dev::ImplementControlLimits::setVelLimits
bool setVelLimits(int axis, double min, double max) override
Set the software speed limits for a particular axis, the behavior of the control card when these limi...
Definition: ImplementControlLimits.cpp:95
yarp::dev::ControlBoardHelper::velE2A_abs
void velE2A_abs(double enc, int j, double &ang, int &k)
Definition: ControlBoardHelper.cpp:420
ImplementControlLimits.h
yarp::dev::ControlBoardHelper::posA2E
void posA2E(double ang, int j, double &enc, int &k)
Definition: ControlBoardHelper.cpp:279
yarp::dev::IControlLimitsRaw::getVelLimitsRaw
virtual bool getVelLimitsRaw(int axis, double *min, double *max)=0
Get the software speed limits for a particular axis.
yarp::dev::ImplementControlLimits::~ImplementControlLimits
virtual ~ImplementControlLimits()
Destructor.
Definition: ImplementControlLimits.cpp:23
ControlBoardHelper.h
yarp::dev::IControlLimitsRaw
Interface for control devices.
Definition: IControlLimits.h:83
castToMapper
yarp::dev::ControlBoardHelper * castToMapper(void *p)
Definition: ControlBoardHelper.h:180
yarp::dev::ImplementControlLimits::ImplementControlLimits
ImplementControlLimits(yarp::dev::IControlLimitsRaw *y)
Constructor.
Definition: ImplementControlLimits.cpp:17
yarp::dev::ImplementControlLimits::iLimits2
IControlLimitsRaw * iLimits2
Definition: ImplementControlLimits.h:31
yarp::dev::ControlBoardHelper
Definition: ControlBoardHelper.h:60
yarp::dev::IControlLimitsRaw::getLimitsRaw
virtual bool getLimitsRaw(int axis, double *min, double *max)=0
Get the software limits for a particular axis.
yarp::dev::ImplementControlLimits::initialize
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
Definition: ImplementControlLimits.cpp:42
yarp::dev::ImplementControlLimits::uninitialize
bool uninitialize()
Clean up internal data and memory.
Definition: ImplementControlLimits.cpp:32
yarp::dev::IControlLimitsRaw::setLimitsRaw
virtual bool setLimitsRaw(int axis, double min, double max)=0
Set the software limits for a particular axis, the behavior of the control card when these limits are...
yAssert
#define yAssert(x)
Definition: Log.h:297
yarp::dev::ImplementControlLimits::helper
void * helper
Definition: ImplementControlLimits.h:32
yarp::dev::ImplementControlLimits::getVelLimits
bool getVelLimits(int axis, double *min, double *max) override
Get the software speed limits for a particular axis.
Definition: ImplementControlLimits.cpp:107