ImageProviderGodotSimulation.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 * @package ArmarXSimulation::components::ImageProviderGodotSimulation
17 * @author Timo Birr
18 * @copyright http://www.gnu.org/licenses/gpl-2.0.txt
19 * GNU General Public License
20 */
21
22#pragma once
23
24#include <mutex>
25#include <string>
26#include <vector>
27
28#include <Eigen/Geometry>
29
30#include <VirtualRobot/Robot.h>
31
33
35#include <VisionX/interface/components/Calibration.h>
36
37#include <arviz_godot/lib/ArVizInteractiveInterface.h>
38
39namespace armarx
40{
41 /**
42 * @defgroup Component-ImageProviderGodotSimulation ImageProviderGodotSimulation
43 * @ingroup ArmarXSimulation-Components
44 *
45 * @class ImageProviderGodotSimulation
46 * @ingroup Component-ImageProviderGodotSimulation
47 * @brief A monocular image provider that renders the simulated scene using arviz_godot.
48 *
49 * This is a modern replacement for ImageProviderDynamicSimulation (which renders the scene
50 * with the outdated Coin3D engine). Instead of rendering locally, it asks a running
51 * arviz_godot instance to render the live ArViz scene (e.g. the robot and objects published
52 * by the SimulatorToArviz component) from the pose of a configured robot camera node and
53 * serves the resulting image as a VisionX image provider.
54 *
55 * Prerequisites at runtime: ArVizStorage, arviz_godot, the Simulator + SimulatorToArviz (so
56 * the scene is present in Godot) and a RobotStateComponent must be running.
57 */
60 virtual public visionx::MonocularCalibrationCapturingProviderInterface
61 {
62 public:
63 static std::string
65 {
66 return "GodotSimulationImageProvider";
67 }
68
69 std::string
70 getDefaultName() const override
71 {
72 return "GodotSimulationImageProvider";
73 }
74
75 protected:
76 /// @see visionx::CapturingImageProvider::onInitCapturingImageProvider()
77 void onInitCapturingImageProvider() override;
78
79 /// @see visionx::CapturingImageProvider::onStartCapturingImageProvider()
80 void onStartCapturingImageProvider() override;
81
82 /// @see visionx::CapturingImageProvider::onExitCapturingImageProvider()
83 void onExitCapturingImageProvider() override;
84
85 /// @see visionx::CapturingImageProvider::onStartCapture(float frameRate)
86 void onStartCapture(float frameRate) override;
87
88 /// @see visionx::CapturingImageProvider::onStopCapture()
89 void onStopCapture() override;
90
91 bool capture(void** ppImageBuffers) override;
92
93 /// @see visionx::MonocularCalibrationCapturingProviderInterface
94 visionx::MonocularCalibration
95 getCalibration(const Ice::Current& c = Ice::emptyCurrent) override;
96
98
99 private:
100 /// Resolve (or re-resolve) the RobotStateComponent clone and the arviz_godot proxy.
101 bool ensureConnected();
102
103 // Configuration.
104 int renderWidth_ = 640;
105 int renderHeight_ = 480;
106 float focalLength_ = 600.f;
107 float nearClipMeters_ = 0.01f;
108 float farClipMeters_ = 100.f;
109 std::string cameraNodeName_;
110 std::string referenceFrame_;
111 std::string arvizGodotName_;
112 std::string robotStateComponentName_;
113 int renderTimeoutMs_ = 2000;
114
115 /// ArViz layers to render ("component" or "component::layer" entries). Empty = whole scene.
116 std::vector<std::string> renderLayers_;
117
118 /// Rotation that maps the camera node's local frame to the OpenGL camera frame
119 /// (camera looks down local -Z, +Y up). Configurable to ease per-robot tuning.
120 Eigen::Quaternionf cameraAlignment_ = Eigen::Quaternionf::Identity();
121
122 // Runtime.
123 arviz_interactive_project::components::arviz_interactive::ArVizInteractiveInterfacePrx
124 arvizGodot_;
125 SharedRobotInterfacePrx sharedRobot_;
126 VirtualRobot::RobotPtr localRobot_;
127
128 std::mutex captureMutex_;
129 };
130} // namespace armarx
constexpr T c
A monocular image provider that renders the simulated scene using arviz_godot.
armarx::PropertyDefinitionsPtr createPropertyDefinitions() override
visionx::MonocularCalibration getCalibration(const Ice::Current &c=Ice::emptyCurrent) override
std::string getDefaultName() const override
Retrieve default name of component.
The CapturingImageProvider provides a callback function to trigger the capturing of images with diffe...
Quaternion< float, 0 > Quaternionf
std::shared_ptr< class Robot > RobotPtr
Definition Bus.h:19
This file offers overloads of toIce() and fromIce() functions for STL container types.
IceUtil::Handle< class PropertyDefinitionContainer > PropertyDefinitionsPtr
PropertyDefinitions smart pointer type.
::IceInternal::ProxyHandle<::IceProxy::armarx::SharedRobotInterface > SharedRobotInterfacePrx
Definition FramedPose.h:59