Ask Your Question

How to save and replay a trajectory generated with moveit

asked 2017-09-20 23:14:26 -0600

ani gravatar image

updated 2017-09-20 23:16:59 -0600

Hi all,

I am using moveit's move_group_interface in C++ to generate a trajectory between two NamedTargets for Youbot. Everything works fine including visualization in RViz. However, on repeated execution, the trajectories look slightly different for the same set of targets. So, my question is: Is there any way one can save a trajectory so that it can be reused later on? I have tried saving the "plan.trajectory_", but it doesn't seem to work. Details of current setup is given below.

Robot: Youbot
Planner: OMPL/RRTkConfigDefault
Interface: moveit/move_group_interface in C++
Logic/Sequence Used:
1. Set Start State to Current State
2. Set a Named Target
3. Visualize the plan in Rviz
4. Execute the plan


edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2018-01-02 08:37:09 -0600

pk gravatar image

You can write a script to save the generated plan. When you command a target position in MoveIt!, you can access the trajectory using moveit::planning_interface::MoveGroup::Plan (API). You can save this trajectory as a YAML file and read it next time you are executing the motion, use this Plan for execution. Unfortunately, there is no available function which performs this action.

edit flag offensive delete link more


in case you're wondering how to save a yaml file

NYs gravatar image NYs  ( 2018-01-03 08:28:22 -0600 )edit

Is there a reference for dumping yaml in c++?

pranavb104 gravatar image pranavb104  ( 2019-01-21 04:56:18 -0600 )edit

answered 2018-01-04 07:59:57 -0600

NYs gravatar image

updated 2018-01-04 08:01:05 -0600

Got this working for python on UR5 in Gazebo

import yaml
import os

plan = group.plan()

file_path = os.path.join(os.path.expanduser('~'), 'saved_trajectories', 'plan.yaml')
with open(file_path, 'w') as file_save:
    yaml.dump(plan, file_save, default_flow_style=True)

with open(file_path, 'r') as file_open:
    loaded_plan = yaml.load(file_open)

edit flag offensive delete link more


Is there a reference for dumping yaml in c++?

pranavb104 gravatar image pranavb104  ( 2019-01-21 04:56:26 -0600 )edit

Is there a way to save the trajectory using RViz?

Diliban gravatar image Diliban  ( 2021-01-08 06:23:17 -0600 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools



Asked: 2017-09-20 23:14:26 -0600

Seen: 2,227 times

Last updated: Jan 04 '18