ROS2WheelOdometry.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  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/Math/Transform.h>
  10. #include <ROS2/Sensor/Events/PhysicsBasedSource.h>
  11. #include <ROS2Sensors/Sensor/ROS2SensorComponentBase.h>
  12. #include <nav_msgs/msg/odometry.hpp>
  13. #include <rclcpp/publisher.hpp>
  14. #include "ROS2OdometryCovariance.h"
  15. namespace ROS2Sensors
  16. {
  17. //! Wheel odometry sensor component.
  18. //! It constructs and publishes an odometry message, which contains information about the vehicle's velocity and position in space.
  19. //! This is a physical sensor that takes a vehicle's configuration and computes updates from the wheels' rotations.
  20. //! @see <a href="https://index.ros.org/p/nav_msgs/">nav_msgs package</a>.
  21. class ROS2WheelOdometryComponent : public ROS2SensorComponentBase<ROS2::PhysicsBasedSource>
  22. {
  23. public:
  24. AZ_COMPONENT(ROS2WheelOdometryComponent, ROS2Sensors::ROS2WheelOdometryComponentTypeId, SensorBaseType);
  25. ROS2WheelOdometryComponent();
  26. ~ROS2WheelOdometryComponent() = default;
  27. static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required);
  28. static void Reflect(AZ::ReflectContext* context);
  29. //////////////////////////////////////////////////////////////////////////
  30. // Component overrides
  31. void Activate() override;
  32. void Deactivate() override;
  33. //////////////////////////////////////////////////////////////////////////
  34. private:
  35. std::shared_ptr<rclcpp::Publisher<nav_msgs::msg::Odometry>> m_odometryPublisher;
  36. nav_msgs::msg::Odometry m_odometryMsg;
  37. AZ::Vector3 m_robotPose{ 0 };
  38. AZ::Quaternion m_robotRotation{ 0, 0, 0, 1 };
  39. ROS2OdometryCovariance m_poseCovariance;
  40. ROS2OdometryCovariance m_twistCovariance;
  41. void OnOdometryEvent();
  42. void OnPhysicsEvent(float physicsDeltaTime);
  43. };
  44. } // namespace ROS2Sensors