Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ROS2 frame tests #4

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Test Goal

Check if the frame is added to the tf tree.

## Test Perquisites

- Empty default Level
- ROS2 Gem Activated
- O3DE Editor running

## Steps

- Create entity

![add entity](asset/add-entity.png)

- Check if there are no frames in the tf tree `ros2 run tf2_tools view_frames` This will create a file `*.pdf` in the current directory it should contain the following frames:
![tf tree empty](asset/frames-no-tf.png)

- Add the frame component to the entity

![add component](asset/add-ros2-frame.png)

- The component should look like this:

![result](asset/resulting.png)

- Check if the frame is added to the tf tree `ros2 run tf2_tools view_frames` This will create a file `*.pdf` in the current directory it should contain the following frames:

![tf tree](asset/frames-tf-present.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Test Goal

Check when the frame is added to the tf tree the transform is published

## Test Perquisites

- Empty default Level
- ROS2 Gem Activated
- O3DE Editor running

## Steps

- Execute preparation script in o3de console `pyRunFile Ros2FrameTest/FRAME_DYNAMIC_TRANSFORMS_PUBLISHED/tools/prepare_test.py`

- Run the game (`ctrl + G`)

- Check if the frame is added to the tf tree `ros2 run tf2_tools view_frames` This will create a file `*.pdf` in the current directory it should contain the following frames:

![tf tree](asset/frames.png)

- Check if the transform is published `ros2 topic echo /tf` This should print the transform between the two frames. Move the camera (WASD) and check if the transform is updated.

## Expected Result

The frame is added to the tf tree and the transform is published
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import azlmbr.legacy.general as general
import azlmbr.bus as bus
import azlmbr.entity as entity
import azlmbr.editor as editor
import azlmbr.entity
import azlmbr.object
from azlmbr.entity import EntityId
from azlmbr.entity import EntityType

import subprocess
DEGREE_RADIAN_FACTOR = 0.0174533
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert deg to rad with math.radians()


def GetDefaultCamera():
search_filter = entity.SearchFilter()
search_filter.names = ["Camera"]
entityIdList = azlmbr.entity.SearchBus(azlmbr.bus.Broadcast, 'SearchEntities', search_filter)
assert len(entityIdList) == 1
return entityIdList[0]



if __name__ == "__main__":

typeNameList = ["ROS2 Camera Sensor", "ROS2 Frame"]
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent naming convention. Use lower_camel_case for temp variables as previously.

typeIdsList = editor.EditorComponentAPIBus(bus.Broadcast, 'FindComponentTypeIdsByEntityType', typeNameList, entity.EntityType().Game)

ROS2CameraSensorTypeId = typeIdsList[0]

defaultCameraEntity = GetDefaultCamera()

rosCameraEntityId = azlmbr.editor.ToolsApplicationRequestBus(azlmbr.bus.Broadcast, 'CreateNewEntity', defaultCameraEntity)
editor.EditorEntityAPIBus(bus.Event, 'SetName', rosCameraEntityId, "FooCameraTest")


azlmbr.components.TransformBus(azlmbr.bus.Event, "SetLocalRotation", rosCameraEntityId, azlmbr.math.Vector3(-DEGREE_RADIAN_FACTOR*90.0, 0.0, 0.0))

outcomeROS2Camera = editor.EditorComponentAPIBus(bus.Broadcast, 'AddComponentsOfType', rosCameraEntityId, typeIdsList )
assert outcomeROS2Camera.IsSuccess()
cameraComponentOutcome = azlmbr.editor.EditorComponentAPIBus(bus.Broadcast, 'GetComponentOfType', rosCameraEntityId, ROS2CameraSensorTypeId)
assert cameraComponentOutcome.IsSuccess()
cameraComponentId = cameraComponentOutcome.GetValue()

## ROS2 Checking if the transform is correct


Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary blank line.

29 changes: 29 additions & 0 deletions Ros2FrameTest/FRAME_HIERARCHY/FRAME_HIERARCHY_TESTCASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
## Test Goal

Check when the frame is added to the tf tree the transform is published

## Test Perquisites

- Empty default Level
- ROS2 Gem Activated
- O3DE Editor running

## Steps

- Create entity

- Create second entity (child of the first entity)

- Add the frame component to the both entities, the hierarchy should look like this:

![entities](asset/entities.png)

- Set the name to "sensor_frame2", should look like this:

![entity 2 frame name](asset/entity2-frame.png)

- Run the game (`ctrl + G`)

- Check if the frame is added to the tf tree `ros2 run tf2_tools view_frames` This will create a file `*.pdf` in the current directory it should contain the following frames:

![tf tree](asset/frames-hierarchy.png)
Binary file added Ros2FrameTest/FRAME_HIERARCHY/asset/entities.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
31 changes: 31 additions & 0 deletions Ros2FrameTest/FRAME_NAMESPACE/FRAME_NAMESPACE_TESTCASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
## Test Goal

Check if the changing of the namespace in the frame component is reflected in the tf tree.

## Test Perquisites

- Empty default Level
- ROS2 Gem Activated
- O3DE Editor running

## Steps

- Create entity

- Add the frame component to the entity the tf frames without changing the namespace.

- Run the game (`ctrl + G`)

- Check the frames by running `ros2 run tf2_tools view_frames`. The frame component should look like this:

![frames without namespace](asset/frames-without-namespace.png)

- Stop the game (`Esc Esc`) and add the namespace `test_namespace` to the frame component.

![add namespace](asset/add-custom-namespace.png)

- Run the game (`ctrl + G`)

- Check the frames by running `ros2 run tf2_tools view_frames`. The frame component should look like this:

![frames with namespace](asset/frames-with-namespace.png)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 25 additions & 0 deletions Ros2FrameTest/FRAME_PREFAB/FRAME_PREFAB_TESTCASE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Test Goal

Check if the prefab with defined tf tree is loaded correctly and the transforms are published.

## Test Perquisites

- Empty default Level
- ROS2 Gem Activated
- O3DE Editor running

## Steps

- Add the prefab to the level by right clicking on the level then `Instantiate Prefab` and select the prefab `ROSbot.prefab`

![add prefab](asset/add-prefab.png)

- Run the game (`ctrl + G`)

- Check the tf tree `ros2 run tf2_tools view_frames` This will create a file `*.pdf` in the current directory it should contain the following frames:

![tf tree](asset/frames.png)

## Expected Result

The prefab is loaded and the tf tree is published.
Binary file added Ros2FrameTest/FRAME_PREFAB/asset/add-prefab.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added Ros2FrameTest/FRAME_PREFAB/asset/frames.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## Test Goal

Check if the prefab with defined tf tree is loaded correctly and the transforms are published.

## Test Perquisites

- Empty default Level
- ROS2 Gem Activated
- O3DE Editor running

## Steps

- Add the prefab to the level by right clicking on the level then `Instantiate Prefab` and select the prefab `ROSbot.prefab`

![add prefab](asset/add-prefab.png)

- Run the script for checking the `tf_static` by running the command `python3 tools/check_tf_static.py`

- Run the game (`ctrl + G`)

- Check the `tf_static` by running the command `ros2 topic echo /tf_static` This should print the transform between the two frames. Move the camera (WASD) and check if the transform is updated.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the purpose of moving the camera at this point? Is there any frame attached to the camera?


## Expected Result

The prefab is loaded and transforms are published. No duplicate in parent-child relationship in the tf tree.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import rclpy
from rclpy.node import Node

from tf2_msgs.msg import TFMessage


class TfStaticSubscriber(Node):

def __init__(self):
super().__init__('tf_static_subscriber')
self.subscription = self.create_subscription(
TFMessage,
'tf_static',
self.callback,
10)
self.subscription

def callback(self, msg):
for transform in msg.transforms:
self.get_logger().info('Child frame: "%s"' % transform.child_frame_id)
self.get_logger().info('Parent frame: "%s"' % transform.header.frame_id)
if (transform.child_frame_id == transform.header.frame_id):
self.get_logger().error('Child frame and parent frame are the same!')


def main(args=None):
rclpy.init(args=args)

tf_static_subscriber = TfStaticSubscriber()

rclpy.spin(tf_static_subscriber)

tf_static_subscriber.destroy_node()
rclpy.shutdown()


if __name__ == '__main__':
main()