/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #pragma once #include #include #include #include #include #include #include #include #include #include #include #include namespace ROS2Sensors { //! Contact sensor detects collisions between two objects. //! It reports the location of the contact associated forces. //! This component publishes a contact_sensor topic. //! It doesn't measure torque. class ROS2ContactSensorComponent : public ROS2::ROS2SensorComponentBase { public: using SensorBaseType = ROS2::ROS2SensorComponentBase; AZ_COMPONENT(ROS2ContactSensorComponent, ROS2ContactSensorComponentTypeId, SensorBaseType); ROS2ContactSensorComponent(); ~ROS2ContactSensorComponent() = default; static void Reflect(AZ::ReflectContext* context); static void GetRequiredServices(AZ::ComponentDescriptor::DependencyArrayType& required); ////////////////////////////////////////////////////////////////////////// // Component overrides void Activate() override; void Deactivate() override; ////////////////////////////////////////////////////////////////////////// private: ////////////////////////////////////////////////////////////////////////// void FrequencyTick(); void AddNewContact(const AzPhysics::CollisionEvent& event); AZ::EntityId m_entityId; AZStd::string m_entityName = ""; AzPhysics::SimulatedBodyEvents::OnCollisionBegin::Handler m_onCollisionBeginHandler; AzPhysics::SimulatedBodyEvents::OnCollisionPersist::Handler m_onCollisionPersistHandler; AzPhysics::SimulatedBodyEvents::OnCollisionEnd::Handler m_onCollisionEndHandler; std::shared_ptr> m_contactsPublisher; AZStd::unordered_map m_activeContacts; AZStd::mutex m_activeContactsMutex; }; } // namespace ROS2Sensors