Visu.h
Go to the documentation of this file.
1/*
2 * This file is part of ArmarX.
3 *
4 * ArmarX is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * ArmarX is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * @author Fabian Reister ( fabian dot reister at kit dot edu )
17 * @date 2021
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#pragma once
23
24#include <array>
25#include <atomic>
26#include <map>
27#include <mutex>
28#include <optional>
29#include <set>
30#include <string>
31
32#include <VirtualRobot/VirtualRobot.h>
33
38
41
49
50namespace armarx
51{
53} // namespace armarx
54
56{
57 struct ScanPoint
58 {
59 Eigen::Vector3f point;
60 float intensity;
61 };
62
63 /**
64 * @brief Models decay of object localizations by decreasing the confidence
65 * the longer the object was not localized.
66 */
67 class Visu : public armarx::Logging
68 {
69 public:
70 Visu();
71
72 ~Visu();
73
75 const std::string& prefix = "visu.");
76 void init(const wm::CoreSegment* coreSegment,
77 armem::robot_state::VirtualRobotReader* virtualRobotReader);
78 void connect(const viz::Client& arviz, DebugObserverInterfacePrx debugObserver = nullptr);
79
80 /// Stop and join the visualization task. Safe to call more than once.
81 void disconnect();
82
84 const std::string& tabName);
85 void remoteGuiUpdate();
86
87
88 private:
89 void visualizeRun();
90 void visualizeOnce(const Time& timestamp);
91
92 Eigen::Isometry3f getCalibrationOffset(const std::string& sensorFrame) const;
93 void createOrUpdateCalibrationTab();
94
95 viz::Client arviz;
96 std::optional<DebugObserverHelper> debugObserver;
97
98 struct Properties
99 {
100 bool enabled = true;
101 bool uniformColor = false;
102 bool colorByIntensity = true;
103 float frequencyHz = 5;
104 int maxRobotAgeMs = 100;
105 int pointSizeInPixels = 3;
106 } p;
107
109
110 armem::robot_state::VirtualRobotReader* virtualRobotReader;
111
112 std::map<std::string, std::pair<VirtualRobot::RobotPtr, DateTime>> robots;
113
114 VirtualRobot::RobotPtr getSynchronizedRobot(const std::string& name,
115 const DateTime& timestamp);
116
117 void visualizeScan(const std::vector<ScanPoint>& points,
118 const std::string& sensorName,
119 const std::string& agentName,
120 const viz::Color& color);
121
122 std::map<std::string, armem::laser_scans::LaserScanStamped> getCurrentLaserScans();
123
124 const wm::CoreSegment* coreSegment;
125
126 // --- Extrinsic calibration via Remote GUI ---
127
128 struct SensorCalibrationData
129 {
130 float x = 0.f; // [mm]
131 float y = 0.f; // [mm]
132 float yaw = 0.f; // [deg]
133 };
134
135 // Cleared and rebuilt on each tab update. [0]=x [mm], [1]=y [mm], [2]=yaw [deg]
136 struct CalibrationTab : armarx::RemoteGui::Client::Tab
137 {
138 std::map<std::string, std::array<armarx::RemoteGui::Client::FloatSpinBox, 3>> sensors;
139 };
140
142 std::string remoteGuiTabName_;
143
144 mutable std::mutex sensorMutex_;
145 std::set<std::string> knownSensorFrames_;
146 std::map<std::string, SensorCalibrationData> calibrationData_;
147
148 CalibrationTab calibrationTab_;
149 std::atomic<bool> needsTabRebuild_{false};
150 };
151
152} // namespace armarx::armem::server::laser_scans
std::string timestamp()
Base Class for all Logging classes.
Definition Logging.h:238
IceUtil::Handle< RunningTask< T > > pointer_type
Shared pointer type for convenience.
void defineProperties(armarx::PropertyDefinitionsPtr defs, const std::string &prefix="visu.")
Definition Visu.cpp:46
void connect(const viz::Client &arviz, DebugObserverInterfacePrx debugObserver=nullptr)
Definition Visu.cpp:69
void disconnect()
Stop and join the visualization task. Safe to call more than once.
Definition Visu.cpp:94
void init(const wm::CoreSegment *coreSegment, armem::robot_state::VirtualRobotReader *virtualRobotReader)
Definition Visu.cpp:61
void connectRemoteGui(armarx::LightweightRemoteGuiComponentPluginUser *guiUser, const std::string &tabName)
Definition Visu.cpp:108
Represents a point in time.
Definition DateTime.h:25
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file is part of ArmarX.
armarx::core::time::DateTime Time
This file offers overloads of toIce() and fromIce() functions for STL container types.
::IceInternal::ProxyHandle<::IceProxy::armarx::DebugObserverInterface > DebugObserverInterfacePrx
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.