DriveModel.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #pragma once
  9. #include "VehicleInputs.h"
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <AzCore/std/utils.h>
  12. #include <ROS2Controllers/VehicleDynamics/VehicleConfiguration.h>
  13. #include <VehicleDynamics/VehicleModelLimits.h>
  14. namespace ROS2Controllers::VehicleDynamics
  15. {
  16. //! Abstract class for turning vehicle inputs into behavior of wheels and steering elements
  17. class DriveModel
  18. {
  19. public:
  20. AZ_RTTI(DriveModel, "{1B57E83D-19BF-4403-8712-1AE98A12F0CD}");
  21. enum class DriveModelType
  22. {
  23. SimplifiedDriveModelType
  24. };
  25. static void Reflect(AZ::ReflectContext* context);
  26. virtual ~DriveModel() = default;
  27. //! Activate the model. Vehicle configuration is to remain the same until another Activate is called.
  28. //! @param vehicleConfig configuration containing axes and wheels information
  29. virtual void Activate(const VehicleConfiguration& vehicleConfig) = 0;
  30. //! Applies inputs to the drive. This model will calculate and apply physical forces.
  31. //! @param inputs captured state of inputs to use.
  32. //! @param deltaTimeNs nanoseconds passed since last call of this function.
  33. void ApplyInputState(const VehicleInputs& inputs, AZ::u64 deltaTimeNs);
  34. //! Computes expected velocity from individual wheels velocity.
  35. //! The method queries all wheels for rotation speed, and computes vehicle's expected velocity in its coordinate frame.
  36. //! @returns pair of linear and angular velocities
  37. virtual AZStd::pair<AZ::Vector3, AZ::Vector3> GetVelocityFromModel() = 0;
  38. //! Allows to disable vehicle dynamics.
  39. //! @param isDisable true if drive model should be disabled.
  40. void SetDisabled(bool isDisable);
  41. //! Get vehicle maximum limits.
  42. VehicleInputs GetMaximumPossibleInputs() const;
  43. protected:
  44. //! Returns pointer to implementation specific Vehicle limits.
  45. virtual const VehicleModelLimits* GetVehicleLimitPtr() const = 0;
  46. //! Apply input to implemented vehicle model.
  47. virtual void ApplyState(const VehicleInputs& inputs, AZ::u64 deltaTimeNs) = 0;
  48. //! True if model is disabled.
  49. bool m_disabled{ false };
  50. };
  51. } // namespace ROS2Controllers::VehicleDynamics