Note: This tutorial assumes that you have completed the previous tutorials: Getting started, Pattern creation, Iterating patterns.
(!) Please ask about problems and questions regarding this tutorial on answers.ros.org. Don't forget to include in your question the link to this page, the versions of your OS & ROS, and also add appropriate tags.

Importing and exporting

Description: This tutorial covers importing and exporting .yaml files to store, modify and/or generate a transform tree.

Tutorial Level: BEGINNER

This tutorial will show you how to export a transform tree, modify the exported file, and then import it.

Exporting transform tree

To export the transform tree, call the service, /save, with a filepath parameter specifying the desired location of the exported .yaml file. Following the previous tutorials we export the tree we have created thus far:

$ rosservice call /pattern_manager/save "path: '/path/to/my_file.yaml'"

The generated file should look like this:

root:
  grp1:
    lin1:
      lin1_0:
        ref_frame: lin1
        rotation: [0.0, 0.0, 0.0, 1.0]
        translation: [0.0, 0.0, 0.0]
      lin1_1:
        ref_frame: lin1
        rotation: [0.0, 0.0, 0.0, 1.0]
        translation: [1.0, 0.0, 0.0]
      lin1_2:
        ref_frame: lin1
        rotation: [0.0, 0.0, 0.0, 1.0]
        translation: [2.0, 0.0, 0.0]
      lin1_3:
        ref_frame: lin1
        rotation: [0.0, 0.0, 0.0, 1.0]
        translation: [3.0, 0.0, 0.0]
      ref_frame: grp1
      rotation: [0.0, 0.0, 0.0, 1.0]
      translation: [0.0, 0.0, 0.0]
    ref_frame: root
    rotation: [0.0, 0.0, 0.0, 1.0]
    translation: [0.0, 0.0, 0.0]
  ref_frame: world
  rotation: [0.0, 0.0, 0.0, 1.0]
  translation: [0.0, 0.0, 0.0]

Next, we will manually modify the transform tree by editing the .yaml file.

Modifying transform tree

As an example of modifying the .yaml file, let us add a fourth transform to the lin1 pattern below lin1_3 and call it lin1_4 like so:

...
lin1_4:
  ref_frame: lin1
  rotation: [0.0, 0.0, 0.0, 1.0]
  translation: [4.0, 0.0, 0.0]
...

This is just one example of modification. Any modification within the limits of the fixed structure of the tree can be done via the exported (or manually created) file.

Importing transform tree

Now that we have modified the .yaml file, let us import the file to the pattern_manager node. To do this we will use the /load service as such:

$ rosservice call /pattern_manager/load "path: '/path/to/my_file.yaml'"

We can make sure that the transform tree has been correctly updated by calling /get_transforms on lin1. The output should include the newly added lin1_4.

$ rosservice call /pattern_manager/get_transform_id "name: 'lin1'" 
id: 140554725632320
$ rosservice call /pattern_manager/get_transforms  "parent_id: 140554725632320" 
transforms: 
  - 
    name: "lin1_4"
    parent_id: 140554725632320
    ref_frame: "lin1"
    id: 140554725632496
    active: False
    translation: 
      x: 4.0
      y: 0.0
      z: 0.0
    rotation: 
      x: 0.0
      y: 0.0
      z: 0.0
      w: 1.0
    number: 9
  - 
...

Hopefully it should now be clear how to import, export, create, and modify your transform tree by hand by editing or creating .yaml files.

Wiki: pattern_manager/Tutorials/Importing and exporting (last edited 2020-01-19 23:04:00 by Mads)