-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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 | ||
|
||
 | ||
|
||
- 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: | ||
 | ||
|
||
- Add the frame component to the entity | ||
|
||
 | ||
|
||
- The component should look like this: | ||
|
||
 | ||
|
||
- 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: | ||
|
||
 |
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: | ||
|
||
 | ||
|
||
- 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 |
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 | ||
|
||
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"] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Inconsistent naming convention. Use |
||
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 | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary blank line. |
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: | ||
|
||
 | ||
|
||
- Set the name to "sensor_frame2", should look like this: | ||
|
||
 | ||
|
||
- 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: | ||
|
||
 |
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: | ||
|
||
 | ||
|
||
- Stop the game (`Esc Esc`) and add the namespace `test_namespace` to the frame component. | ||
|
||
 | ||
|
||
- Run the game (`ctrl + G`) | ||
|
||
- Check the frames by running `ros2 run tf2_tools view_frames`. The frame component should look like this: | ||
|
||
 |
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` | ||
|
||
 | ||
|
||
- 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: | ||
|
||
 | ||
|
||
## Expected Result | ||
|
||
The prefab is loaded and the tf tree is published. |
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` | ||
|
||
 | ||
|
||
- 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. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() |
There was a problem hiding this comment.
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()