iCub-main
Loading...
Searching...
No Matches
FineCalibrationChecker.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2025 iCub Facility - Istituto Italiano di Tecnologia
3 * Author: Jacopo Losi
4 * email: jacopo.losi@iit.it
5 * Permission is granted to copy, distribute, and/or modify this program
6 * under the terms of the GNU General Public License, version 2 or any
7 * later version published by the Free Software Foundation.
8 *
9 * A copy of the license can be found at
10 * http://www.robotcub.org/icub/license/gpl.txt
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
15 * Public License for more details
16 */
17// -*- mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
18
19#ifndef FINE_CALIBRATION_CHECKER_THREAD_H
20#define FINE_CALIBRATION_CHECKER_THREAD_H
21
22// std includes
23#include <vector>
24#include <string>
25#include <map>
26#include <memory>
27
28#include <opencv2/opencv.hpp>
29
30// yarp includes
31#include <yarp/os/Bottle.h>
32#include <yarp/os/Thread.h>
33#include <yarp/dev/PolyDriver.h>
34#include <yarp/dev/DeviceDriver.h>
35#include <yarp/dev/IMultipleWrapper.h>
36#include <yarp/dev/IControlCalibration.h>
37#include <yarp/dev/IMotor.h>
38#include <yarp/dev/IEncoders.h>
39
40// iCub includes
42
43
44struct ItemData {
45 std::string name;
46 int64_t val1, val2, val3;
47 double val4;
48};
49
50class FineCalibrationChecker : public yarp::dev::DeviceDriver,
51 public yarp::os::Thread,
52 public yarp::dev::IMultipleWrapper
53{
54public:
55 // Enum for device status
56 enum class deviceStatus
57 {
58 INITIALIZED = 0,
59 OPENED = 1,
60 CONFIGURED = 2,
61 STARTED = 3,
62 CALIBRATED = 4,
65 UNKNOWN = 244,
66 NONE = 255
67 };
68
69 // Constructor
71
72 // Destructor
74
75 // Copy constructor
77
78 // Copy assignment operator
80
81 // Move constructor
83
84 // Move assignment operator
86
87 // Overridden methods from yarp::dev::DeviceDriver
88 bool open(yarp::os::Searchable& config) override;
89 bool close() override;
90
91 // Overridden methods from yarp::os::Thread
92 void run() override;
93 void onStop() override;
94 bool threadInit() override;
95
96 // Overridden methods from yarp::dev::IMultipleWrapper
97 bool attachAll(const yarp::dev::PolyDriverList& device2attach) override;
98 bool detachAll() override;
99
100 bool isCalibrationSuccessful() const;
101
102private:
103 // Private members
104
105 // Configuration parameters
106 std::string _portPrefix = "/fineCalibrationChecker";
107 std::string _robotName= "";
108 std::string _deviceName= "fineCalibrationChecker";
109 std::string _remoteRawValuesPort = "";
110 bool _withGui = false;
111
112 deviceStatus _deviceStatus = deviceStatus::NONE;
113
114 yarp::os::Bottle _axesNamesList = yarp::os::Bottle();
115 yarp::os::Bottle _goldPositionsList = yarp::os::Bottle();
116 yarp::os::Bottle _encoderResolutionsList = yarp::os::Bottle();
117 yarp::os::Bottle _calibrationDeltasList = yarp::os::Bottle();
118 yarp::os::Bottle _axesSignsList = yarp::os::Bottle();
119
120 std::vector<std::string> _robotSubpartsWrapper = {"setup_mc", "head", "left_arm", "right_arm", "torso", "left_leg", "right_leg"};
121 std::map<std::string, std::vector<std::int32_t>> rawDataValuesMap;
122 iCub::rawValuesKeyMetadataMap rawDataMetadata;
123 std::map<std::string, std::array<int32_t, 2>> axesRawGoldenPositionsResMap;
124 std::string _rawValuesTag = "eoprot_tag_mc_joint_status_addinfo_multienc";
125
126 // Pointers to interfaces
127 struct
128 {
129 yarp::dev::IMultipleWrapper* _imultwrap{ nullptr };
130 yarp::dev::IControlCalibration* _icontrolcalib { nullptr };
131 yarp::dev::IMotor* _imot { nullptr };
132 yarp::dev::IEncoders* _ienc { nullptr };
133 } remappedControlBoardInterfaces;
134
135 struct
136 {
137 yarp::dev::IMultipleWrapper* _imultwrap{ nullptr };
139 } remappedRawValuesPublisherInterfaces;
140
141 // Client drivers to communicate with interfaces
142 std::unique_ptr<yarp::dev::PolyDriver> _remappedControlBoardDevice;
143 std::unique_ptr<yarp::dev::PolyDriver> _remappedRawValuesPublisherDevice;
144
145 void evaluateHardStopPositionDelta(const std::string& key, const std::string& outputFileName);
146 void generateOutputImage(int frameWidth, int frameHeight, const std::vector<ItemData>& items);
147
148 // Utility methods
149 cv::Scalar getColorForDelta(double delta, double threshold_1, double threshold_2);
150
151 bool attachToAllControlBoards(const yarp::dev::PolyDriverList& polyList);
152};
153
154#endif // FINE_CALIBRATION_CHECKER_THREAD_H
iCub::debugLibrary::IRawValuesPublisher * _iravap
FineCalibrationChecker(const FineCalibrationChecker &other)=default
bool open(yarp::os::Searchable &config) override
FineCalibrationChecker & operator=(const FineCalibrationChecker &other)=default
FineCalibrationChecker(FineCalibrationChecker &&other) noexcept=default
bool attachAll(const yarp::dev::PolyDriverList &device2attach) override
yarp::dev::IControlCalibration * _icontrolcalib
~FineCalibrationChecker()=default
FineCalibrationChecker & operator=(FineCalibrationChecker &&other) noexcept=default
yarp::dev::IEncoders * _ienc
yarp::dev::IMultipleWrapper * _imultwrap