VR-Engage  2.3
Loading...
Searching...
No Matches
vreFwlActuator.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vreFwlActuator.h
7//! \ingroup vreVrfRtd
8//! \brief Fixed-wing aircraft actuator component for VREngage
9//!
10//! This file defines the DtVreFwlActuator class, which provides real-time
11//! dynamics integration for fixed-wing aircraft controlled through VREngage.
12//! It handles joystick input, updates control surfaces, and maintains
13//! proper kinematic state.
14
15#pragma once
16
19#include <vrfmodel/fixedWingActuatorComponent.h>
20
21class DtSetJoyDeviceSwitchRequest;
22class DtSimMessage;
23class DtBooleanInputPort;
24class DtIntegerInputPort;
25class DtBooleanOutputPort;
26class DtSetRestoreRequest;
27class DtSetLocationRequest;
28class DtSetHeadingRequest;
29class DtSimResource;
30
32{
33class AirplaneDynamics;
34}
35
36namespace FwlCgfVrf
37{
38class StateRepository;
39
40//! \brief Type string for VREngage fixed-wing actuator component
41//!
42//! Constant used to identify this component type in the simulation system.
43const char TS_VREngageActuator[] = "fixedwinglib-cgf-vr-engage-actuator";
44
45class Cgf;
47
48//! \brief Fixed-wing aircraft actuator component for VREngage
49//!
50//! This class provides the real-time dynamics integration for fixed-wing aircraft
51//! controlled through VREngage. It processes joystick inputs, handles control surface
52//! movement, and maintains proper kinematic state.
53//!
54//! \note Generally the VREngage actuator should not directly write the kinematic
55//! state to the state repository but use its output ports instead. This
56//! allows to use the Update Repository Actuator which in turn allows to
57//! mix the RTD VREngageActuator with the VRF Flight Kinematics Actuator.
58//! However, there are exceptions:
59//! - setRestore() and setLocation() (same if player takes control) use
60//! state repository methods like processSetRestore() and checkAndClampAircraftOnGround()
61//! which directly write the kinematic state to the state repository.
62//!
63//! Reason:
64//! - VRF often calls DtVrfMovingObjectStateRepository::clampToGround() after
65//! a setLocation request. This method considers the current kinematic state
66//! of the state repository which has to be assigned beforehand.
67//! - The kinematic state is written to the state repository only
68//! at certain situations (setRestore, setLocation etc.) while the
69//! RTD actuator is active (see isPlayerControlled()). Hence, there should
70//! be no critical interference with other actuators.
71class RTD_VRF_BACKEND_PLUGIN_EXPORT DtVreFwlActuator : public DtFixedWingActuatorComponent
72{
73public:
74 //! \brief Constructor
75 //! \param name The name of the component
76 //! \param object The local object this component belongs to
77 //! \param simManager The simulation services manager
78 //! \param compDescriptor Component descriptor containing configuration
79 //! \param parentRegistry Parent registry for reader/writer functionality
80 //!
81 //! Initializes a new fixed-wing actuator component for VREngage control.
82 DtVreFwlActuator(const DtString& name, DtLocalObject* object, DtSimulationServices* simManager,
83 DtComponentDescriptor* compDescriptor, DtReaderWriterRegistry* parentRegistry);
84
85 //! \brief Virtual destructor
86 //!
87 //! Cleans up resources used by the actuator component.
88 virtual ~DtVreFwlActuator() override;
89
90 //! \brief Gets the component type
91 //! \return The type string for this component
92 //!
93 //! Returns TS_VREngageActuator as the component type identifier.
94 virtual const char* type() const override;
95
96 //! \brief Sets the radio interface for this component
97 //! \param radio The radio interface to use
98 //!
99 //! Configures the radio interface used for communication with this component.
100 virtual void setRadio(DtSimRadio* radio) override;
101
102 //! \brief Performs per-frame processing
103 //!
104 //! Called once per simulation frame to update the component state,
105 //! process inputs, and generate outputs.
106 virtual void tick() override;
107
108 //! \brief Creates component ports
109 //! \return True if port creation was successful
110 //!
111 //! Creates input and output ports for joystick control, landing gear,
112 //! flaps, and other control surfaces.
113 virtual bool createPorts() override;
114
115 //! \brief Creates port groups
116 //! \return True if port group creation was successful
117 //!
118 //! Creates logical groupings of related ports such as control surfaces.
119 virtual bool createPortGroups() override;
120
121 //! \brief Updates the control surface positions
122 //! \param resetToZero If true, resets all control surfaces to neutral positions
123 //!
124 //! Updates the positions of all aircraft control surfaces based on current inputs
125 //! or resets them to neutral positions if resetToZero is true.
126 virtual void updateControlSurfaces(bool resetToZero = false);
127
128 //! \brief Component factory function
129 //! \param name The name for the new component
130 //! \param object The local object the component will belong to
131 //! \param simManager The simulation services manager
132 //! \param compDescriptor Component descriptor containing configuration
133 //! \param parentRegistry Parent registry for reader/writer functionality
134 //! \return Pointer to the newly created component
135 //!
136 //! Static factory function used for component creation through the component registry.
137 static DtSimComponent* creator(const DtString& name, DtLocalObject* object, DtSimulationServices* simManager,
138 DtComponentDescriptor* compDescriptor, DtReaderWriterRegistry* parentRegistry);
139
140 //! \brief Static callback for radio messages
141 //! \param msg The received message
142 //! \param usr User data pointer (points to the actuator instance)
143 //!
144 //! Static callback function invoked when a radio message is received.
145 //! Routes the message to the appropriate instance.
146 static void radioMsgCallback(DtSimMessage* msg, void* usr);
147
148 //! \brief Processes a radio message
149 //! \param msg The message to process
150 //!
151 //! Handles incoming radio messages directed to this component.
152 virtual void processRadioMsg(DtSimMessage* msg);
153
154 //! \brief Processes a restore request
155 //! \param req The restore request to process
156 //!
157 //! Restores the entity to a previously saved state.
158 //! Note: This method directly writes to the state repository. See class notes.
159 virtual void processSetRestore(DtSetRestoreRequest* req);
160
161 //! \brief Processes a location change request
162 //! \param req The location request to process
163 //!
164 //! Changes the entity's location.
165 //! Note: This method directly writes to the state repository. See class notes.
166 virtual void processSetLocation(DtSetLocationRequest* req);
167
168 //! \brief Processes a heading change request
169 //! \param req The heading request to process
170 //!
171 //! Changes the entity's heading.
172 virtual void processSetHeading(DtSetHeadingRequest* req);
173
174 //! \brief Gets the state repository
175 //! \return Pointer to the fixed-wing entity state repository
176 //!
177 //! Returns the state repository used by this fixed-wing aircraft.
178 DtFixedWingEntityStateRepository* getStateRepository();
179
180protected:
181 //! \brief Checks if the entity is currently player-controlled
182 //! \return True if the entity is player-controlled, false otherwise
183 //!
184 //! Determines whether the entity is currently under player control
185 //! through VREngage or AI control.
187
188 //! \brief Writes output data to ports
189 //!
190 //! Updates all output ports with current state data.
192
193 //! \brief Enables or disables state propagation thresholding
194 //! \param enable True to enable thresholding, false to disable
195 //!
196 //! Enables or disables thresholding for state propagation to reduce
197 //! network traffic by only sending significant state changes.
199
200 //! \brief Synchronizes RTD fuel with the configured VR-Forces resource.
201 //!
202 //! Invoked at RTD-control transitions and during every RTD-controlled tick.
204
205 //! \brief Publishes the fuel amount used by the frontend displays.
207
208 //! \brief Returns the configured VR-Forces fuel resource, or nullptr when unavailable.
209 DtSimResource* fuelResource();
210
211 //! \brief Sets the aircraft speed
212 //! \param speed The new speed value to set
213 //!
214 //! Sets the current speed of the aircraft.
215 virtual void setSpeed(DtReal speed);
216
217 //! \brief Checks and adjusts the aircraft position to keep it on the ground
218 //! \param localPosition The current local position to check
219 //!
220 //! Ensures the aircraft doesn't sink into or float above the ground
221 //! when it should be in contact with the terrain.
222 virtual void checkAndClampAircraftOnGround(const DtVector& localPosition);
223
224 //! \brief Copies state from RTD to the state repository
225 //!
226 //! Copies the current state from the real-time dynamics engine to
227 //! the state repository to synchronize the simulation state.
228 virtual void copyStateFromRTD();
229
230 //! \brief Copies state from RTD to provided parameters
231 //! \param position Output parameter for position
232 //! \param velocity Output parameter for velocity
233 //! \param acceleration Output parameter for acceleration
234 //! \param orientation Output parameter for orientation
235 //! \param rotVelocity Output parameter for rotational velocity
236 //!
237 //! Copies the current state from the real-time dynamics engine to
238 //! the provided output parameters.
239 virtual void copyStateFromRTD(
240 DtVector& position, DtVector& velocity, DtVector& acceleration, DtTaitBryan& orientation, DtVector& rotVelocity);
241
242 //! \brief Copies state from the state repository to RTD
243 //!
244 //! Copies the current state from the state repository to the real-time
245 //! dynamics engine to synchronize the simulation state.
246 virtual void copyStateToRTD();
247
248 //! \brief Gets the fixed-wing parameters
249 //! \return Pointer to the fixed-wing parameters
250 //!
251 //! Returns the parameters used to configure this fixed-wing aircraft.
253
255
256 //! \brief Input port for joystick enabled state
257 DtBooleanInputPort* myJoystickEnabledPort;
258
259 //! \brief Input port for landing gear control
260 DtBooleanInputPort* myLandingGearPort;
261
262 //! \brief Input port for flap setting
263 DtIntegerInputPort* myFlapSettingPort;
264
265 //! \brief Input port for air brake control
266 DtAnalogInputPort* myAirBrakePort;
267
268 //! \brief Input port for wheel brake control
269 DtAnalogInputPort* myWheelBrakePort;
270
271 //! \brief Input port for control stick (pitch/roll)
272 DtConstrainedDualAxisAnalogInputPort* myStickPort;
273
274 //! \brief Input port for rudder pedals (yaw)
275 DtConstrainedAnalogInputPort* myPedalPort;
276
277 //! \brief Input port for throttle control
278 DtConstrainedAnalogInputPort* myThrottlePort;
279
280 //! \brief Output port for landing gear state
281 DtBooleanOutputPort* myLandingGearState;
282
283 //! \brief Output port for rudder position
284 DtAnalogOutputPort* myRudderPort;
285
286 //! \brief Output port for left aileron position
287 DtAnalogOutputPort* myLeftAileronPort;
288
289 //! \brief Output port for right aileron position
290 DtAnalogOutputPort* myRightAileronPort;
291
292 //! \brief Output port for left elevator position
293 DtAnalogOutputPort* myLeftElevatorPort;
294
295 //! \brief Output port for right elevator position
296 DtAnalogOutputPort* myRightElevatorPort;
297
298 //! \brief Output port for left flap position
299 DtAnalogOutputPort* myLeftFlapPort;
300
301 //! \brief Output port for right flap position
302 DtAnalogOutputPort* myRightFlapPort;
303
304 //! \brief Output port group for all control surfaces
305 DtOutputPortGroup* myControlSurfacesGroup;
306
307 //! \brief Pointer to the real-time dynamics model
308 FixedWingLibCGF::AirplaneDynamics* myDynamics;
309
310 //! \brief Flag indicating whether the entity is player-controlled
312
313 //! \brief Last recorded speed value
315
316 //! \brief Flag to keep landing gear extended when on ground
317 //!
318 //! Keep gears extended if vehicle is placed on ground even if isTouchingGround is (still) false.
319 //! This is required to avoid that gears are retracted due to joystick input while vehicle is on ground.
320 //! Lock is automatically released as soon as isTouchingGround becomes true.
322
323 //! \brief Synchronizes the RTD fuel tank with the VR-Forces fuel resource.
325};
326} // namespace FwlCgfVrf
FixedWingLibCGF::AirplaneDynamics * myDynamics
Pointer to the real-time dynamics model.
Definition vreFwlActuator.h:308
void enableStatePropThresholding(bool enable)
Enables or disables state propagation thresholding.
DtConstrainedAnalogInputPort * myThrottlePort
Input port for throttle control.
Definition vreFwlActuator.h:278
DtAnalogOutputPort * myRudderPort
Output port for rudder position.
Definition vreFwlActuator.h:284
DtAnalogInputPort * myWheelBrakePort
Input port for wheel brake control.
Definition vreFwlActuator.h:269
virtual void processSetRestore(DtSetRestoreRequest *req)
Processes a restore request.
DtIntegerInputPort * myFlapSettingPort
Input port for flap setting.
Definition vreFwlActuator.h:263
static void radioMsgCallback(DtSimMessage *msg, void *usr)
Static callback for radio messages.
DtFixedWingEntityStateRepository * getStateRepository()
Gets the state repository.
DtAnalogOutputPort * myLeftElevatorPort
Output port for left elevator position.
Definition vreFwlActuator.h:293
DtVreFwlActuator(const DtString &name, DtLocalObject *object, DtSimulationServices *simManager, DtComponentDescriptor *compDescriptor, DtReaderWriterRegistry *parentRegistry)
Constructor.
DtBooleanOutputPort * myLandingGearState
Output port for landing gear state.
Definition vreFwlActuator.h:281
bool myPlayerControlled
Flag indicating whether the entity is player-controlled.
Definition vreFwlActuator.h:311
virtual void tick() override
Performs per-frame processing.
void writeOutputData()
Writes output data to ports.
virtual const char * type() const override
Gets the component type.
DtConstrainedAnalogInputPort * myPedalPort
Input port for rudder pedals (yaw)
Definition vreFwlActuator.h:275
const DtVreFwlParameters * getFWParameters()
Gets the fixed-wing parameters.
static DtSimComponent * creator(const DtString &name, DtLocalObject *object, DtSimulationServices *simManager, DtComponentDescriptor *compDescriptor, DtReaderWriterRegistry *parentRegistry)
Component factory function.
DtAnalogInputPort * myAirBrakePort
Input port for air brake control.
Definition vreFwlActuator.h:266
DtBooleanInputPort * myLandingGearPort
Input port for landing gear control.
Definition vreFwlActuator.h:260
DtConstrainedDualAxisAnalogInputPort * myStickPort
Input port for control stick (pitch/roll)
Definition vreFwlActuator.h:272
DtAnalogOutputPort * myLeftFlapPort
Output port for left flap position.
Definition vreFwlActuator.h:299
bool myExtendedGearsLocked
Flag to keep landing gear extended when on ground.
Definition vreFwlActuator.h:321
virtual ~DtVreFwlActuator() override
Virtual destructor.
DtAnalogOutputPort * myRightElevatorPort
Output port for right elevator position.
Definition vreFwlActuator.h:296
virtual void copyStateFromRTD(DtVector &position, DtVector &velocity, DtVector &acceleration, DtTaitBryan &orientation, DtVector &rotVelocity)
Copies state from RTD to provided parameters.
virtual void updateControlSurfaces(bool resetToZero=false)
Updates the control surface positions.
virtual void processSetLocation(DtSetLocationRequest *req)
Processes a location change request.
virtual void processRadioMsg(DtSimMessage *msg)
Processes a radio message.
DtBooleanInputPort * myJoystickEnabledPort
Input port for joystick enabled state.
Definition vreFwlActuator.h:257
virtual void copyStateToRTD()
Copies state from the state repository to RTD.
virtual bool createPorts() override
Creates component ports.
UNIMPLEMENTED_COPYCTOR_AND_ASSIGNMENT_OPERATOR(DtVreFwlActuator)
virtual void processSetHeading(DtSetHeadingRequest *req)
Processes a heading change request.
virtual void setRadio(DtSimRadio *radio) override
Sets the radio interface for this component.
DtOutputPortGroup * myControlSurfacesGroup
Output port group for all control surfaces.
Definition vreFwlActuator.h:305
virtual void copyStateFromRTD()
Copies state from RTD to the state repository.
virtual bool createPortGroups() override
Creates port groups.
DtAnalogOutputPort * myLeftAileronPort
Output port for left aileron position.
Definition vreFwlActuator.h:287
virtual void checkAndClampAircraftOnGround(const DtVector &localPosition)
Checks and adjusts the aircraft position to keep it on the ground.
DtAnalogOutputPort * myRightFlapPort
Output port for right flap position.
Definition vreFwlActuator.h:302
void updateFuelExtendedData()
Publishes the fuel amount used by the frontend displays.
virtual void setSpeed(DtReal speed)
Sets the aircraft speed.
bool isPlayerControlled()
Checks if the entity is currently player-controlled.
DtAnalogOutputPort * myRightAileronPort
Output port for right aileron position.
Definition vreFwlActuator.h:290
void synchronizeFuel()
Synchronizes RTD fuel with the configured VR-Forces resource.
DtReal myLastSpeed
Last recorded speed value.
Definition vreFwlActuator.h:314
DtSimResource * fuelResource()
Returns the configured VR-Forces fuel resource, or nullptr when unavailable.
vreRtd::RtdFuelSynchronizer myFuelSynchronizer
Synchronizes the RTD fuel tank with the VR-Forces fuel resource.
Definition vreFwlActuator.h:324
Fixed-wing parameters for VREngage.
Definition vreFwlParameters.h:41
Synchronizes RTD vehicle fuel with a VR-Forces fuel resource.
Definition vreRtdUtil.h:98
Forward declarations for the FixedWingLibCGF namespace.
Definition vreFwlActuator.h:32
Definition vreFwlActuator.h:37
const char TS_VREngageActuator[]
Type string for VREngage fixed-wing actuator component.
Definition vreFwlActuator.h:43
Common definitions for the RTD backend library.
Utility functions for VREngage RTD components.