Przeglądaj źródła

Pid refactoring (#179)

Improving the reusability of PIDConfiguration.* by factoring out of VehicleDynamics/DriveModels intoto Utilities/Controllers, making it reusable by other components without depending on VehicleDynamics.
danielemorra98 2 lat temu
rodzic
commit
0c1e31f02c

+ 2 - 2
Gems/ROS2/Code/Include/ROS2/Manipulator/MotorizedJointComponent.h

@@ -12,7 +12,7 @@
 #include <AzCore/Component/TickBus.h>
 #include <AzCore/Math/Transform.h>
 #include <AzCore/Math/Vector2.h>
-#include <ROS2/VehicleDynamics/DriveModels/PidConfiguration.h>
+#include <ROS2/Utilities/Controllers/PidConfiguration.h>
 
 namespace ROS2
 {
@@ -67,7 +67,7 @@ namespace ROS2
         AZ::Vector3 m_jointDir{ 0.f, 0.f, 1.f }; //!< Direction of joint movement in parent frame of reference, used to compute measurement.
         AZ::Vector3 m_effortAxis{ 0.f, 0.f, 1.f }; //!< Direction of force or torque application in owning entity frame of reference.
         AZStd::pair<float, float> m_limits{ -0.5f, 0.5f }; //!< limits of joint, the force is applied only when joint is within limits.
-        VehicleDynamics::PidConfiguration m_pidPos; //!< PID controller for position.
+        Controllers::PidConfiguration m_pidPos; //!< PID controller for position.
 
         bool m_linear{ true }; //!< Linear mode. The force is applied through RigidBodyBus.
         bool m_animationMode{ true }; //!< Use TransformBus (animation mode, no physics) instead of RigidBodyBus.

+ 2 - 2
Gems/ROS2/Code/Include/ROS2/VehicleDynamics/DriveModels/PidConfiguration.h → Gems/ROS2/Code/Include/ROS2/Utilities/Controllers/PidConfiguration.h

@@ -10,7 +10,7 @@
 #include <AzCore/Serialization/SerializeContext.h>
 #include <control_toolbox/pid.hpp>
 
-namespace ROS2::VehicleDynamics
+namespace ROS2::Controllers
 {
     //! A wrapper for ROS 2 control_toolbox pid controller.
     //! @see <a href="https://github.com/ros-controls/control_toolbox">control_toolbox</a>.
@@ -40,4 +40,4 @@ namespace ROS2::VehicleDynamics
 
         control_toolbox::Pid m_pid; //!< PID implementation object from control_toolbox (of ros2_control).
     };
-} // namespace ROS2::VehicleDynamics
+} // namespace ROS2::Controllers

+ 0 - 1
Gems/ROS2/Code/Source/Frame/ROS2FrameComponent.cpp

@@ -147,7 +147,6 @@ namespace ROS2
     {
         return m_isDynamic;
     }
-
     const ROS2FrameComponent* ROS2FrameComponent::GetParentROS2FrameComponent() const
     {
         return Internal::GetFirstROS2FrameAncestor(GetEntity());

+ 2 - 0
Gems/ROS2/Code/Source/ROS2SystemComponent.cpp

@@ -9,6 +9,7 @@
 
 #include <ROS2/Communication/QoS.h>
 #include <ROS2/Communication/TopicConfiguration.h>
+#include <ROS2/Utilities/Controllers/PidConfiguration.h>
 #include <VehicleDynamics/VehicleModelComponent.h>
 
 #include <Atom/RPI.Public/Pass/PassSystemInterface.h>
@@ -27,6 +28,7 @@ namespace ROS2
         QoS::Reflect(context);
         TopicConfiguration::Reflect(context);
         VehicleDynamics::VehicleModelComponent::Reflect(context);
+        ROS2::Controllers::PidConfiguration::Reflect(context);
         if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
         {
             serialize->Class<ROS2SystemComponent, AZ::Component>()->Version(0);

+ 3 - 3
Gems/ROS2/Code/Source/VehicleDynamics/DriveModels/PidConfiguration.cpp → Gems/ROS2/Code/Source/Utilities/Controllers/PidConfiguration.cpp

@@ -9,9 +9,9 @@
 #include <AzCore/Serialization/EditContext.h>
 #include <AzCore/Serialization/EditContextConstants.inl>
 #include <AzCore/Serialization/SerializeContext.h>
-#include <ROS2/VehicleDynamics/DriveModels/PidConfiguration.h>
+#include <ROS2/Utilities/Controllers/PidConfiguration.h>
 
-namespace ROS2::VehicleDynamics
+namespace ROS2::Controllers
 {
     void PidConfiguration::Reflect(AZ::ReflectContext* context)
     {
@@ -65,4 +65,4 @@ namespace ROS2::VehicleDynamics
         }
         return output;
     }
-} // namespace ROS2::VehicleDynamics
+} // namespace ROS2::Controllers

