VR-Engage  2.3
Loading...
Searching...
No Matches
vreRlActuator.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vreRlActuator.h
7//! \ingroup vreVrfRtd
8//! \brief Rotary-wing aircraft actuator component for VREngage
9//!
10//! This file defines the DtVreRlActuator class, which provides real-time
11//! dynamics integration for rotary-wing aircraft controlled through VREngage.
12//! It handles joystick input, updates control surfaces, and maintains
13//! proper kinematic state.
14
15#pragma once
16
20
21class DtSetDestroyRequest;
22class DtSetRestoreRequest;
23class DtSetAltitudeRequest;
24class DtSetLocationRequest;
25class DtSetHeadingRequest;
26class DtSimMessage;
27class DtBooleanInputPort;
28class DtAnalogInputPort;
29class DtSimResource;
30
31namespace makVre
32{
33class MiniPID;
34}
35
36namespace RotorLibCGF
37{
38class HelicopterDynamics;
39};
40
41namespace RlCgfVrf
42{
43class Bot;
44class StateRepository;
45class JoystickControlledBot;
46class HeliCGF;
48
49//! \brief Type string for VREngage rotary-wing actuator component
50//!
51//! Constant used to identify this component type in the simulation system.
52const char TS_VREngageActuator[] = "rotorlib-cgf-vr-engage-actuator";
53
54//! \brief Rotary-wing aircraft actuator component for VREngage
55//!
56//! This class provides the real-time dynamics integration for rotary-wing aircraft
57//! controlled through VREngage. It processes joystick inputs, handles control surface
58//! movement, and maintains proper kinematic state.
59//!
60//! \note Generally the VREngage actuator should not directly write the kinematic
61//! state to the state repository but use its output ports instead. This
62//! allows to use the Update Repository Actuator which in turn allows to
63//! mix the RTD actuator with the VRF Flight Kinematics Actuator.
64//! However, there are exceptions:
65//! - setRestore() and setLocation() (same if player takes control) use
66//! state repository methods like processSetRestore() and checkAndClampAircraftOnGround()
67//! which directly write the kinematic state to the state repository.
68//!
69//! Reason:
70//! - VRF often calls DtVrfMovingObjectStateRepository::clampToGround() after
71//! a setLocation request. This method considers the current kinematic state
72//! of the state repository which has to be assigned beforehand.
73//! - The kinematic state is written to the state repository only
74//! at certain situations (setRestore, setLocation etc.) while the
75//! RTD actuator is active (see isPlayerControlled()). Hence, there should
76//! be no critical interference with other actuators.
77class RTD_VRF_BACKEND_PLUGIN_EXPORT DtVreRlActuator : public makVre::DtVreRotaryWingActuatorComponent
78{
79public:
80 //! \brief Constructor
81 //! \param name The name of the component
82 //! \param object The local object this component belongs to
83 //! \param simManager The simulation services manager
84 //! \param compDescriptor Component descriptor containing configuration
85 //! \param parentRegistry Parent registry for reader/writer functionality
86 //!
87 //! Initializes a new rotary-wing actuator component for VREngage control.
88 DtVreRlActuator(const DtString& name, DtLocalObject* object, DtSimulationServices* simManager,
89 DtComponentDescriptor* compDescriptor, DtReaderWriterRegistry* parentRegistry);
90
91 //! \brief Virtual destructor
92 //!
93 //! Cleans up resources used by the actuator component.
94 virtual ~DtVreRlActuator() override;
95
96 //! \brief Gets the state repository
97 //! \return Pointer to the rotary-wing entity state repository
98 //!
99 //! Returns the state repository used by this rotary-wing aircraft.
100 DtRotaryWingEntityStateRepository* getStateRepository();
101
102 //! \brief Gets the component type
103 //! \return The type string for this component
104 //!
105 //! Returns TS_VREngageActuator as the component type identifier.
106#if RTD_VRF_PLUGIN_VER >= 440
107 virtual const char* type() const override;
108#else
109 virtual DtString type() const;
110#endif
111
112 //! \brief Performs per-frame processing
113 //!
114 //! Called once per simulation frame to update the component state,
115 //! process inputs, and generate outputs.
116 virtual void tick() override;
117
118 //! \brief Initializes the component before the first tick
119 //!
120 //! Performs initialization that must occur before the first tick,
121 //! such as setting up initial state values.
122 virtual void preFirstTickInit() override;
123
124 //! \brief Initializes the component
125 //! \return True if initialization was successful
126 //!
127 //! Performs initial setup of the component, including configuration
128 //! loading and port initialization.
129 virtual bool init() override;
130
131 //! \brief Creates component ports
132 //! \return True if port creation was successful
133 //!
134 //! Creates input and output ports for helicopter controls including
135 //! collective, cyclic, pedals, and wheel brakes.
136 virtual bool createPorts() override;
137
138 //! \brief Component factory function
139 //! \param name The name for the new component
140 //! \param object The local object the component will belong to
141 //! \param simManager The simulation services manager
142 //! \param compDescriptor Component descriptor containing configuration
143 //! \param parentRegistry Parent registry for reader/writer functionality
144 //! \return Pointer to the newly created component
145 //!
146 //! Static factory function used for component creation through the component registry.
147 static DtSimComponent* creator(const DtString& name, DtLocalObject* object, DtSimulationServices* simManager,
148 DtComponentDescriptor* compDescriptor, DtReaderWriterRegistry* parentRegistry);
149
150protected:
151 //! \brief Checks if the entity is currently player-controlled
152 //! \return True if the entity is player-controlled, false otherwise
153 //!
154 //! Determines whether the entity is currently under player control
155 //! through VREngage or AI control.
157
158 //! \brief Writes output data to ports
159 //!
160 //! Updates all output ports with current state data.
162
163 //! \brief Synchronizes RTD fuel with the configured VR-Forces resource.
164 //!
165 //! Invoked at RTD-control transitions and during every RTD-controlled tick.
167
168 //! \brief Publishes the fuel amount used by the frontend displays.
170
171 //! \brief Returns the configured VR-Forces fuel resource, or nullptr when unavailable.
172 DtSimResource* fuelResource();
173
174 //! \brief Sets the aircraft speed
175 //! \param speed The new speed value to set
176 //!
177 //! Sets the current speed of the aircraft.
178 virtual void setSpeed(DtReal speed);
179
180 //! \brief Checks and adjusts the aircraft position to keep it on the ground
181 //! \param localPosition The current local position to check
182 //!
183 //! Ensures the aircraft doesn't sink into or float above the ground
184 //! when it should be in contact with the terrain.
185 virtual void checkAndClampAircraftOnGround(const DtVector& localPosition);
186
187 //! \brief Copies state from RTD to the state repository
188 //!
189 //! Copies the current state from the real-time dynamics engine to
190 //! the state repository to synchronize the simulation state.
191 virtual void copyStateFromRTD();
192
193 //! \brief Copies state from RTD to provided parameters
194 //! \param position Output parameter for position
195 //! \param velocity Output parameter for velocity
196 //! \param acceleration Output parameter for acceleration
197 //! \param orientation Output parameter for orientation
198 //! \param rotVelocity Output parameter for rotational velocity
199 //!
200 //! Copies the current state from the real-time dynamics engine to
201 //! the provided output parameters.
202 virtual void copyStateFromRTD(
203 DtVector& position, DtVector& velocity, DtVector& acceleration, DtTaitBryan& orientation, DtVector& rotVelocity);
204
205 //! \brief Copies state from the state repository to RTD
206 //!
207 //! Copies the current state from the state repository to the real-time
208 //! dynamics engine to synchronize the simulation state.
209 virtual void copyStateToRTD();
210
211 //! \brief Gets the rotary-wing parameters
212 //! \return Pointer to the rotary-wing parameters
213 //!
214 //! Returns the parameters used to configure this rotary-wing aircraft.
216
217 //! \brief Enables or disables state propagation thresholding
218 //! \param enable True to enable thresholding, false to disable
219 //!
220 //! Enables or disables thresholding for state propagation to reduce
221 //! network traffic by only sending significant state changes.
223
224 //! \brief Sets the radio interface for this component
225 //! \param radio The radio interface to use
226 //!
227 //! Configures the radio interface used for communication with this component.
228#if RTD_VRF_PLUGIN_VER >= 430
229 virtual void setRadio(DtSimRadio* radio) override;
230#else
231 virtual void setRadio(DtSimBaseRadio* radio);
232#endif
233
234 //! \brief Static callback for radio messages
235 //! \param msg The received message
236 //! \param usr User data pointer (points to the actuator instance)
237 //!
238 //! Static callback function invoked when a radio message is received.
239 //! Routes the message to the appropriate instance.
240 static void radioMsgCallback(DtSimMessage* msg, void* usr);
241
242 //! \brief Processes a radio message
243 //! \param msg The message to process
244 //!
245 //! Handles incoming radio messages directed to this component.
246 virtual void processRadioMsg(DtSimMessage* msg);
247
248 //! \brief Processes a restore request
249 //! \param req The restore request to process
250 //!
251 //! Restores the entity to a previously saved state.
252 //! Note: This method directly writes to the state repository. See class notes.
253 virtual void processSetRestore(DtSetRestoreRequest* req);
254
255 //! \brief Processes a location change request
256 //! \param req The location request to process
257 //!
258 //! Changes the entity's location.
259 //! Note: This method directly writes to the state repository. See class notes.
260 virtual void processSetLocation(DtSetLocationRequest* req);
261
262 //! \brief Processes a heading change request
263 //! \param req The heading request to process
264 //!
265 //! Changes the entity's heading.
266 virtual void processSetHeading(DtSetHeadingRequest* req);
267
268 //! \brief Input port for joystick enabled state
269 DtBooleanInputPort* myJoystickEnabledPort;
270
271#if RTD_VRF_PLUGIN_VER < 440
272 //! \brief Input port for wheel brake control (boolean version)
273 DtBooleanInputPort* myWheelBrakePort;
274#else
275 //! \brief Input port for wheel brake control (analog version)
276 DtAnalogInputPort* myWheelBrakePort;
277
278 //! \brief Input port for pedal control (yaw)
279 DtAnalogInputPort* myPedalPort;
280
281 //! \brief Input port for collective control (lift)
282 DtConstrainedAnalogInputPort* myCollectivePort;
283
284 //! \brief Input port for cyclic control (pitch/roll)
285 DtConstrainedDualAxisAnalogInputPort* myCyclicPort;
286#endif
287
288 //! \brief Flag indicating whether the entity is player-controlled
290
291 //! \brief Pointer to the real-time dynamics model
292 RotorLibCGF::HelicopterDynamics* myDynamics;
293
294 //! \brief Last recorded speed value
296
297 //! \brief PID controller for X-axis stabilization
299
300 //! \brief PID controller for Y-axis stabilization
302
303 //! \brief Previous latitude value for position tracking
305
306 //! \brief Previous longitude value for position tracking
308
309 //! \brief Synchronizes the RTD fuel tank with the VR-Forces fuel resource.
311};
312} // namespace RlCgfVrf
RotorLibCGF::HelicopterDynamics * myDynamics
Pointer to the real-time dynamics model.
Definition vreRlActuator.h:292
virtual void setRadio(DtSimBaseRadio *radio)
Sets the radio interface for this component.
virtual void tick() override
Performs per-frame processing.
DtReal myLastSpeed
Last recorded speed value.
Definition vreRlActuator.h:295
virtual void copyStateFromRTD(DtVector &position, DtVector &velocity, DtVector &acceleration, DtTaitBryan &orientation, DtVector &rotVelocity)
Copies state from RTD to provided parameters.
bool myPlayerControlled
Flag indicating whether the entity is player-controlled.
Definition vreRlActuator.h:289
virtual void processRadioMsg(DtSimMessage *msg)
Processes a radio message.
virtual void processSetRestore(DtSetRestoreRequest *req)
Processes a restore request.
void writeOutputData()
Writes output data to ports.
bool isPlayerControlled()
Checks if the entity is currently player-controlled.
DtBooleanInputPort * myJoystickEnabledPort
Input port for joystick enabled state.
Definition vreRlActuator.h:269
void synchronizeFuel()
Synchronizes RTD fuel with the configured VR-Forces resource.
virtual DtString type() const
Gets the component type.
virtual void setSpeed(DtReal speed)
Sets the aircraft speed.
virtual bool createPorts() override
Creates component ports.
virtual void checkAndClampAircraftOnGround(const DtVector &localPosition)
Checks and adjusts the aircraft position to keep it on the ground.
DtSimResource * fuelResource()
Returns the configured VR-Forces fuel resource, or nullptr when unavailable.
virtual bool init() override
Initializes the component.
makVre::MiniPID * myXPid
PID controller for X-axis stabilization.
Definition vreRlActuator.h:298
static DtSimComponent * creator(const DtString &name, DtLocalObject *object, DtSimulationServices *simManager, DtComponentDescriptor *compDescriptor, DtReaderWriterRegistry *parentRegistry)
Component factory function.
virtual void copyStateFromRTD()
Copies state from RTD to the state repository.
const DtVreRlParameters * getParameters()
Gets the rotary-wing parameters.
virtual void copyStateToRTD()
Copies state from the state repository to RTD.
float myPreviousLat
Previous latitude value for position tracking.
Definition vreRlActuator.h:304
void updateFuelExtendedData()
Publishes the fuel amount used by the frontend displays.
virtual void preFirstTickInit() override
Initializes the component before the first tick.
static void radioMsgCallback(DtSimMessage *msg, void *usr)
Static callback for radio messages.
DtRotaryWingEntityStateRepository * getStateRepository()
Gets the state repository.
void setStatePropThresholdingEnabled(bool enable)
Enables or disables state propagation thresholding.
vreRtd::RtdFuelSynchronizer myFuelSynchronizer
Synchronizes the RTD fuel tank with the VR-Forces fuel resource.
Definition vreRlActuator.h:310
DtVreRlActuator(const DtString &name, DtLocalObject *object, DtSimulationServices *simManager, DtComponentDescriptor *compDescriptor, DtReaderWriterRegistry *parentRegistry)
Constructor.
virtual void processSetLocation(DtSetLocationRequest *req)
Processes a location change request.
float myPreviousLon
Previous longitude value for position tracking.
Definition vreRlActuator.h:307
makVre::MiniPID * myYPid
PID controller for Y-axis stabilization.
Definition vreRlActuator.h:301
virtual void processSetHeading(DtSetHeadingRequest *req)
Processes a heading change request.
DtBooleanInputPort * myWheelBrakePort
Input port for wheel brake control (boolean version)
Definition vreRlActuator.h:273
virtual ~DtVreRlActuator() override
Virtual destructor.
Rotary-wing parameters for VREngage.
Definition vreRlParameters.h:38
Rotary-wing aircraft actuator with enhanced collision and crash handling.
Definition vreRotaryWingActuator.h:33
A compact PID (Proportional-Integral-Derivative) controller class.
Definition pid.h:33
Synchronizes RTD vehicle fuel with a VR-Forces fuel resource.
Definition vreRtdUtil.h:98
Definition vreRlActuator.h:42
const char TS_VREngageActuator[]
Type string for VREngage rotary-wing actuator component.
Definition vreRlActuator.h:52
Forward declarations for the RotorLibCGF namespace.
Definition vreRlActuator.h:37
!
Definition glsVreMessageUtil.h:50
Actuator for rotary-wing aircraft simulation.
Common definitions for the RTD backend library.
Utility functions for VREngage RTD components.