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