RobotecAI / robotec-o3de-tools

Toolset for demo recordings in O3DE
5 stars 1 forks source link

Update ROS2ScriptIntegration #58

Closed jhanca-robotecai closed 3 months ago

jhanca-robotecai commented 3 months ago

Few updates in ROS2ScriptIntegration Gem:

Tested with the script

local test_bus = { 
    Properties = 
    {
    },
    topicVector3 = "test/vector3",
    topicQuaternion = "test/quaternion",
    topicTransform = "test/transform"
}

function test_bus:OnActivate()
    self.ros2TestVector3BusHandler = SubscriberNotificationsBus.Connect(self, self.topicVector3)
    SubscriberRequestBus.Broadcast.SubscribeToGeometryMsgVector3(self.topicVector3)

    self.ros2TestQuaternionBusHandler = SubscriberNotificationsBus.Connect(self, self.topicQuaternion)
    SubscriberRequestBus.Broadcast.SubscribeToGeometryMsgQuaternion(self.topicQuaternion)

    self.ros2TestTransformBusHandler = SubscriberNotificationsBus.Connect(self, self.topicTransform)
    SubscriberRequestBus.Broadcast.SubscribeToGeometryMsgTransform(self.topicTransform)
end

function test_bus:OnDeactivate()
    if self.ros2TestVector3BusHandler ~= nil then
        self.ros2TestVector3BusHandler:Disconnect()
    end

    if self.ros2TestQuaternionBusHandler ~= nil then
        self.ros2TestQuaternionBusHandler:Disconnect()
    end

    if self.ros2TestTransformBusHandler ~= nil then
        self.ros2TestTransformBusHandler:Disconnect()
    end
end

function test_bus:OnGeometryMsgVector3(value)
    Debug.Log("Received vector value x: " .. value.x)
    Debug.Log("Received vector value y: " .. value.y)
    Debug.Log("Received vector value z: " .. value.z)
end

function test_bus:OnGeometryMsgQuaternion(value)
    Debug.Log("Received quaternion value x: " .. value.x)
    Debug.Log("Received quaternion value y: " .. value.y)
    Debug.Log("Received quaternion value z: " .. value.z)
    Debug.Log("Received quaternion value w: " .. value.w)
end

function test_bus:OnGeometryMsgTransform(value)
    Debug.Log("Received transform translation value x: " .. value.translation.x)
    Debug.Log("Received transform translation value y: " .. value.translation.y)
    Debug.Log("Received transform translation value z: " .. value.translation.z)

    Debug.Log("Received transform rotation value x: " .. value.rotation.x)
    Debug.Log("Received transform rotation value y: " .. value.rotation.y)
    Debug.Log("Received transform rotation value z: " .. value.rotation.z)
    Debug.Log("Received transform rotation value w: " .. value.rotation.w)
end

return test_bus

ros 2 calls:

ros2 topic pub --once /test/quaternion geometry_msgs/msg/Quaternion "{x: 2.0, y: 3.0, z: 4.0, w: 1.0}"
ros2 topic pub --once /test/vector3 geometry_msgs/msg/Vector3 "{x: 1, y: 2, z: 3}"
ros2 topic pub --once /test/transform geometry_msgs/msg/Transform "{translation: {x: 0.1, y: 0.2, z: 0.3}, rotation: {x: 2.0, y: 3.0, z: 4.0, w: 1.0}}"

O3DE terminal:

(Script) - Received quaternion value x: 2.0
(Script) - Received quaternion value y: 3.0
(Script) - Received quaternion value z: 4.0
(Script) - Received quaternion value w: 1.0
(Script) - Received vector value x: 1.0
(Script) - Received vector value y: 2.0
(Script) - Received vector value z: 3.0
(Script) - Received transform translation value x: 0.10000000149012
(Script) - Received transform translation value y: 0.20000000298023
(Script) - Received transform translation value z: 0.30000001192093
(Script) - Received transform rotation value x: 2.0
(Script) - Received transform rotation value y: 3.0
(Script) - Received transform rotation value z: 4.0
(Script) - Received transform rotation value w: 1.0
michalpelka commented 3 months ago

Good additions.