Loading [MathJax]/extensions/tex2jax.js
iCub-main
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
FineCalibrationCheckerThread.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/os/ResourceFinder.h>
34#include <yarp/dev/PolyDriver.h>
35#include <yarp/dev/DeviceDriver.h>
36#include <yarp/dev/IRemoteCalibrator.h>
37#include <yarp/dev/IControlCalibration.h>
38#include <yarp/dev/IMotor.h>
39
40// iCub includes
42
43
44struct ItemData {
45 std::string name;
46 int32_t val1, val2, val3, val4;
47};
48
49class FineCalibrationCheckerThread : public yarp::os::Thread
50{
51public:
52 // Enum for device status
53 enum class deviceStatus
54 {
55 INITIALIZED = 0,
56 OPENED = 1,
57 CONFIGURED = 2,
58 CALIBRATED = 3,
61 UNKNOWN = 244,
62 NONE = 255
63 };
64
65 // Constructor
67
68 // Destructor
70
71 // Copy constructor
73
74 // Copy assignment operator
76
77 // Move constructor
79
80 // Move assignment operator
82
83 // Parameterized constructor
84 FineCalibrationCheckerThread(yarp::os::ResourceFinder& rf);
85
86 // Overridden methods from yarp::os::Thread
87 void run() override;
88 void onStop() override;
89 bool threadInit() override;
90 void threadRelease() override;
91
92 bool isCalibrationSuccessful() const;
93
94private:
95 // Private members
96
97 // Configuration parameters
98 std::string _portPrefix = "/fineCalibrationChecker";
99 std::string _robotName= "";
100 std::string _deviceName= "fineCalibrationChecker";
101 std::string _remoteRawValuesPort = "";
102
103 deviceStatus _deviceStatus = deviceStatus::NONE;
104
105 yarp::os::Bottle _controlBoardsList = yarp::os::Bottle();
106 yarp::os::Bottle _axesNamesList = yarp::os::Bottle();
107 std::vector<std::string> _robotSubpartsWrapper = {"setup_mc", "head", "left_arm", "right_arm", "torso", "left_leg", "right_leg"};
108 std::map<std::string, std::vector<std::int32_t>> rawDataValuesMap;
109 iCub::rawValuesKeyMetadataMap rawDataMetadata;
110 std::map<std::string, std::array<int32_t, 2>> axesRawGoldenPositionsResMap;
111 std::string _rawValuesTag = "eoprot_tag_mc_joint_status_addinfo_multienc";
112
113 // Pointers to interfaces
114 yarp::dev::IRemoteCalibrator* _iremotecalib;
115 yarp::dev::IControlCalibration* _icontrolcalib;
116 yarp::dev::IMotor* _imot;
118
119 // Client drivers to communicate with interfaces
120 std::unique_ptr<yarp::dev::PolyDriver> _fineCalibrationCheckerDevice;
121 std::unique_ptr<yarp::dev::PolyDriver> _rawValuesOublisherDevice;
122
123 bool configureCalibration();
124 bool runCalibration();
125 void evaluateHardStopPositionDelta(const std::string& key, const std::string& inputFileName, const std::string& outputFileName);
126 void generateOutputImage(int frameWidth, int frameHeight, const std::vector<ItemData>& items);
127 // Utility methods
128 void configureDevicesMap(std::vector<std::string> list);
129 cv::Scalar getColorForDelta(int32_t delta, int32_t threshold_1, int32_t threshold_2);
130};
131
132#endif // FINE_CALIBRATION_CHECKER_THREAD_H
FineCalibrationCheckerThread(const FineCalibrationCheckerThread &other)=default
FineCalibrationCheckerThread & operator=(FineCalibrationCheckerThread &&other) noexcept=default
FineCalibrationCheckerThread & operator=(const FineCalibrationCheckerThread &other)=default
FineCalibrationCheckerThread(FineCalibrationCheckerThread &&other) noexcept=default