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 }
void checkAndDestroy(T *&p)
yarp::dev::ControlBoardHelper * castToMapper(void *p)
define control board standard interfaces
bool ret
#define yDebug(...)
Definition: Log.h:237
#define yAssert(x)
Definition: Log.h:297
#define yWarning(...)
Definition: Log.h:271
Interface implemented by all device drivers.
Definition: DeviceDriver.h:38
virtual bool park(DeviceDriver *dd, bool wait=true)=0
virtual bool calibrate(DeviceDriver *dd)=0
virtual bool quitPark()=0
virtual bool quitCalibrate()=0
Interface for control devices, calibration commands.
virtual bool setCalibrationParametersRaw(int axis, const CalibrationParameters &params)
Start calibration, this method is very often platform specific.
virtual bool calibrationDoneRaw(int j)=0
Check if the calibration is terminated, on a particular joint.
virtual bool calibrateAxisWithParamsRaw(int axis, unsigned int type, double p1, double p2, double p3)=0
Start calibration, this method is very often platform specific.
virtual bool setCalibrator(ICalibrator *c)
Set the calibrator object to be used to calibrate the robot.
virtual bool calibrateRobot()
Calibrate robot by using an external calibrator.
bool calibrationDone(int j) override
Check if the calibration is terminated, on a particular joint.
bool setCalibrationParameters(int axis, const CalibrationParameters &params) override
Start calibration, this method is very often platform specific.
ImplementControlCalibration(yarp::dev::IControlCalibrationRaw *y)
bool initialize(int size, const int *amap, const double *enc, const double *zos)
Initialize the internal data and alloc memory.
bool calibrateAxisWithParams(int axis, unsigned int type, double p1, double p2, double p3) override
Start calibration, this method is very often platform specific.
bool uninitialize()
Clean up internal data and memory.
An interface for the device drivers.