VR-Engage  2.3
Loading...
Searching...
No Matches
driverControlLogic.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2025 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file driverControlLogic.h
7//! \brief Defines the DtDriverControlLogic component for controlling ground vehicle operation.
8//!
9//! This component provides comprehensive vehicle control functionality including steering,
10//! throttle, braking, gear shifting, and auxiliary systems (headlights, differential lock, etc.)
11//!
12//! \ingroup vreCommonComponents
13
14#pragma once
15
17
19
21
22namespace makVre
23{
24//! \brief Forward declaration of the initialization table class
25class DtInitTable;
26
28{
29//! \ingroup RoleConfigParams
30//! \defgroup DriverControlLogicRoleParams Driver Control Logic Role Parameters
31//! \roleInherits{EntityControlLogicRoleParams}
32//! Configuration Options for driver role.
33//! @{
34
35//! \vreRoleParam{hasDifferentialLock,bool,false,driverControlLogic,Determines whether or not this role will have diff lock.}
36constexpr const char* hasDifferentialLock = "hasDifferentialLock";
37
38//! \vreRoleParam{canPivot,bool,false,driverControlLogic,Determines whether or not this role has the ability to pivot.}
39constexpr const char* canPivot = "canPivot";
40
41//! \vreRoleParam{showInclinometer,bool,false,driverControlLogic,Determines whether to show the inclinometer instrument displaying entity pitch and roll.}
42constexpr const char* showInclinometer = "showInclinometer";
43//! @}
44} // namespace DriverControlLogicConfig
45
46//! \brief Type identifier for DtDriverControlLogic component
47constexpr const char* DtDriverControlLogicType = "DtDriverControlLogic";
48
49//! \brief Component for controlling ground vehicle operation
50//!
51//! The DtDriverControlLogic provides functionality for controlling various aspects of ground
52//! vehicles. This includes basic driving controls (steering, throttle, braking), transmission
53//! controls (gear shifting), and auxiliary systems (engine, differential lock, parking brake,
54//! headlights, and pivot steering).
55//!
56//! It also maintains vehicle state information through attributes and handles resource
57//! updates for systems like fuel levels.
59{
60public:
61 //! \brief Constructor for DtDriverControlLogic
62 //!
63 //! Initializes the component with default values and checks out the required
64 //! VR Engage Ground license.
66
67 //! \brief Virtual destructor for DtDriverControlLogic
68 virtual ~DtDriverControlLogic() override;
69
70 //! \brief Initializes the component with configuration from Lua
71 //!
72 //! Sets up input handlers, initializes state attributes, and subscribes to resource updates.
73 //! Configures vehicle capabilities based on Lua settings (differential lock and pivot steering).
74 //!
75 //! \param player Pointer to the player station this component belongs to
76 //! \param config Configuration table containing initialization parameters
77 //! \return True if initialization succeeds, false otherwise
79
80 //! \brief Updates the component state
81 //!
82 //! Updates the headlight state attribute based on the vehicle's current appearance.
83 //!
84 //! \param dt Delta time in seconds since the last tick
85 virtual void tick(double dt) override;
86
87 //! \brief Shuts down the component
88 //!
89 //! Unsubscribes from resource updates, removes callbacks, and cleans up input handlers.
90 virtual void shutdown() override;
91
92 //! \brief Returns the component type identifier
93 //! \return The component type string
94 virtual const char* type() const override;
95
96 //! \brief Input handler functions
97 //! @{
98
99 //! \brief Handles left steering input
100 //!
101 //! Inverts the value and passes it to setSteering().
102 //!
103 //! \param val The input value, typically from 0.0 to 1.0
104 virtual void steerLeft(float val);
105
106 //! \brief Handles right steering input
107 //!
108 //! Passes the value directly to setSteering().
109 //!
110 //! \param val The input value, typically from 0.0 to 1.0
111 virtual void steerRight(float val);
112
113 //! \brief Sets the vehicle's steering value
114 //!
115 //! Sends a "Steering" joystick message with the provided value.
116 //!
117 //! \param val The steering value, from -1.0 (full left) to 1.0 (full right)
118 virtual void setSteering(double val);
119
120 //! \brief Sets the vehicle's throttle value
121 //!
122 //! Sends a "Throttle" joystick message with the provided value.
123 //!
124 //! \param val The throttle value, typically from 0.0 to 1.0
125 virtual void setThrottle(double val);
126
127 //! \brief Sets the vehicle's brake value
128 //!
129 //! Sends a "Brake" joystick message with the provided value.
130 //!
131 //! \param val The brake value, typically from 0.0 to 1.0
132 virtual void setBrake(double val);
133
134 //! \brief Shifts up to the next gear
135 //!
136 //! Sends a "GearUp" joystick message with the provided value.
137 //!
138 //! \param val The input value, a value of 1.0 triggers the gear shift
139 virtual void setGearUp(double val);
140
141 //! \brief Shifts down to the previous gear
142 //!
143 //! Sends a "GearDown" joystick message with the provided value.
144 //!
145 //! \param val The input value, a value of 1.0 triggers the gear shift
146 virtual void setGearDown(double val);
147
148 //! \brief Toggles the engine on/off
149 //!
150 //! Sends an "EngineEnable" joystick message with the provided value.
151 //!
152 //! \param val The input value, a value of 1.0 typically toggles the engine state
153 virtual void setEngineEnable(double val);
154
155 //! \brief Toggles the differential lock
156 //!
157 //! Sends a "DifferentialLock" joystick message with the provided value.
158 //! Only applies to vehicles with differential lock capability.
159 //!
160 //! \param val The input value, a value of 1.0 typically toggles the differential lock
161 virtual void setDifferentialLock(double val);
162
163 //! \brief Toggles the parking brake
164 //!
165 //! Sends a "ParkingBrake" joystick message with the provided value.
166 //!
167 //! \param val The input value, a value of 1.0 typically toggles the parking brake
168 virtual void setParkingBrake(double val);
169
170 //! \brief Toggles the headlights
171 //!
172 //! Sends a "Headlights" joystick message with the provided value.
173 //!
174 //! \param val The input value, a value of 1.0 typically toggles the headlights
175 virtual void setHeadlights(double val);
176
177 //! \brief Controls pivot steering
178 //!
179 //! Sends a "Pivot" joystick message with the provided value.
180 //! Only applies to vehicles with pivot steering capability.
181 //!
182 //! \param val The input value
183 virtual void setPivot(double val);
184
185 //! @}
186
187 //! \brief Sends a joystick message to the simulation
188 //!
189 //! Helper function called by the various control functions to send
190 //! joystick messages with the appropriate parameters.
191 //!
192 //! \param function The function name to include in the message
193 //! \param val The function value to include in the message
194 //! \param delay Optional delay before sending the message (defaults to 0)
195 virtual void sendJoystickMessage(const std::string& function, double val, double delay = 0);
196
197protected:
198 //! \brief Input handler logic for processing input device events
200
201 //! \brief Main joystick function group name from configuration
202 //!
203 //! Used to identify the function group when sending joystick messages.
205
206 //! \brief Flag indicating if this vehicle is capable of pivot steering
207 //!
208 //! When true, enables pivot steering functionality. This value is stored in
209 //! the "canPivot" state attribute. Defaults to false.
211
212 //! \brief Flag indicating if this vehicle has a differential lock
213 //!
214 //! When true, enables differential lock functionality. This value is stored in
215 //! the "hasDifferentialLock" state attribute. Defaults to false.
217
218 // Sets whether to show the inclinometer instrument. This shows the entity's pitch and roll.
220
221 //! \brief Attribute handle storing the current fuel amount.
222 //! \vreAttrKey{fuel}
224
225 //! \brief Attribute handle storing the full-tank fuel capacity.
226 //! \vreAttrKey{fuelFullAmount}
228
229 //! \vreAttrKey{ownship.position}
231
232 //! \vreAttrKey{ownship.orientation}
234
235 //! \vreAttrKey{ownship.localPosition}
237
238 //! \vreAttrKey{ownship.yaw}
240
241 //! \vreAttrKey{ownship.pitch}
243
244 //! \vreAttrKey{ownship.roll}
246
247 //! \vreAttrKey{ownship.localOrientation}
249
250};
251
252} // namespace makVre
Type-specific handle class for attributes.
Definition attributeHandle.h:229
virtual void setSteering(double val)
Sets the vehicle's steering value.
DtAttributeHandleType< double > myFuelAttr
Attribute handle storing the current fuel amount.
Definition driverControlLogic.h:223
DtAttributeHandleType< DtTaitBryan > myLocalOrientationAttr
Definition driverControlLogic.h:248
bool myShowInclinometer
Definition driverControlLogic.h:219
DtAttributeHandleType< double > myFuelFullAmountAttr
Attribute handle storing the full-tank fuel capacity.
Definition driverControlLogic.h:227
DtAttributeHandleType< DtTaitBryan > myOrientationAttr
Definition driverControlLogic.h:233
virtual bool initialize(makVre::DtPlayerStation *player, makVre::DtInitTable &config) override
Initializes the component with configuration from Lua.
DtAttributeHandleType< DtVector > myPositionAttr
Definition driverControlLogic.h:230
std::string myMainJoystickGroup
Main joystick function group name from configuration.
Definition driverControlLogic.h:204
DtAttributeHandleType< double > myRollAttr
Definition driverControlLogic.h:245
virtual void setHeadlights(double val)
Toggles the headlights.
bool myHasDifferentialLock
Flag indicating if this vehicle has a differential lock.
Definition driverControlLogic.h:216
virtual void setPivot(double val)
Controls pivot steering.
bool myCanPivot
Flag indicating if this vehicle is capable of pivot steering.
Definition driverControlLogic.h:210
virtual void steerLeft(float val)
Input handler functions.
virtual void setGearDown(double val)
Shifts down to the previous gear.
virtual void setEngineEnable(double val)
Toggles the engine on/off.
virtual void shutdown() override
Shuts down the component.
virtual void setParkingBrake(double val)
Toggles the parking brake.
virtual const char * type() const override
Returns the component type identifier.
DtAttributeHandleType< DtVector > myLocalPositionAttr
Definition driverControlLogic.h:236
DtDriverControlLogic()
Constructor for DtDriverControlLogic.
DtInputLogic myDriverInputLogic
Input handler logic for processing input device events.
Definition driverControlLogic.h:199
DtAttributeHandleType< double > myPitchAttr
Definition driverControlLogic.h:242
virtual void setGearUp(double val)
Shifts up to the next gear.
virtual void setDifferentialLock(double val)
Toggles the differential lock.
virtual void sendJoystickMessage(const std::string &function, double val, double delay=0)
Sends a joystick message to the simulation.
virtual ~DtDriverControlLogic() override
Virtual destructor for DtDriverControlLogic.
virtual void setBrake(double val)
Sets the vehicle's brake value.
virtual void steerRight(float val)
Handles right steering input.
virtual void setThrottle(double val)
Sets the vehicle's throttle value.
DtAttributeHandleType< double > myYawAttr
Definition driverControlLogic.h:239
virtual void tick(double dt) override
Updates the component state.
Component that provides entity control functionality.
Definition entityControlLogic.h:64
Table-based access to Lua state for configuration data.
Definition initializer.h:38
Class for managing input configuration and handling in VR-Engage.
Definition inputLogic.h:39
virtual DtPlayerStation & player()
Gets the player station.
Class for managing the user interface for engaged roles.
Definition playerStation.h:51
Defines the logic for controlling entities in VR-Engage.
constexpr const char * canPivot
Definition driverControlLogic.h:39
constexpr const char * hasDifferentialLock
Definition driverControlLogic.h:36
constexpr const char * showInclinometer
Definition driverControlLogic.h:42
Defines export/import macros for the vreCommonComponents library.
#define VRECOMMONCOMPONENTS_DLL
DLL export/import macro for the vreCommonComponents library.
Definition export.h:28
Definition driverControlLogic.h:28
!
Definition glsVreMessageUtil.h:50
constexpr const char * DtDriverControlLogicType
Type identifier for DtDriverControlLogic component.
Definition driverControlLogic.h:47
Defines the base class for all VREngage messages.