SkidSteeringControlComponent.cpp 2.7 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. #include "SkidSteeringControlComponent.h"
  9. #include <AzCore/Component/TransformBus.h>
  10. #include <AzCore/Math/MathUtils.h>
  11. #include <AzCore/Serialization/EditContext.h>
  12. #include <AzCore/Serialization/EditContextConstants.inl>
  13. #include <AzFramework/Physics/RigidBodyBus.h>
  14. #include <PhysX/Joint/PhysXJointRequestsBus.h>
  15. #include <ROS2Controllers/VehicleDynamics/VehicleInputControlBus.h>
  16. #include <VehicleDynamics/WheelControllerComponent.h>
  17. namespace ROS2Controllers
  18. {
  19. void SkidSteeringControlComponent::Reflect(AZ::ReflectContext* context)
  20. {
  21. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  22. {
  23. serialize->Class<SkidSteeringControlComponent, AZ::Component>()->Version(1);
  24. if (AZ::EditContext* editorContext = serialize->GetEditContext())
  25. {
  26. editorContext->Class<SkidSteeringControlComponent>("Skid Steering Twist Control", "")
  27. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  28. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC_CE("Game"))
  29. ->Attribute(AZ::Edit::Attributes::Category, "ROS2")
  30. ->Attribute(AZ::Edit::Attributes::Icon, "Editor/Icons/Components/SkidSteeringTwistControl.svg")
  31. ->Attribute(AZ::Edit::Attributes::ViewportIcon, "Editor/Icons/Components/Viewport/SkidSteeringTwistControl.svg");
  32. }
  33. }
  34. }
  35. void SkidSteeringControlComponent::Activate()
  36. {
  37. TwistNotificationBus::Handler::BusConnect(GetEntityId());
  38. }
  39. void SkidSteeringControlComponent::Deactivate()
  40. {
  41. TwistNotificationBus::Handler::BusDisconnect();
  42. }
  43. void SkidSteeringControlComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  44. {
  45. required.push_back(AZ_CRC_CE("ROS2RobotControl"));
  46. required.push_back(AZ_CRC_CE("SkidSteeringModelService"));
  47. }
  48. void SkidSteeringControlComponent::TwistReceived(const AZ::Vector3& linear, const AZ::Vector3& angular)
  49. {
  50. // Notify input system for vehicle dynamics. Only speed and steering is currently supported.
  51. VehicleDynamics::VehicleInputControlRequestBus::Event(
  52. GetEntityId(), &VehicleDynamics::VehicleInputControlRequests::SetTargetLinearSpeedV3, linear);
  53. VehicleDynamics::VehicleInputControlRequestBus::Event(
  54. GetEntityId(), &VehicleDynamics::VehicleInputControlRequests::SetTargetAngularSpeedV3, angular);
  55. }
  56. } // namespace ROS2Controllers