RavEngine
Loading...
Searching...
No Matches
DirectDrivetrain.h
1// Redistribution and use in source and binary forms, with or without
2// modification, are permitted provided that the following conditions
3// are met:
4// * Redistributions of source code must retain the above copyright
5// notice, this list of conditions and the following disclaimer.
6// * Redistributions in binary form must reproduce the above copyright
7// notice, this list of conditions and the following disclaimer in the
8// documentation and/or other materials provided with the distribution.
9// * Neither the name of NVIDIA CORPORATION nor the names of its
10// contributors may be used to endorse or promote products derived
11// from this software without specific prior written permission.
12//
13// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
14// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24//
25// Copyright (c) 2008-2022 NVIDIA Corporation. All rights reserved.
26// Copyright (c) 2004-2008 AGEIA Technologies, Inc. All rights reserved.
27// Copyright (c) 2001-2004 NovodeX AG. All rights reserved.
28
29#pragma once
30
31#include "vehicle2/PxVehicleAPI.h"
32#include "../physxintegration/PhysXIntegration.h"
33
34namespace snippetvehicle2
35{
36
37using namespace physx;
38using namespace physx::vehicle2;
39
41{
42 PxVehicleDirectDriveThrottleCommandResponseParams directDriveThrottleResponseParams;
43
44 DirectDrivetrainParams transformAndScale(
45 const PxVehicleFrame& srcFrame, const PxVehicleFrame& trgFrame, const PxVehicleScale& srcScale, const PxVehicleScale& trgScale) const;
46
47 PX_FORCE_INLINE bool isValid(const PxVehicleAxleDescription& axleDesc) const
48 {
49 if (!directDriveThrottleResponseParams.isValid(axleDesc))
50 return false;
51
52 return true;
53 }
54};
55
57{
58 PxReal directDriveThrottleResponseStates[PxVehicleLimits::eMAX_NB_WHEELS];
59
60 PX_FORCE_INLINE void setToDefault()
61 {
62 PxMemZero(this, sizeof(DirectDrivetrainState));
63 }
64};
65
66
67//
68//This class holds the parameters, state and logic needed to implement a vehicle that
69//is using a direct drivetrain.
70//
71//See BaseVehicle for more details on the snippet code design.
72//
74 : public PhysXActorVehicle
78{
79public:
80 bool initialize(PxPhysics& physics, const PxCookingParams& params, PxMaterial& defaultMaterial, bool addPhysXBeginEndComponents = true);
81 virtual void destroy();
82
83 virtual void initComponentSequence(bool addPhysXBeginEndComponents);
84
86 const PxVehicleAxleDescription*& axleDescription,
88 const PxVehicleDirectDriveThrottleCommandResponseParams*& throttleResponseParams,
89 const PxVehicleSteerCommandResponseParams*& steerResponseParams,
91 const PxVehicleCommandState*& commands, const PxVehicleDirectDriveTransmissionCommandState*& transmissionCommands,
92 const PxVehicleRigidBodyState*& rigidBodyState,
93 PxVehicleArrayData<PxReal>& brakeResponseStates, PxVehicleArrayData<PxReal>& throttleResponseStates,
94 PxVehicleArrayData<PxReal>& steerResponseStates)
95 {
96 axleDescription = &mBaseParams.axleDescription;
97 brakeResponseParams.setDataAndCount(mBaseParams.brakeResponseParams, sizeof(mBaseParams.brakeResponseParams) / sizeof(PxVehicleBrakeCommandResponseParams));
98 throttleResponseParams = &mDirectDriveParams.directDriveThrottleResponseParams;
99 steerResponseParams = &mBaseParams.steerResponseParams;
100 ackermannParams.setDataAndCount(mBaseParams.ackermannParams, sizeof(mBaseParams.ackermannParams)/sizeof(PxVehicleAckermannParams));
101 commands = &mCommandState;
102 transmissionCommands = &mTransmissionCommandState;
103 rigidBodyState = &mBaseState.rigidBodyState;
104 brakeResponseStates.setData(mBaseState.brakeCommandResponseStates);
105 throttleResponseStates.setData(mDirectDriveState.directDriveThrottleResponseStates);
106 steerResponseStates.setData(mBaseState.steerCommandResponseStates);
107 }
108
110 const PxVehicleAxleDescription*& axleDescription,
111 PxVehicleArrayData<const PxReal>& brakeResponseStates,
112 PxVehicleArrayData<const PxReal>& throttleResponseStates,
114 {
115 axleDescription = &mBaseParams.axleDescription;
116 brakeResponseStates.setData(mBaseState.brakeCommandResponseStates);
117 throttleResponseStates.setData(mDirectDriveState.directDriveThrottleResponseStates);
118 actuationStates.setData(mBaseState.actuationStates);
119 }
120
121 virtual void getDataForDirectDrivetrainComponent(
122 const PxVehicleAxleDescription*& axleDescription,
123 PxVehicleArrayData<const PxReal>& brakeResponseStates,
124 PxVehicleArrayData<const PxReal>& throttleResponseStates,
129 {
130 axleDescription = &mBaseParams.axleDescription;
131 brakeResponseStates.setData(mBaseState.brakeCommandResponseStates);
132 throttleResponseStates.setData(mDirectDriveState.directDriveThrottleResponseStates);
133 wheelParams.setData(mBaseParams.wheelParams);
134 actuationStates.setData(mBaseState.actuationStates);
135 tireForces.setData(mBaseState.tireForces);
136 wheelRigidBody1dStates.setData(mBaseState.wheelRigidBody1dStates);
137 }
138
139
140 //Parameters and states of the vehicle's direct drivetrain.
141 DirectDrivetrainParams mDirectDriveParams;
142 DirectDrivetrainState mDirectDriveState;
143
144 //The commands that will control the vehicle's transmission
145 PxVehicleDirectDriveTransmissionCommandState mTransmissionCommandState;
146};
147
148}//namespace snippetvehicle2
Material class to represent a set of surface properties.
Definition PxMaterial.h:149
Abstract singleton factory class used for instancing objects in the Physics SDK.
Definition PxPhysics.h:91
Determine the actuation state for each wheel of a direct drive vehicle.
Definition PxVehicleDrivetrainComponents.h:177
Forward the applicable set of control values for a direct drive vehicle to a command response state f...
Definition PxVehicleDrivetrainComponents.h:75
Forward integrate the angular speed of each wheel on a vehicle by integrating the brake and drive tor...
Definition PxVehicleDrivetrainComponents.h:237
Definition DirectDrivetrain.h:78
void getDataForDirectDriveCommandResponseComponent(const PxVehicleAxleDescription *&axleDescription, PxVehicleSizedArrayData< const PxVehicleBrakeCommandResponseParams > &brakeResponseParams, const PxVehicleDirectDriveThrottleCommandResponseParams *&throttleResponseParams, const PxVehicleSteerCommandResponseParams *&steerResponseParams, PxVehicleSizedArrayData< const PxVehicleAckermannParams > &ackermannParams, const PxVehicleCommandState *&commands, const PxVehicleDirectDriveTransmissionCommandState *&transmissionCommands, const PxVehicleRigidBodyState *&rigidBodyState, PxVehicleArrayData< PxReal > &brakeResponseStates, PxVehicleArrayData< PxReal > &throttleResponseStates, PxVehicleArrayData< PxReal > &steerResponseStates)
Provide vehicle data items for this component.
Definition DirectDrivetrain.h:85
virtual void getDataForDirectDriveActuationStateComponent(const PxVehicleAxleDescription *&axleDescription, PxVehicleArrayData< const PxReal > &brakeResponseStates, PxVehicleArrayData< const PxReal > &throttleResponseStates, PxVehicleArrayData< PxVehicleWheelActuationState > &actuationStates)
Provide vehicle data items for this component.
Definition DirectDrivetrain.h:109
Definition PhysXIntegration.h:116
#define PX_FORCE_INLINE
Definition PxPreprocessor.h:335
Sorts an array of objects in ascending order, assuming that the predicate implements the < operator:
Definition PxBoxController.h:39
PX_FORCE_INLINE void * PxMemZero(void *dest, PxU32 count)
Sets the bytes of the provided buffer to zero.
Definition PxMemory.h:53
Structure describing parameters affecting mesh cooking.
Definition PxCooking.h:185
A description of a single axle that is to be affected by Ackermann steer correction.
Definition PxVehicleSteeringParams.h:86
Helper struct to pass array type data to vehice components and functions.
Definition PxVehicleParams.h:249
PX_FORCE_INLINE void setData(T *data)
Set the data as an array of structs.
Definition PxVehicleParams.h:261
Definition PxVehicleParams.h:53
Distribute a brake response to the wheels of a vehicle.
Definition PxVehicleBrakingParams.h:56
A description of the state of commands that are applied to the vehicle.
Definition PxVehicleCommandStates.h:53
Distribute a throttle response to the wheels of a direct drive vehicle.
Definition PxVehicleDrivetrainParams.h:57
A description of the state of transmission-related commands that are applied to a vehicle with direct...
Definition PxVehicleCommandStates.h:69
Definition PxVehicleParams.h:174
Definition PxVehicleRigidBodyStates.h:47
Definition PxVehicleParams.h:224
Definition PxVehicleParams.h:369
PX_FORCE_INLINE void setDataAndCount(T *data, const PxU32 count)
Set the data as an array of structs and set the number of data entries.
Definition PxVehicleParams.h:376
Distribute a steer response to the wheels of a vehicle.
Definition PxVehicleSteeringParams.h:58
Definition DirectDrivetrain.h:41
Definition DirectDrivetrain.h:57