@@ -180,73 +180,48 @@ namespace ROS2::VehicleDynamics::Utilities
180
180
continue ;
181
181
}
182
182
183
- PhysX::HingeJointComponent* hingeComponent{ nullptr };
184
- hingeComponent = wheelEntity->FindComponent <PhysX::HingeJointComponent>();
185
-
186
- PhysX::ArticulationLinkComponent* articulation{ nullptr };
187
- articulation = wheelEntity->FindComponent <PhysX::ArticulationLinkComponent>();
188
-
189
- if (!hingeComponent && !articulation)
190
- {
191
- AZ_Warning (
192
- " GetAllDriveWheelsData" ,
193
- false ,
194
- " Wheel entity for axle %s does not have a HingeJointComponent nor an ArticulationLinkComponent, ignoring" ,
195
- axle.m_axleTag .c_str ());
196
- continue ;
197
- }
198
-
199
- if (articulation)
200
- {
201
- if (articulation->m_config .m_articulationJointType != PhysX::ArticulationJointType::Hinge)
202
- {
203
- AZ_Warning (
204
- " GetAllDriveWheelsData" ,
205
- false ,
206
- " Wheel entity for axle %s has an Articulation Link, but it's not a hinge joint, ignoring" ,
207
- wheel.ToString ().c_str ());
208
- continue ;
209
- }
210
- }
211
-
212
- VehicleDynamics::WheelDynamicsData wheelData;
213
- wheelData.m_isArticulation = articulation;
214
- wheelData.m_wheelEntity = wheel;
215
- if (articulation)
216
- {
217
- wheelData.m_wheelJoint = articulation->GetId ();
218
- const bool hasFreeAxis = Utils::TryGetFreeArticulationAxis (wheelData.m_wheelEntity , wheelData.m_axis );
219
-
220
- AZ_Error (" VehicleDynamics::Utilities" , hasFreeAxis, " Articulation wheel has no free axis somehow" );
221
- }
222
- else
223
- {
224
- wheelData.m_wheelJoint = hingeComponent->GetId ();
225
- }
226
- wheelData.m_wheelRadius = axle.m_wheelRadius ;
183
+ VehicleDynamics::WheelDynamicsData wheelData = GetWheelData (wheel, axle.m_wheelRadius );
227
184
driveWheelEntities.push_back (wheelData);
228
185
}
229
186
}
230
187
return driveWheelEntities;
231
188
}
232
189
233
- AZ::EntityComponentIdPair GetWheelPhysxHinge (const AZ::EntityId wheelEntityId)
190
+ VehicleDynamics::WheelDynamicsData GetWheelData (const AZ::EntityId wheelEntityId, float wheelRadius )
234
191
{
192
+ VehicleDynamics::WheelDynamicsData wheelData;
193
+ wheelData.m_wheelEntity = wheelEntityId;
194
+ wheelData.m_wheelRadius = wheelRadius;
235
195
AZ::Entity* wheelEntity = nullptr ;
236
196
AZ::ComponentApplicationBus::BroadcastResult (wheelEntity, &AZ::ComponentApplicationRequests::FindEntity, wheelEntityId);
237
197
if (!wheelEntity)
238
198
{
239
199
AZ_Warning (" GetWheelDynamicData" , false , " Entity %s was not found" , wheelEntityId.ToString ().c_str ());
240
- return AZ::EntityComponentIdPair () ;
200
+ return wheelData ;
241
201
}
242
202
PhysX::HingeJointComponent* hingeComponent{ nullptr };
243
203
hingeComponent = wheelEntity->FindComponent <PhysX::HingeJointComponent>();
244
- if (!hingeComponent)
204
+
205
+ PhysX::ArticulationLinkComponent* articulationComponent{ nullptr };
206
+ articulationComponent = wheelEntity->FindComponent <PhysX::ArticulationLinkComponent>();
207
+
208
+ if (hingeComponent)
209
+ {
210
+ wheelData.m_isArticulation = false ;
211
+ wheelData.m_wheelJoint = hingeComponent->GetId ();
212
+ return wheelData;
213
+ }
214
+ if (articulationComponent)
245
215
{
246
- AZ_Warning (" GetWheelDynamicData" , false , " Entity %s has no PhysX::HingeJointComponent" , wheelEntityId.ToString ().c_str ());
247
- return AZ::EntityComponentIdPair ();
216
+ wheelData.m_isArticulation = true ;
217
+ Utils::TryGetFreeArticulationAxis (wheelEntityId, wheelData.m_axis );
218
+ wheelData.m_wheelJoint = articulationComponent->GetId ();
219
+ return wheelData;
220
+
248
221
}
249
- return AZ::EntityComponentIdPair (wheelEntityId, hingeComponent->GetId ());
222
+
223
+ AZ_Warning (" GetWheelDynamicData" , false , " Entity %s has no PhysX::HingeJointComponent" , wheelEntityId.ToString ().c_str ());
224
+ return wheelData;
250
225
}
251
226
252
227
float ComputeRampVelocity (float targetVelocty, float lastVelocity, AZ::u64 deltaTimeNs, float acceleration, float maxVelocity)
@@ -268,4 +243,27 @@ namespace ROS2::VehicleDynamics::Utilities
268
243
}
269
244
return AZStd::clamp (commandVelocity, -maxVelocity, maxVelocity);
270
245
}
246
+
247
+ void SetWheelRotationSpeed (const VehicleDynamics::WheelDynamicsData& data, float wheelRotationSpeed)
248
+ {
249
+ if (data.m_isArticulation )
250
+ {
251
+ PhysX::ArticulationJointRequestBus::Event (
252
+ data.m_wheelEntity , &PhysX::ArticulationJointRequests::SetDriveTargetVelocity, data.m_axis , wheelRotationSpeed);
253
+ }
254
+ else
255
+ {
256
+ PhysX::JointRequestBus::Event ( AZ::EntityComponentIdPair (data.m_wheelEntity ,data.m_wheelJoint ), &PhysX::JointRequests::SetVelocity, wheelRotationSpeed);
257
+ }
258
+ }
259
+
260
+ AZ::Transform GetJointTransform (const VehicleDynamics::WheelDynamicsData& data)
261
+ {
262
+ AZ::Transform hingeTransform{ AZ::Transform::Identity () };
263
+ if (!data.m_isArticulation )
264
+ {
265
+ PhysX::JointRequestBus::EventResult (hingeTransform, AZ::EntityComponentIdPair (data.m_wheelEntity ,data.m_wheelJoint ), &PhysX::JointRequests::GetTransform);
266
+ }
267
+ return hingeTransform;
268
+ }
271
269
} // namespace ROS2::VehicleDynamics::Utilities
0 commit comments