VR-Engage  2.3
Loading...
Searching...
No Matches
vreGimbalController.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2026 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file vreGimbalController.h
7//! \ingroup vreVrfmodel
8//! \brief Controller for sensor gimbal movement and targeting
9//!
10//! This file defines the DtVreGimbalController class which extends the base sensor
11//! gimbal controller with VRE-specific functionality. It provides mechanisms for
12//! controlling sensor gimbal movement, targeting, and laser designation.
13
14#pragma once
15
16#include "vreVrfmodel/export.h"
17#include <vrfmodel/sensorGimbalController.h>
18#include "vreVrfModel/vreSimComponent.h"
19
20#include <matrix/vlVector.h>
21#include <matrix/vlTaitBryan.h>
22
23namespace makVrf
24{
25class DtLaserDesignatorStateComponent;
26}
27
28namespace makVre
29{
30class DtVreGimbalControllerDescriptor;
31
32//! \brief Type identifier for the VRE sensor gimbal controller component
33const char DtVreGimbalControllerType[] = "vre-sensor-gimbal-controller";
34
35//! \brief Controller for sensor gimbal movement and targeting
36//!
37//! DtVreGimbalController extends the base sensor gimbal controller with VRE-specific
38//! functionality. It manages the rotation of sensor gimbals to aim sensors at targets,
39//! handles laser designation, and provides mechanisms for object tracking. The controller
40//! supports both joystick-controlled and AI-controlled gimbal movement.
41//! Joystick connection state and the current request count are restored
42//! through VreJoystickControllers.Controllers internal state, using the existing sensor interface.
44 : public DtVreSimComponent<DtSensorGimbalController>
45{
47
48public:
49 //! \brief Constructor
50 //! \param name The name of this component
51 //! \param owner The local object that owns this component
52 //! \param simManager The simulation services manager
53 //! \param desc Component descriptor with configuration parameters
54 //! \param parentRegistry Optional parent registry for reader/writer functionality
55 //!
56 //! Creates a new gimbal controller component with the specified parameters.
57 DtVreGimbalController(const DtString& name, DtLocalObject* owner, DtSimulationServices* simManager,
58 DtComponentDescriptor* desc = 0, DtReaderWriterRegistry* parentRegistry = 0);
59
60 //! \brief Virtual destructor
61 //!
62 //! Cleans up resources used by the gimbal controller component.
63 virtual ~DtVreGimbalController() override;
64
65 //! \brief Gets the type identifier for this component
66 //! \return String identifying the component type (DtVreGimbalControllerType)
67 //!
68 //! Implements the DtSimComponent::type() method to return the
69 //! type identifier for this component.
70 virtual const char* type() const override;
71
72 //! \brief Initializes the gimbal controller
73 //! \return True if initialization succeeded
74 //!
75 //! Powers on VRE gimbal sensors as soon as the backend component is
76 //! initialized so first-created frontend sensor views render scene data.
77 virtual bool init() override;
78
79 //! \brief Runs existing initialization, then restores incoming joystick control.
80 //! \note Ordinary creation, scenario loading, and rewind do not reconnect the joystick.
81 virtual void preFirstTickInit() override;
82
83 //! \brief Calculates and sets port values based on function input
84 //! \param functionGroup The function group identifier
85 //! \param function The specific function name
86 //! \param value The input value to process
87 //! \param repeat Flag indicating whether the function should repeat
88 //!
89 //! Processes input from function ports (typically joystick inputs) and
90 //! applies the appropriate transforms to control the gimbal movement.
92 const DtString& functionGroup, const DtString& function, double value, bool repeat) override;
93
94 //! \brief Finds the world location that a sensor is aiming at
95 //! \param location The geocentric location of the sensor
96 //! \param orientation The orientation of the sensor
97 //! \param aimingPoint Output parameter that will contain the aiming point if found
98 //! \return True if an aiming point was successfully found, false otherwise
99 //!
100 //! Determines the world location that a sensor is currently aiming at,
101 //! based on the sensor's location, orientation, and internal configuration.
103 const DtVector& location, const DtTaitBryan& orientation, DtVector& aimingPoint) const override;
104
105 //! \brief Chooses an appropriate laser designator object as the target to engage
106 //! \return Pointer to the selected designator component, or NULL if no valid target found
107 //!
108 //! Searches for and selects an appropriate laser designator object to engage as
109 //! a target. Uses targetDesignatorValid() to check if each potential target is valid.
110 //! This method enables sensors to track laser-designated targets.
111 virtual const makVrf::DtLaserDesignatorStateComponent* lookupDesignator() const;
112
113 //! \brief Processes a message to set the gimbal aim direction
114 //! \param msg Pointer to the simulation message containing aim parameters
115 //!
116 //! Handles messages requesting to set the aiming direction of the gimbal.
117 //! Extracts the target aiming information from the message and applies it
118 //! to the gimbal controller.
119 virtual void processSetAimGimbal(DtSimMessage* msg) override;
120
121 //! \brief Stops tracking, keeps the current elevation, and returns azimuth to neutral
122 virtual void holdCurrentAim();
123
124 //! \brief Updates the current laser designator target location
125 //!
126 //! Refreshes the stored location of the current laser designator target.
127 //! This keeps the gimbal controller's understanding of the target position
128 //! up to date for accurate tracking.
130
131 //! \brief Updates the controller state each simulation frame
132 //!
133 //! Overridden to allow object tracking while in joystick mode. This method
134 //! is called each simulation frame to update the gimbal orientation based
135 //! on current tracking targets and input controls.
136 virtual void tick() override;
137
138 //! \brief Determines the target point based on orientation and maximum laser range
139 //! \param orientation The orientation to calculate the target point from
140 //! \param location Output parameter that will contain the target point if found
141 //! \return True if a target point was successfully found, false otherwise
142 //!
143 //! Overridden to respect the maximum range of the laser when determining target points.
144 //! Calculates the point in world space that corresponds to the given orientation
145 //! and the configured maximum laser range.
146 virtual bool targetPoint(const DtTaitBryan& orientation, DtVector& location) const override;
147
148protected:
149 //! \brief Handles joystick connection events
150 //!
151 //! Keeps the VRE gimbal sensor powered on when a player role takes control
152 //! of the gimbal joystick function group and persists the current joystick state.
153 virtual void joystickConnected() override;
154
155 //! \brief Runs the sensor's normal disconnection hook and persists the disabled state.
156 virtual void joystickDisconnected() override;
157
158 //! \brief Calls the inherited request handler once and persists count-only changes.
159 //! \param msg The original joystick device request message.
160 virtual void processJoyDeviceRequest(DtSimMessage* msg) override;
161
162 //! \brief Writes the existing sensor interface's enabled flag and exact request count.
164
165 //! \brief Restores incoming state and reconnects the original sensor joystick callback once.
167
168 //! \brief Aims the sensor at a specified world location
169 //! \param worldLocation The geocentric world location to aim at
170 //!
171 //! Attempts to adjust the gimbal orientation so that the sensor is aimed
172 //! at the specified world location. Calculates the appropriate azimuth and
173 //! elevation angles to achieve the desired aiming point.
174 virtual void aimSensorAtPoint(const DtVector& worldLocation) override;
175
176private:
177 //! \brief Remembers incoming conversion until first-tick initialization consumes it.
179
180 //! \brief Default constructor (not implemented)
181 //!
182 //! Default constructor is private and not implemented to prevent
183 //! creation of instances without proper initialization.
185
186 //! \brief Copy constructor (not implemented)
187 //!
188 //! Copy constructor is private and not implemented to prevent
189 //! copy construction.
191
192 //! \brief Assignment operator (not implemented)
193 //! \return Reference to this object
194 //!
195 //! Assignment operator is private and not implemented to prevent assignment.
197
198public:
199 //! \brief Factory method to create a new instance of this component
200 //! \param name The name for the new component
201 //! \param object The local object that will own this component
202 //! \param simManager The simulation services manager
203 //! \param compDescriptor Optional component descriptor
204 //! \param parentRegistry Optional parent registry for reader/writer functionality
205 //! \return Pointer to the newly created component
206 //!
207 //! Static factory method used by the component creation system to instantiate
208 //! new instances of this component type.
209 static DtSimComponent* creator(const DtString& name, DtLocalObject* object, DtSimulationServices* simManager,
210 DtComponentDescriptor* compDescriptor, DtReaderWriterRegistry* parentRegistry);
211
212protected:
213 //! \brief Pointer to the gimbal controller descriptor
214 //!
215 //! Contains the configuration parameters for this gimbal controller component.
216 DtVreGimbalControllerDescriptor* myVreGimbalDescriptor;
217
218 //! \brief Gets the current terrain check distance
219 //! \return The current distance to check for terrain intersections
220 //!
221 //! Returns the current distance value used for terrain intersection checks.
222 //! Used to handle terrain loading latency issues by progressively checking
223 //! at different distances.
224 double checkDistance() const;
225
226 //! \brief Increases the terrain check distance
227 //!
228 //! Increments the terrain check distance when a previous check fails.
229 //! Helps handle terrain loading latency by progressively increasing the
230 //! check distance until terrain is found or the maximum is reached.
232
233 //! \brief Resets the terrain check distance to the minimum value
234 //!
235 //! Resets the terrain check distance back to the minimum configured value.
236 //! Called when starting a new series of terrain checks.
237 void resetCheckDistance() const;
238
239 //! \brief Minimum distance for terrain intersection checks
240 //!
241 //! The starting (minimum) distance used for terrain intersection checks.
242 //! This is the initial value used when resetting the check distance.
244
245 //! \brief Current distance for terrain intersection checks
246 //!
247 //! The current distance being used for terrain intersection checks.
248 //! May be modified during runtime as checks are performed.
250
251 //! \brief Maximum distance for terrain intersection checks
252 //!
253 //! The maximum distance to use for terrain intersection checks.
254 //! Once this value is reached, no further increases will occur.
256
257 //! \brief Laser code for designation
258 //!
259 //! The code used for laser designation. This helps identify specific
260 //! laser designators when multiple are present in the simulation.
262
263 //! \brief Flag indicating whether continuous tracking is enabled
264 //!
265 //! When true, indicates that the gimbal should continuously track
266 //! the target, even in joystick control mode.
268
269 //! Sim time at which a deferred end-of-task hold is applied, or negative if none is pending.
270 double myPendingHoldTime = -1.0;
271
272};
273
274} // namespace makVre
double checkDistance() const
Gets the current terrain check distance.
virtual ~DtVreGimbalController() override
Virtual destructor.
void resetCheckDistance() const
Resets the terrain check distance to the minimum value.
double myCurrentCheckDistance
Current distance for terrain intersection checks.
Definition vreGimbalController.h:249
virtual void processJoyDeviceRequest(DtSimMessage *msg) override
Calls the inherited request handler once and persists count-only changes.
virtual void tick() override
Updates the controller state each simulation frame.
DtVreGimbalController()
Default constructor (not implemented)
virtual bool targetPoint(const DtTaitBryan &orientation, DtVector &location) const override
Determines the target point based on orientation and maximum laser range.
virtual void preFirstTickInit() override
Runs existing initialization, then restores incoming joystick control.
double myPendingHoldTime
Sim time at which a deferred end-of-task hold is applied, or negative if none is pending.
Definition vreGimbalController.h:270
virtual void aimSensorAtPoint(const DtVector &worldLocation) override
Aims the sensor at a specified world location.
DtVreGimbalController(const DtVreGimbalController &orig)
Copy constructor (not implemented)
virtual void joystickDisconnected() override
Runs the sensor's normal disconnection hook and persists the disabled state.
int myLaserCode
Laser code for designation.
Definition vreGimbalController.h:261
void increaseCheckDistance() const
Increases the terrain check distance.
virtual void updateDesignatorLocation()
Updates the current laser designator target location.
virtual bool init() override
Initializes the gimbal controller.
virtual void calcAndSetPortValues(const DtString &functionGroup, const DtString &function, double value, bool repeat) override
Calculates and sets port values based on function input.
static DtSimComponent * creator(const DtString &name, DtLocalObject *object, DtSimulationServices *simManager, DtComponentDescriptor *compDescriptor, DtReaderWriterRegistry *parentRegistry)
Factory method to create a new instance of this component.
virtual void joystickConnected() override
Handles joystick connection events.
const DtVreGimbalController & operator=(const DtVreGimbalController &orig)
Assignment operator (not implemented)
void updateJoystickState()
Writes the existing sensor interface's enabled flag and exact request count.
DtVreSimComponent< DtSensorGimbalController > Base
Definition vreGimbalController.h:46
virtual const char * type() const override
Gets the type identifier for this component.
virtual void holdCurrentAim()
Stops tracking, keeps the current elevation, and returns azimuth to neutral.
DtVreGimbalControllerDescriptor * myVreGimbalDescriptor
Pointer to the gimbal controller descriptor.
Definition vreGimbalController.h:216
virtual void processSetAimGimbal(DtSimMessage *msg) override
Processes a message to set the gimbal aim direction.
DtVreGimbalController(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Constructor.
double myMaxCheckDistance
Maximum distance for terrain intersection checks.
Definition vreGimbalController.h:255
virtual const makVrf::DtLaserDesignatorStateComponent * lookupDesignator() const
Chooses an appropriate laser designator object as the target to engage.
bool myRestoreJoystickState
Remembers incoming conversion until first-tick initialization consumes it.
Definition vreGimbalController.h:178
double myMinCheckDistance
Minimum distance for terrain intersection checks.
Definition vreGimbalController.h:243
void restoreJoystickState()
Restores incoming state and reconnects the original sensor joystick callback once.
virtual bool findLocationOfSensorAiming(const DtVector &location, const DtTaitBryan &orientation, DtVector &aimingPoint) const override
Finds the world location that a sensor is aiming at.
bool myContinuousTrack
Flag indicating whether continuous tracking is enabled.
Definition vreGimbalController.h:267
DtVreSimComponent(const DtString &name, DtLocalObject *owner, DtSimulationServices *simManager, DtComponentDescriptor *desc=0, DtReaderWriterRegistry *parentRegistry=0)
Definition vreSimComponent.h:63
Defines export macros for the vreVrfmodel library.
#define VREVRFMODEL_DLL
Definition export.h:22
!
Definition glsVreMessageUtil.h:50
const char DtVreGimbalControllerType[]
Type identifier for the VRE sensor gimbal controller component.
Definition vreGimbalController.h:33
Definition connectorAccessory.h:38