ROS2RobotControlComponent.cpp 2.1 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 <AzCore/Component/Entity.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <AzCore/Serialization/EditContext.h>
  12. #include <AzCore/Serialization/EditContextConstants.inl>
  13. #include "ROS2RobotControlComponent.h"
  14. #include "TwistControl.h"
  15. namespace ROS2
  16. {
  17. void ROS2RobotControlComponent::Init()
  18. {
  19. // TODO - instead, create/reset robot control in Activate based on selected implementation (in the component)
  20. m_robotControl = std::make_unique<TwistControl>();
  21. }
  22. void ROS2RobotControlComponent::Activate()
  23. {
  24. m_robotControl->Activate(GetEntity(), m_topic);
  25. }
  26. void ROS2RobotControlComponent::Deactivate()
  27. {
  28. m_robotControl->Deactivate();
  29. }
  30. void ROS2RobotControlComponent::Reflect(AZ::ReflectContext* context)
  31. {
  32. if (AZ::SerializeContext* serialize = azrtti_cast<AZ::SerializeContext*>(context))
  33. {
  34. serialize->Class<ROS2RobotControlComponent, AZ::Component>()
  35. ->Version(1)
  36. ->Field("topic", &ROS2RobotControlComponent::m_topic)
  37. ;
  38. if (AZ::EditContext* ec = serialize->GetEditContext())
  39. {
  40. ec->Class<ROS2RobotControlComponent>("Robot control", "[Customizable robot control component]")
  41. ->ClassElement(AZ::Edit::ClassElements::EditorData, "")
  42. ->Attribute(AZ::Edit::Attributes::AppearsInAddComponentMenu, AZ_CRC("Game")) // TODO - "Simulation"?
  43. ->DataElement(AZ::Edit::UIHandlers::Default, &ROS2RobotControlComponent::m_topic, "Topic", "ROS2 topic to subscribe to")
  44. ;
  45. }
  46. }
  47. }
  48. /*
  49. void ROS2RobotControlComponent::GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required)
  50. {
  51. // TODO - query current/selected RobotControl implementation for what components are required
  52. }
  53. */
  54. } // namespace ROS2