AckermannControlComponent.cpp 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. #include "AckermannControlComponent.h"
  9. #include <AzCore/Serialization/EditContext.h>
  10. #include <AzCore/Serialization/EditContextConstants.inl>
  11. #include <AzFramework/Physics/RigidBodyBus.h>
  12. #include <ROS2Controllers/VehicleDynamics/VehicleInputControlBus.h>
  13. namespace ROS2Controllers
  14. {
  15. void AckermannControlComponent::Reflect(AZ::ReflectContext* context)
  16. {
  17. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  18. {
  19. serialize->Class<AckermannControlComponent, AZ::Component>()->Version(1);
  20. if (AZ::EditContext* ec = serialize->GetEditContext())
  21. {
  22. ec->Class<AckermannControlComponent>("Ackermann Control", "Relays Ackermann commands to vehicle inputs")
  23. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  24. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  25. ->Attribute(AZ::Edit::Attributes::Category, "ROS2")
  26. ->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/AckermannControl.svg")
  27. ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Editor/Icons/Components/Viewport/AckermannControl.svg");
  28. }
  29. }
  30. }
  31. void AckermannControlComponent::Activate()
  32. {
  33. AckermannNotificationBus::Handler::BusConnect(GetEntityId());
  34. }
  35. void AckermannControlComponent::Deactivate()
  36. {
  37. AckermannNotificationBus::Handler::BusDisconnect();
  38. }
  39. void AckermannControlComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  40. {
  41. required.push_back(AZ_CRC_CE("ROS2RobotControl"));
  42. required.push_back(AZ_CRC_CE("AckermannModelService"));
  43. }
  44. void AckermannControlComponent::AckermannReceived(const AckermannCommandStruct& acs)
  45. {
  46. // Notify input system for vehicle dynamics. Only speed and steering is currently supported.
  47. VehicleDynamics::VehicleInputControlRequestBus::Event(
  48. GetEntityId(), &VehicleDynamics::VehicleInputControlRequests::SetTargetLinearSpeed, acs.m_speed);
  49. VehicleDynamics::VehicleInputControlRequestBus::Event(
  50. GetEntityId(), &VehicleDynamics::VehicleInputControlRequests::SetTargetSteering, acs.m_steeringAngle);
  51. }
  52. } // namespace ROS2Controllers