6
6
#
7
7
# Redistribution and use in source and binary forms, with or without
8
8
# modification, are permitted provided that the following conditions are met:
9
- #
9
+ #
10
10
# - Redistributions of source code must retain the above copyright notice, this
11
11
# list of conditions and the following disclaimer.
12
12
# - Redistributions in binary form must reproduce the above copyright notice,
15
15
# - Neither the name of Carnegie Mellon University nor the names of its
16
16
# contributors may be used to endorse or promote products derived from this
17
17
# software without specific prior written permission.
18
- #
18
+ #
19
19
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20
20
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21
21
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32
32
from ..util import SetTrajectoryTags
33
33
from base import BasePlanner , PlanningError , PlanningMethod , Tags
34
34
35
+
35
36
class SnapPlanner (BasePlanner ):
36
37
"""Planner that checks the straight-line trajectory to the goal.
37
38
@@ -40,15 +41,15 @@ class SnapPlanner(BasePlanner):
40
41
due to an environment or self collision, the planner immediately returns
41
42
failure by raising a PlanningError. Collision checking is performed using
42
43
the standard CheckPathAllConstraints method.
43
-
44
+
44
45
SnapPlanner is intended to be used only as a "short circuit" to speed up
45
46
planning between nearby configurations. This planner is most commonly used
46
47
as the first item in a Sequence meta-planner to avoid calling a motion
47
48
planner when the trivial solution is valid.
48
49
"""
49
50
def __init__ (self ):
50
51
super (SnapPlanner , self ).__init__ ()
51
-
52
+
52
53
def __str__ (self ):
53
54
return 'SnapPlanner'
54
55
@@ -86,7 +87,6 @@ def PlanToEndEffectorPose(self, robot, goal_pose, **kw_args):
86
87
# close to the configuration of the arm, so we don't need to do any
87
88
# custom IK ranking.
88
89
manipulator = robot .GetActiveManipulator ()
89
- current_config = robot .GetDOFValues (manipulator .GetArmIndices ())
90
90
ik_param = openravepy .IkParameterization (goal_pose , ikp .Transform6D )
91
91
ik_solution = manipulator .FindIKSolution (
92
92
ik_param , ikfo .CheckEnvCollisions ,
@@ -101,7 +101,7 @@ def PlanToEndEffectorPose(self, robot, goal_pose, **kw_args):
101
101
def _Snap (self , robot , goal , ** kw_args ):
102
102
Closed = openravepy .Interval .Closed
103
103
104
- curr = robot .GetActiveDOFValues ()
104
+ start = robot .GetActiveDOFValues ()
105
105
active_indices = robot .GetActiveDOFIndices ()
106
106
107
107
# Use the CheckPathAllConstraints helper function to collision check
@@ -110,28 +110,32 @@ def _Snap(self, robot, goal, **kw_args):
110
110
params = openravepy .Planner .PlannerParameters ()
111
111
params .SetRobotActiveJoints (robot )
112
112
params .SetGoalConfig (goal )
113
- check = params .CheckPathAllConstraints (curr , goal , [], [], 0. , Closed )
113
+ check = params .CheckPathAllConstraints (start , goal , [], [], 0. , Closed )
114
114
115
115
# The function returns a bitmask of ConstraintFilterOptions flags,
116
116
# indicating which constraints are violated. We'll abort if any
117
117
# constraints are violated.
118
118
if check != 0 :
119
119
raise PlanningError ('Straight line trajectory is not valid.' )
120
120
121
- # Create a two-point trajectory that starts at our current
122
- # configuration and takes us to the goal.
123
- traj = openravepy .RaveCreateTrajectory (self .env , '' )
121
+ # Create a trajectory that starts at our current configuration.
124
122
cspec = robot .GetActiveConfigurationSpecification ()
125
- active_indices = robot .GetActiveDOFIndices ()
123
+ traj = openravepy .RaveCreateTrajectory (self .env , '' )
124
+ traj .Init (cspec )
126
125
127
- waypoints = numpy .zeros ((2 , cspec .GetDOF ()))
128
- cspec .InsertJointValues (waypoints [0 , :], curr , robot ,
129
- active_indices , False )
130
- cspec .InsertJointValues (waypoints [1 , :], goal , robot ,
126
+ start_waypoint = numpy .zeros (cspec .GetDOF ())
127
+ cspec .InsertJointValues (start_waypoint , start , robot ,
131
128
active_indices , False )
129
+ traj .Insert (0 , start_waypoint .ravel ())
132
130
133
- traj .Init (cspec )
134
- traj .Insert (0 , waypoints .ravel ())
131
+ # Make the trajectory end at the goal configuration, as long as it
132
+ # was not identical to the start configuration.
133
+ if not numpy .allclose (start , goal ):
134
+ goal_waypoint = numpy .zeros (cspec .GetDOF ())
135
+ cspec .InsertJointValues (goal_waypoint , goal , robot ,
136
+ active_indices , False )
137
+ traj .Insert (1 , goal_waypoint .ravel ())
135
138
139
+ # Tag the return trajectory as smooth (in joint space) and return it.
136
140
SetTrajectoryTags (traj , {Tags .SMOOTH : True }, append = True )
137
141
return traj
0 commit comments