Utilities.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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 "WheelDynamicsData.h"
  10. #include <AzCore/Component/ComponentBus.h>
  11. #include <AzCore/Component/EntityId.h>
  12. #include <AzCore/std/containers/vector.h>
  13. #include <AzCore/std/string/string.h>
  14. #include <ROS2Controllers/VehicleDynamics/AxleConfiguration.h>
  15. #include <ROS2Controllers/VehicleDynamics/VehicleConfiguration.h>
  16. namespace ROS2Controllers::VehicleDynamics::Utilities
  17. {
  18. //! Create the most common two wheel axle out of existing wheel entities.
  19. //! @param leftWheel Left wheel entity. It needs a WheelControllerComponent if it is a drive or steering axis.
  20. //! @param rightWheel Right wheel entity. It needs a WheelControllerComponent if it is a drive or steering axis.
  21. //! @param tag Additional information for the user (and reflected in the configuration) about what this axle is.
  22. //! @param wheelRadius Radius for both wheels, in meters. Wheels with different radii are not supported.
  23. //! @param steering Is this axle used for vehicle steering. If true, wheels need to have steering entities set in
  24. //! WheelControlComponents.
  25. //! @param drive Is this axle used to drive vehicle?
  26. //! @returns An axle configuration created according to call parameters.
  27. AxleConfiguration Create2WheelAxle(
  28. AZ::EntityId leftWheel, AZ::EntityId rightWheel, AZStd::string tag, float wheelRadius, bool steering, bool drive);
  29. //! Create an axle for both steering and drive, named "Front". @see Create2WheelAxle.
  30. //! @param leftWheel left wheel entity's id (entity should has rigid body and collider component)
  31. //! @param rightWheel right wheel entity's id (entity should has rigid body and collider component)
  32. //! @param wheelRadius radius in meters
  33. AxleConfiguration CreateFrontSteerAndDriveAxle(AZ::EntityId leftWheel, AZ::EntityId rightWheel, float wheelRadius);
  34. //! Create an axle for drive, named "Rear". @see Create2WheelAxle.
  35. //! @param leftWheel left wheel entity's id (entity should has rigid body and collider component)
  36. //! @param rightWheel right wheel entity's id (entity should has rigid body and collider component)
  37. //! @param wheelRadius radius in meters
  38. AxleConfiguration CreateRearDriveAxle(AZ::EntityId leftWheel, AZ::EntityId rightWheel, float wheelRadius);
  39. //! Retrieve all steering entities for a given vehicle configuration.
  40. //! @param vehicleConfig Vehicle configuration to process.
  41. //! @returns This function will only return data for properly set up steering entities and raise warnings if something is not right.
  42. //! Wheels with a WheelControllerComponent need a SteeringEntity set, and the axle must be a steering axle.
  43. AZStd::vector<VehicleDynamics::SteeringDynamicsData> GetAllSteeringEntitiesData(const VehicleConfiguration& vehicleConfig);
  44. //! Retrieve all drive entities for a given vehicle configuration.
  45. //! @param vehicleConfig Vehicle configuration to process.
  46. //! @returns This function will only return data for properly set up wheels and raise warnings if something is not right.
  47. //! Wheels need a WheelControllerComponent, and the axle must be a drive axle.
  48. AZStd::vector<VehicleDynamics::WheelDynamicsData> GetAllDriveWheelsData(const VehicleConfiguration& vehicleConfig);
  49. //! Retrieve wheel data for a given wheel entity (components id for joints and free axis)
  50. //! @param wheelEntityId Wheel entity to process.
  51. //! @param wheelRadius Radius of the wheel in meters.
  52. //! @returns struct with wheel data.
  53. VehicleDynamics::WheelDynamicsData GetWheelData(const AZ::EntityId wheelEntityId, float wheelRadius);
  54. //! Computes ramped velocity.
  55. //! @param targetVelocity Last commanded velocity to send to robot (in eg m/s or rad/s)
  56. //! @param lastVelocity Last commanded Velocity (in eg m/s or rad/s)
  57. //! @param deltaTimeNs Duration between subsequent calls to @fn ComputeRampVelocity in nanoseconds
  58. //! @param acceleration Acceleration (in eg m/s² or rad/s²)
  59. //! @param maxVelocity Limit for velocity to clamp to (in eg m/s or rad/s)
  60. //! @returns ramped velocity according to time, acceleration and clamped to @param maxVelocity
  61. float ComputeRampVelocity(float targetVelocity, float lastVelocity, AZ::u64 deltaTimeNs, float acceleration, float maxVelocity);
  62. void SetWheelRotationSpeed(const VehicleDynamics::WheelDynamicsData& data, float wheelRotationSpeed);
  63. AZ::Transform GetJointTransform(const VehicleDynamics::WheelDynamicsData& data);
  64. } // namespace ROS2Controllers::VehicleDynamics::Utilities