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