YARP
Yet Another Robot Platform
ImplementControlCalibration.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 
10 #include <yarp/dev/DeviceDriver.h>
13 #include <yarp/os/Log.h>
14 
15 #include <cstdio>
16 
17 using namespace yarp::dev;
18 
20 {
21  calibrator=nullptr;
22 }
23 
25 {
26  if (c!=nullptr)
27  {
28  calibrator=c;
29  return true;
30  }
31 
32  return false;
33 }
34 
36 {
37  bool ret = false;
38  if (calibrator!=nullptr)
39  {
40  yDebug("Going to call calibrator\n");
41  ret=calibrator->calibrate(dynamic_cast<DeviceDriver *>(this));
42  }
43  else
44  yWarning("Warning called calibrate but no calibrator was set\n");
45 
46  return ret;
47 }
48 
50 {
51  bool ret=false;
52  if (calibrator!=nullptr)
53  ret=calibrator->quitCalibrate();
54  return ret;
55 }
56 
58 {
59  bool ret=false;
60  if (calibrator!=nullptr)
61  ret=calibrator->quitPark();
62  return ret;
63 }
64 
66 {
67  bool ret=false;
68  if (calibrator!=nullptr)
69  {
70  yDebug("Going to call calibrator\n");
71  ret=calibrator->park(dynamic_cast<DeviceDriver *>(this), wait);
72  }
73  else
74  yWarning("Warning called park but no calibrator was set\n");
75 
76  return ret;
77 }
78 
80 // ControlCalibration Interface Implementation
82 {
83  iCalibrate = dynamic_cast<IControlCalibrationRaw *> (y);
84  helper = nullptr;
85  temp = nullptr;
86 }
87 
89 {
90  uninitialize();
91 }
92 
93 bool ImplementControlCalibration::initialize(int size, const int *amap, const double *enc, const double *zos)
94 {
95  if (helper != nullptr)
96  return false;
97 
98  helper = (void *)(new ControlBoardHelper(size, amap, enc, zos));
99  yAssert(helper != nullptr);
100  temp = new double[size];
101  yAssert(temp != nullptr);
102  return true;
103 }
104 
110 {
111  if (helper != nullptr)
112  {
113  delete castToMapper(helper);
114  helper = nullptr;
115  }
116 
118 
119  return true;
120 }
121 
123 {
124  int k = castToMapper(helper)->toHw(j);
125 
126  return iCalibrate->calibrationDoneRaw(k);
127 }
128 
129 bool ImplementControlCalibration::calibrateAxisWithParams(int axis, unsigned int type, double p1, double p2, double p3)
130 {
131  int k = castToMapper(helper)->toHw(axis);
132 
133  return iCalibrate->calibrateAxisWithParamsRaw(k, type, p1, p2, p3);
134 }
135 
137 {
138  int k = castToMapper(helper)->toHw(axis);
139 
140  return iCalibrate->setCalibrationParametersRaw(k, params);
141 }
yarp::dev::ControlBoardHelper::toHw
int toHw(int axis)
Definition: ControlBoardHelper.cpp:245
yarp::dev::ImplementControlCalibration::uninitialize
bool uninitialize()
Clean up internal data and memory.
Definition: ImplementControlCalibration.cpp:109
yarp::dev::ICalibrator::park
virtual bool park(DeviceDriver *dd, bool wait=true)=0
yarp::dev::ImplementControlCalibration::helper
void * helper
Definition: ImplementControlCalibration.h:27
yarp::dev::DeviceDriver
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
yarp::dev::IControlCalibration::calibrateRobot
virtual bool calibrateRobot()
Calibrate robot by using an external calibrator.
Definition: ImplementControlCalibration.cpp:35
yarp::dev::IControlCalibrationRaw
Interface for control devices, calibration commands.
Definition: IControlCalibration.h:48
ret
bool ret
Definition: ImplementAxisInfo.cpp:72
ControlBoardInterfaces.h
define control board standard interfaces
yarp::dev
An interface for the device drivers.
Definition: audioBufferSizeData.cpp:17
yarp::dev::ImplementControlCalibration::setCalibrationParameters
bool setCalibrationParameters(int axis, const CalibrationParameters &params) override
Start calibration, this method is very often platform specific.
Definition: ImplementControlCalibration.cpp:136
yarp::dev::ImplementControlCalibration::calibrationDone
bool calibrationDone(int j) override
Check if the calibration is terminated, on a particular joint.
Definition: ImplementControlCalibration.cpp:122
Log.h
yarp::dev::IControlCalibrationRaw::setCalibrationParametersRaw
virtual bool setCalibrationParametersRaw(int axis, const CalibrationParameters &params)
Start calibration, this method is very often platform specific.
Definition: IControlCalibration.h:75
yarp::dev::ICalibrator::quitCalibrate
virtual bool quitCalibrate()=0
yarp::dev::ICalibrator::quitPark
virtual bool quitPark()=0
yarp::dev::ImplementControlCalibration::calibrateAxisWithParams
bool calibrateAxisWithParams(int axis, unsigned int type, double p1, double p2, double p3) override
Start calibration, this method is very often platform specific.
Definition: ImplementControlCalibration.cpp:129
yarp::dev::IControlCalibration::IControlCalibration
IControlCalibration()
Definition: ImplementControlCalibration.cpp:19
yarp::dev::ImplementControlCalibration::temp
double * temp
Definition: ImplementControlCalibration.h:28
yarp::dev::IControlCalibrationRaw::calibrateAxisWithParamsRaw
virtual bool calibrateAxisWithParamsRaw(int axis, unsigned int type, double p1, double p2, double p3)=0
Start calibration, this method is very often platform specific.
yarp::dev::ICalibrator
Definition: ICalibrator.h:19
yarp::dev::IControlCalibration::setCalibrator
virtual bool setCalibrator(ICalibrator *c)
Set the calibrator object to be used to calibrate the robot.
Definition: ImplementControlCalibration.cpp:24
yWarning
#define yWarning(...)
Definition: Log.h:271
yarp::dev::ImplementControlCalibration::~ImplementControlCalibration
virtual ~ImplementControlCalibration()
Destructor.
Definition: ImplementControlCalibration.cpp:88
yarp::dev::ICalibrator::calibrate
virtual bool calibrate(DeviceDriver *dd)=0
checkAndDestroy
void checkAndDestroy(T *&p)
Definition: ControlBoardHelper.h:45
yarp::dev::IControlCalibration::abortPark
virtual bool abortPark()
Definition: ImplementControlCalibration.cpp:57
yarp::dev::ImplementControlCalibration::iCalibrate
IControlCalibrationRaw * iCalibrate
Definition: ImplementControlCalibration.h:26
castToMapper
yarp::dev::ControlBoardHelper * castToMapper(void *p)
Definition: ControlBoardHelper.h:180
yarp::dev::ControlBoardHelper
Definition: ControlBoardHelper.h:60
yarp::dev::IControlCalibration::abortCalibration
virtual bool abortCalibration()
Definition: ImplementControlCalibration.cpp:49
yDebug
#define yDebug(...)
Definition: Log.h:237
ImplementControlCalibration.h
yarp::dev::ImplementControlCalibration::ImplementControlCalibration
ImplementControlCalibration(yarp::dev::IControlCalibrationRaw *y)
Definition: ImplementControlCalibration.cpp:81
yarp::dev::CalibrationParameters
Definition: IControlCalibration.h:32
yarp::dev::ImplementControlCalibration::initialize
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
Definition: ImplementControlCalibration.cpp:93
yAssert
#define yAssert(x)
Definition: Log.h:297
yarp::dev::IControlCalibrationRaw::calibrationDoneRaw
virtual bool calibrationDoneRaw(int j)=0
Check if the calibration is terminated, on a particular joint.
DeviceDriver.h
yarp::dev::IControlCalibration::park
virtual bool park(bool wait=true)
Definition: ImplementControlCalibration.cpp:65