Skip to content

Commit 61496cc

Browse files
author
Yoan Mollard
committed
Created overlay for DMP trajectories
1 parent 30c010f commit 61496cc

File tree

6 files changed

+77
-4
lines changed

6 files changed

+77
-4
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ project(dmp_lib)
44
## Find catkin macros and libraries
55
## if COMPONENTS list like find_package(catkin REQUIRED COMPONENTS xyz)
66
## is used, also find other catkin packages
7-
find_package(catkin REQUIRED)
7+
find_package(catkin REQUIRED nav_msgs geometry_msgs)
88

99
## System dependencies are found with CMake's conventions
1010
# find_package(Boost REQUIRED COMPONENTS system)

package.xml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
<description>DMP generator</description>
66

77
<maintainer email="[email protected]">Busch Baptiste</maintainer>
8-
<license>TODO</license>
8+
<maintainer email="[email protected]">Yoan Mollard</maintainer>
9+
<license>GNU3</license>
910

1011
<!-- The *_depend tags are used to specify dependencies -->
1112
<!-- Dependencies can be catkin packages or system dependencies -->
@@ -19,7 +20,10 @@
1920
<!-- Use test_depend for packages you need only for testing: -->
2021
<!-- <test_depend>gtest</test_depend> -->
2122
<buildtool_depend>catkin</buildtool_depend>
22-
23+
<build_depend>trajectory_msgs</build_depend>
24+
<build_depend>nav_msgs</build_depend>
25+
<run_depend>trajectory_msgs</run_depend>
26+
<run_depend>nav_msgs</run_depend>
2327

2428
<!-- The export tag contains other, unspecified, tags -->
2529
<export>

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# fetch values from package.xml
77
setup_args = generate_distutils_setup(
8-
packages=['dmp_lib'],
8+
packages=['dmp_lib', 'dmp_trajectories'],
99
package_dir={'': 'src'},
1010
)
1111

src/dmp_lib/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . dmp_discrete import DMPs_discrete
2+
from . dmp_rhythmic import DMPs_rhythmic

src/dmp_trajectories/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . dmp_traj_discrete import *
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from dmp_lib import DMPs_discrete
2+
from nav_msgs.msg import Path
3+
from geometry_msgs.msg import PoseStamped
4+
from transformations import pose_to_list, list_to_pose # TODO dependency baxter_commander
5+
from tf.transformations import quaternion_about_axis
6+
import numpy as np
7+
import rospy
8+
9+
# dmp = DMPs_discrete(dmps=2, bfs=bfs)
10+
# print len(np.array([path1, path2])
11+
# dmp.imitate_path(y_des=np.array([path1, path2]))
12+
# # change the scale of the movement
13+
# dmp.goal[0] = 3; dmp.goal[1] = 2
14+
15+
# y_track,dy_track,ddy_track = dmp.rollout()
16+
17+
class DiscreteTaskSpaceTrajectory(object):
18+
NUMBER_STABLE_STATES = 50
19+
20+
def __init__(self, init_path, bfs=10):
21+
assert isinstance(path, Path)
22+
self.init_path = init_path
23+
self._dmp = DMPs_discrete(dmps=7, bfs=bfs)
24+
self._dmp.imitate_path(self._path_to_y_des(init_path, self.NUMBER_STABLE_STATES))
25+
26+
if self.init_path.header.frame_id == '':
27+
self.init_path.header.frame_id = self.init_path.poses[0].header.frame_id
28+
29+
def _path_to_y_des(self, path, nss):
30+
y_des = []
31+
for pose_s in path.poses:
32+
assert pose_s.header.frame_id == self.init_path.header.frame_id
33+
pose = [val for sublist in pose_to_list(pose_s) for val in sublist] # flatten to [x, y, z, x, y, z, w]
34+
y_des.append(pose)
35+
36+
# Repeat the last point (stable state) n times to avoid brutal cuts due to asymptotic approach
37+
for n in range(nss):
38+
y_des.append(y_des[-1])
39+
40+
return np.array(y_des).transpose()
41+
42+
def rollout(self, goal):
43+
assert isinstance(goal, PoseStamped)
44+
self._dmp.goal = [val for sublist in pose_to_list(goal) for val in sublist]
45+
y_track, dy_track, ddy_track = self._dmp.rollout()
46+
47+
path = Path()
48+
for y in y_track:
49+
path.poses.append(list_to_pose([[y[0], y[1], y[2]], [y[3], y[4], y[5], y[6]]],
50+
frame_id=self.init_path.header.frame_id))
51+
path.header.stamp = rospy.Time.now()
52+
path.header.frame_id = self.init_path.header.frame_id
53+
return path
54+
55+
if __name__=='__main__':
56+
rospy.init_node("test_dmp_traj_discrete")
57+
path = Path()
58+
for i in range(100):
59+
quat = quaternion_about_axis(i*0.00628, (1, 0, 0))
60+
pose = list_to_pose([[i/100., i/100., i/100.], quat])
61+
pose.header.stamp = i/10.
62+
path.poses.append(pose)
63+
64+
goal = list_to_pose([[-10, -10, -10], [0.707, 0, 0, 0.707]])
65+
rollout = DiscreteTaskSpaceTrajectory(path).rollout(goal)
66+
print rollout

0 commit comments

Comments
 (0)