Create a URDF with the frame editor ========================================= * The frame editor can **show your frames as a URDF** while you work, and **export it** as URDF or xacro. * Each **frame** becomes a URDF **link**. Its **parent** and **pose** become a **joint**. Its **shape** becomes the **visual** of the link. * In this guide you build a **small cell: a table with a box on top**. No URDF knowledge is needed to start. ![The finished table in rviz](../../../_static/manipulation/urdf/frame_editor/01_rviz_result.png "The finished table in rviz") *RViz: the finished cell. The arrows and rings are the drag handles of the selected frame (optional, see "Set up rviz").* ## Installation: Build the Frame Editor as in [TF and rqt Frame Editor](../tf/01_tf_frame_editor.md) (part 1), and source the workspace. ### Start rqt. ``` rqt --force-discover ``` ### Select *Plugins → Frame Editor Plugin*. * Click **URDF** in the toolbar to show the URDF panel (make the window wide, so that everything fits). ## Overview of the window: ![The frame editor with the URDF panel](../../../_static/manipulation/urdf/frame_editor/02_overview.png "The frame editor with the URDF panel") *Frame editor: the whole window, with the URDF panel open on the right.* ## Set up rviz: ### Start rviz in a second terminal. ``` rviz2 ``` * Keep the frame editor running. Its topics only show up in rviz while it is running. * Set the **Fixed Frame** to `world`. It appears after you add your first frame. * Click **Add**, choose *By display type* and add a **TF** display to see the frames. ### Add the Marker display. Without it, no shapes are visible in rviz. * Click **Add**, stay on the tab **By display type**, select **Marker** and click **OK**. ![The Add dialog of rviz, tab By display type](../../../_static/manipulation/urdf/frame_editor/03_rviz_add_marker.png "Add the Marker display") *RViz: the Add dialog, tab "By display type".* * The new display shows an error, because it has no topic yet. Open **Marker** in the Displays panel, click the value of **Topic**, open the list and select `/frame_editor_marker`. ![Selecting the topic of the Marker display](../../../_static/manipulation/urdf/frame_editor/04_rviz_marker_topic.png "Select the topic") *RViz: the Topic of the new Marker display.* * Without the Marker display you only see the axes of your frames, but **not their shapes**. ![The Displays panel of rviz](../../../_static/manipulation/urdf/frame_editor/05_rviz_displays.png "The Displays panel") *RViz: the Displays panel with Fixed Frame, TF and the Marker display.* * Shapes are not published too often, so it may take some seconds for them to appear. ### Optional: add the InteractiveMarkers display to drag frames. * You only need it if you want to **drag frames with the mouse**. Without it, type the values into the fields of the editor. * Click **Add**, select **InteractiveMarkers** in the tab **By display type** and click **OK**. Then set its **Interactive Markers Namespace** to `/frame_editor_interactive`. Build the table ----------------------------------------- * Build a **table with a box on top** from simple shapes: a table top, four legs and a box. * Use these names, so that you can follow the rest of the guide: `table_top`, `leg_front_left`, `leg_front_right`, `leg_back_left`, `leg_back_right` and `box`. * **You choose the sizes and positions.** There are no values to copy. Try, look at rviz, and correct. ### How to check what you did: * **Look in rviz:** do the legs touch the table top? Does the box stand on it? * **Check the parents:** a pose is always **relative to the parent**. Move the table top: everything that belongs to the table should move with it. If a leg stays behind, it has the wrong parent. * **Look at the URDF panel:** the joint of every frame shows its `parent`, its `child` and its position (`xyz`). * **Place frames visually** by dragging them in rviz (needs the InteractiveMarkers display), or **calculate** the numbers: a frame sits in the **center** of its shape, and all sizes and positions are in **metres**. ### Step 1: Add the table top * Click **Add New**, type `table_top` and choose a parent. It is the first frame, so use `world`. If `world` is not in the list, just type it into the field. ![The two dialogs of Add New](../../../_static/manipulation/urdf/frame_editor/06_add_frame.png "Add a new frame") *Frame editor: the two dialogs of **Add New**, first the name, then the parent.* * **Click the new frame in the list** to select it. It is not selected automatically. * Raise it with **z**, to the height of a table. * Set the **Style** to `cube`. A new cube is 1 x 1 x 1, so set **Length**, **Width** and **Height** to make a flat, wide top. * Click **Set Color** and pick a color. Set **Alpha** to `1` for a solid shape (0 is invisible). * Values are applied when you **press Enter** or leave the field. * Watch the **URDF panel**: your frame is now a **link** with its shape, and a **joint** connects it to `world`. ![Editing the table top](../../../_static/manipulation/urdf/frame_editor/07_table_top.png "Pose and shape of the table top") *Frame editor: step 1. On the left the table top, on the right the URDF panel with its new link and joint.* * In rviz you now see the table top, floating in the air: ![The table top in rviz](../../../_static/manipulation/urdf/frame_editor/08_rviz_table_top.png "The table top in rviz") *RViz: the table top after step 1.* ### Step 2: Add the legs * Add `leg_front_left`. **Which parent?** Think about what should move together with what, and test it as described above. * Select it. Make it a thin, tall `cube` and give it a color. * Move it under one corner of the table top. The pose is relative to the parent, so a leg that hangs below the table top has a **negative z**. To calculate it: half the height of the leg plus half the thickness of the table top. * Type `legs` into **Group**. * Select `leg_front_left` again and click **Duplicate**. Type `leg_front_right`. * Select the new leg and change its **x** and **y**. * Do the same for the two back legs. * In the **URDF panel**, every leg appears with its own link and its own joint. ![Duplicating and grouping the legs](../../../_static/manipulation/urdf/frame_editor/09_legs.png "Duplicate and group frames") *Frame editor: step 2. On the left the legs, on the right the URDF panel with a link and a joint for each leg.* * In rviz the table now stands on its four legs: ![The table with legs in rviz](../../../_static/manipulation/urdf/frame_editor/10_rviz_legs.png "The table with legs in rviz") *RViz: the table after step 2.* * Finish one leg completely before you duplicate it. Then you only have to change **x** and **y** on the copies. * **Group** only sorts the list in the editor. It is not written to the URDF. ### Step 3: Add the box * Add `box`, make it a `cube` and give it its own color. * Put it on top of the table top. Again, choose the parent that makes the box move with the table, and calculate or drag its position. **That's it, your cell is ready!** Use the URDF panel ----------------------------------------- ### Live preview * The URDF is **updated on every change**: add, move, drag, restyle, undo and redo. * The **changed lines are highlighted in yellow**. Removed lines can't be highlighted, but the status line counts them. ![The live URDF panel](../../../_static/manipulation/urdf/frame_editor/11_urdf_panel.png "The live URDF panel") *Frame editor: the URDF panel. The yellow line is what the last change touched.* * `world` is not one of your frames, so it is written as an **empty link** at the root. ### Edit the code * You can also **type directly into the URDF** and bring your changes back to the frames. * For example, make the box taller: find the link `box` and make the third number of its `size` bigger. Then move the `xyz` of its joint up by half of that difference, so that the box does not sink into the table. * Click **Apply code to frames**. The frames now follow your code. * Click **Rewrite code from frames** to throw your edits away instead. ![Editing the URDF by hand](../../../_static/manipulation/urdf/frame_editor/12_apply_code.png "Apply code to frames") *Frame editor: the URDF panel with hand-edited code (an example), before it is applied.* * Not everything in URDF can be stored in the editor, for example `` or `` tags. Such code is **not applied**, and the status line tells you why. ### Collision shapes * Planners such as MoveIt use **collision shapes** to avoid hitting things. * Tick **Add collision shapes** to write every shape a second time as ``. * This setting is used for the preview and for all exports. It is off every time you start the editor, so check it before you export. ![Collision shapes in the URDF](../../../_static/manipulation/urdf/frame_editor/13_collision.png "Add collision shapes") *Frame editor: the URDF panel with **Add collision shapes** ticked. Every shape is written a second time as ``.* Change your frames later ----------------------------------------- * **Type in values:** use the **Relative Pose** fields. `a`, `b` and `c` are roll, pitch and yaw. Choose **[rad]** or **[deg]**. * **Drag in rviz:** needs the optional InteractiveMarkers display. Select the frame in the editor, choose the **Interact** tool in rviz and pull the arrows and rings. * **Undo and redo** work for all changes: toolbar arrows or **Ctrl+Z**. * Copying values from other frames, changing the parent and the Measurement Tool work as in the [main README](https://github.com/ROS-Industrial-Session-Common/rqt_frame_editor_plugin/blob/feature/urdf-preview/README.md). Save and export ----------------------------------------- ### Save * Use **Save As** in the toolbar and name your file, for example `table.yaml`. **Open** loads it again. * The **YAML is your project file**. Keep it, so that you can continue later. * With **Also write .urdf next to the YAML on Save** ticked (and the URDF panel open), you also get `table.urdf`. * The file name is used as the robot name. ### Export URDF * Click **Export URDF...** to write only the URDF. ### Export xacro * Click **Export xacro...** to get a cell which you can **reuse in other robot descriptions**. Type a file name, for example `table`. You get two files next to each other: * `table_macro.xacro`: the table as a macro with the parameters `parent` and `origin` * `table.urdf.xacro`: a small file which uses the macro * In the macro, `world` is replaced by the link `table_base`, which is attached to your `parent`. * This needs **one common root**: all your frames must lead back to the same parent, here `world`. #### Use the macro in your own robot (`table` is the name of the saved YAML file): ```xml ``` #### Both exports are also available as ros services. ``` ros2 service list | grep frame_editor ros2 service call /frame_editor_/save_urdf frame_editor/srv/SaveYaml "{filename: /tmp/table.urdf}" ros2 service call /frame_editor_/save_xacro frame_editor/srv/SaveYaml "{filename: /tmp/table.urdf.xacro}" ``` Check your result ----------------------------------------- * **Close rqt first.** Otherwise the editor and your URDF publish the same frames and rviz flickers. ### View the exported file (use the full path). ``` sudo apt install ros-$ROS_DISTRO-urdf-tutorial ros2 launch urdf_tutorial display.launch.py model:=/full/path/to/table.urdf ``` * This also works with `table.urdf.xacro`. * Set the **Fixed Frame** to `world`. Until then, everything looks white. Optional: add a moving lid ----------------------------------------- * A **revolute joint** turns between two angles, like a hinge. Here you add a lid to the box. * You need two frames: one **on the hinge line**, and the lid itself as its child. * Again, you choose the numbers. Check the result in rviz. ### The two frames: * `lid_hinge`: a child of `box`, **without a shape** (style `none`). Put it on the **upper edge of the box** where the hinge should be, on the side facing the negative x direction. * `lid`: a child of `lid_hinge`, a **flat cube** as big as the top of the box. A frame sits in the center of its shape, so move it away from the hinge by half of its length, and up by half of its thickness. ### The joint: * Select `lid_hinge` and set **Joint** (below the Measurement Tool) to `revolute`. * Set the **Axis** to `0 -1 0`. If the lid later opens downwards, change the sign. * Set the **Limits** to `0` and `1.570796` (90 degrees). Keep **effort** and **speed** as they are. ![The joint settings of lid_hinge](../../../_static/manipulation/urdf/frame_editor/14_revolute_joint.png "A revolute joint") *Frame editor: the frames and the joint settings of `lid_hinge` (an example, your numbers will differ).* * The joint is always between the **parent** and the selected frame. * The editor and its rviz view **always show the angle 0**. To move the lid, export the URDF, close rqt and view the file as described above. Move the **slider** of the *joint_state_publisher_gui* window. ![The lid at three slider positions](../../../_static/manipulation/urdf/frame_editor/15_lid_slider.png "The lid at three slider positions") *RViz and the slider window of the exported URDF, at three slider positions: lid closed (0), half open and fully open (1.571 rad).* Known issues: ----------------------------------------- ### The Absolute Pose fields are greyed out. * Use the **Measurement Tool** instead. Don't use the **Reset** buttons below the Absolute Pose. ### A shape is missing in rviz. * Wait some seconds. Check that you added the **Marker display** (see "Set up rviz"). ### You cannot grab the drag handles. * This needs the optional InteractiveMarkers display. A shape may also be in front of the handles: disable the Marker display while you drag. ### The editor fields are greyed out. * Select a frame in the left list first. For the general features of the frame editor, see the [main README](https://github.com/ROS-Industrial-Session-Common/rqt_frame_editor_plugin/blob/feature/urdf-preview/README.md).