+ 0 - 1
Gems/ROS2/Code/Source/VehicleDynamics/DriveModels/AckermannDriveModel.cpp

@@ -21,7 +21,6 @@ namespace ROS2::VehicleDynamics
     void AckermannDriveModel::Reflect(AZ::ReflectContext* context)
     {
         AckermannModelLimits::Reflect(context);
-        PidConfiguration::Reflect(context);
         if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
         {
             serialize->Class<AckermannDriveModel, DriveModel>()

+ 2 - 2
Gems/ROS2/Code/Source/VehicleDynamics/DriveModels/AckermannDriveModel.h

@@ -8,7 +8,7 @@
 #pragma once
 
 #include <AzCore/Serialization/SerializeContext.h>
-#include <ROS2/VehicleDynamics/DriveModels/PidConfiguration.h>
+#include <ROS2/Utilities/Controllers/PidConfiguration.h>
 #include <VehicleDynamics/DriveModel.h>
 #include <VehicleDynamics/ModelLimits/AckermannModelLimits.h>
 #include <VehicleDynamics/VehicleConfiguration.h>
@@ -41,7 +41,7 @@ namespace ROS2::VehicleDynamics
         VehicleConfiguration m_vehicleConfiguration;
         AZStd::vector<WheelDynamicsData> m_driveWheelsData;
         AZStd::vector<SteeringDynamicsData> m_steeringData;
-        PidConfiguration m_steeringPid;
+        ROS2::Controllers::PidConfiguration m_steeringPid;
         float m_speedCommand = 0.0f;
         AckermannModelLimits m_limits;
     };

+ 1 - 1
Gems/ROS2/Code/ros2_files.cmake

@@ -64,6 +64,7 @@ set(FILES
         Source/Spawner/ROS2SpawnerComponent.h
         Source/Spawner/ROS2SpawnPointComponent.cpp
         Source/Spawner/ROS2SpawnPointComponent.h
+        Source/Utilities/Controllers/PidConfiguration.cpp
         Source/Utilities/ROS2Conversions.cpp
         Source/Utilities/ROS2Names.cpp
         Source/VehicleDynamics/AxleConfiguration.cpp
@@ -74,7 +75,6 @@ set(FILES
         Source/VehicleDynamics/DriveModels/AckermannDriveModel.h
         Source/VehicleDynamics/DriveModels/SkidSteeringDriveModel.cpp
         Source/VehicleDynamics/DriveModels/SkidSteeringDriveModel.h
-        Source/VehicleDynamics/DriveModels/PidConfiguration.cpp
         Source/VehicleDynamics/ManualControlEventHandler.h
         Source/VehicleDynamics/Utilities.cpp
         Source/VehicleDynamics/Utilities.h

+ 1 - 1
Gems/ROS2/Code/ros2_header_files.cmake

@@ -19,8 +19,8 @@ set(FILES
         Include/ROS2/Sensor/ROS2SensorComponent.h
         Include/ROS2/Sensor/SensorConfiguration.h
         Include/ROS2/Spawner/SpawnerBus.h
+        Include/ROS2/Utilities/Controllers/PidConfiguration.h
         Include/ROS2/Utilities/ROS2Conversions.h
         Include/ROS2/Utilities/ROS2Names.h
-        Include/ROS2/VehicleDynamics/DriveModels/PidConfiguration.h
         Include/ROS2/VehicleDynamics/VehicleInputControlBus.h
         )