Skip to content

Commit e449158

Browse files
committed
Update examples
1 parent a6fd2d5 commit e449158

File tree

4 files changed

+40
-47
lines changed

4 files changed

+40
-47
lines changed

examples/tesseract_planning_example_composer.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import numpy.testing as nptest
66

77
from tesseract_robotics.tesseract_common import GeneralResourceLocator
8-
from tesseract_robotics.tesseract_environment import Environment
8+
from tesseract_robotics.tesseract_environment import Environment, AnyPoly_wrap_EnvironmentConst
99
from tesseract_robotics.tesseract_common import FilesystemPath, Isometry3d, Translation3d, Quaterniond, \
1010
ManipulatorInfo, AnyPoly, AnyPoly_wrap_double
1111
from tesseract_robotics.tesseract_command_language import CartesianWaypoint, WaypointPoly, \
@@ -15,9 +15,10 @@
1515
AnyPoly_wrap_CompositeInstruction, DEFAULT_PROFILE_KEY, JointWaypoint, JointWaypointPoly, \
1616
InstructionPoly_as_MoveInstructionPoly, WaypointPoly_as_StateWaypointPoly, \
1717
MoveInstructionPoly_wrap_MoveInstruction, StateWaypointPoly_wrap_StateWaypoint, \
18-
CartesianWaypointPoly_wrap_CartesianWaypoint, JointWaypointPoly_wrap_JointWaypoint
18+
CartesianWaypointPoly_wrap_CartesianWaypoint, JointWaypointPoly_wrap_JointWaypoint, \
19+
AnyPoly_wrap_ProfileDictionary
1920

20-
from tesseract_robotics.tesseract_task_composer import TaskComposerPluginFactory, PlanningTaskComposerProblem, \
21+
from tesseract_robotics.tesseract_task_composer import TaskComposerPluginFactory, \
2122
TaskComposerDataStorage, TaskComposerContext
2223

2324
from tesseract_robotics_viewer import TesseractViewer
@@ -134,7 +135,8 @@
134135
task = factory.createTaskComposerNode("FreespacePipeline")
135136

136137
# Get the output keys for the task
137-
output_key = task.getOutputKeys()[0]
138+
output_key = task.getOutputKeys().get("program")
139+
input_key = task.getInputKeys().get("planning_input")
138140

139141
# Create a profile dictionary. Profiles can be customized by adding to this dictionary and setting the profiles
140142
# in the instructions.
@@ -143,18 +145,26 @@
143145
# Create an AnyPoly containing the program. This explicit step is required because the Python bindings do not
144146
# support implicit conversion from the CompositeInstruction to the AnyPoly.
145147
program_anypoly = AnyPoly_wrap_CompositeInstruction(program)
148+
environment_anypoly = AnyPoly_wrap_EnvironmentConst(t_env)
149+
profiles_anypoly = AnyPoly_wrap_ProfileDictionary(profiles)
146150

147-
# Create the task problem and input
148-
task_planning_problem = PlanningTaskComposerProblem(t_env, profiles)
149-
task_planning_problem.input = program_anypoly
151+
# Create the task data
152+
task_data = TaskComposerDataStorage()
153+
task_data.setData(input_key, program_anypoly)
154+
task_data.setData("environment", environment_anypoly)
155+
task_data.setData("profiles", profiles_anypoly)
150156

151157
# Create an executor to run the task
152158
task_executor = factory.createTaskComposerExecutor("TaskflowExecutor")
153159

154160
# Run the task and wait for completion
155-
future = task_executor.run(task.get(), task_planning_problem)
161+
future = task_executor.run(task.get(), task_data)
156162
future.wait()
157163

164+
if not future.context.isSuccessful():
165+
print("Planning task failed")
166+
exit(1)
167+
158168
# Retrieve the output, converting the AnyPoly back to a CompositeInstruction
159169
results = AnyPoly_as_CompositeInstruction(future.context.data_storage.getData(output_key))
160170

examples/tesseract_planning_example_no_composer.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
from tesseract_robotics.tesseract_motion_planners import PlannerRequest, PlannerResponse
1212
from tesseract_robotics.tesseract_motion_planners_simple import generateInterpolatedProgram
1313
from tesseract_robotics.tesseract_motion_planners_ompl import OMPLDefaultPlanProfile, RRTConnectConfigurator, \
14-
OMPLProblemGeneratorFn, OMPLMotionPlanner, ProfileDictionary_addProfile_OMPLPlanProfile
14+
OMPLMotionPlanner, ProfileDictionary_addProfile_OMPLPlanProfile
1515
from tesseract_robotics.tesseract_time_parameterization import TimeOptimalTrajectoryGeneration, \
1616
InstructionsTrajectory
1717
from tesseract_robotics.tesseract_motion_planners_trajopt import TrajOptDefaultPlanProfile, TrajOptDefaultCompositeProfile, \
18-
TrajOptProblemGeneratorFn, TrajOptMotionPlanner, ProfileDictionary_addProfile_TrajOptPlanProfile, \
18+
TrajOptMotionPlanner, ProfileDictionary_addProfile_TrajOptPlanProfile, \
1919
ProfileDictionary_addProfile_TrajOptCompositeProfile
2020

2121
import os
@@ -167,9 +167,13 @@
167167
# output program since the input is modified.
168168
time_parameterization = TimeOptimalTrajectoryGeneration()
169169
instructions_trajectory = InstructionsTrajectory(trajopt_results_instruction)
170-
max_velocity = np.array([2.088, 2.082, 3.27, 3.6, 3.3, 3.078],dtype=np.float64)
171-
max_acceleration = np.array([ 1, 1, 1, 1, 1, 1],dtype=np.float64)
172-
assert time_parameterization.computeTimeStamps(instructions_trajectory, max_velocity, max_acceleration)
170+
max_velocity = np.array([[2.088, 2.082, 3.27, 3.6, 3.3, 3.078]],dtype=np.float64)
171+
max_velocity = np.hstack((-max_velocity.T, max_velocity.T))
172+
max_acceleration = np.array([[ 1, 1, 1, 1, 1, 1]],dtype=np.float64)
173+
max_acceleration = np.hstack((-max_acceleration.T, max_acceleration.T))
174+
max_jerk = np.array([[ 1, 1, 1, 1, 1, 1]],dtype=np.float64)
175+
max_jerk = np.hstack((-max_jerk.T, max_jerk.T))
176+
assert time_parameterization.compute(instructions_trajectory, max_velocity, max_acceleration, max_jerk)
173177

174178
# Flatten the results into a single list of instructions
175179
trajopt_results = trajopt_results_instruction.flatten()

tesseract_viewer_python/examples/abb_irb2400_viewer.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
CompositeInstruction, MoveInstructionPoly, CartesianWaypointPoly, ProfileDictionary, \
88
CartesianWaypointPoly_wrap_CartesianWaypoint, MoveInstructionPoly_wrap_MoveInstruction
99

10-
from tesseract_robotics.tesseract_motion_planners import PlannerRequest, PlannerResponse, generateInterpolatedProgram
10+
from tesseract_robotics.tesseract_motion_planners import PlannerRequest, PlannerResponse
11+
from tesseract_robotics.tesseract_motion_planners_simple import generateInterpolatedProgram
1112
from tesseract_robotics.tesseract_motion_planners_ompl import OMPLDefaultPlanProfile, RRTConnectConfigurator, \
12-
OMPLProblemGeneratorFn, OMPLMotionPlanner, ProfileDictionary_addProfile_OMPLPlanProfile
13+
OMPLMotionPlanner, ProfileDictionary_addProfile_OMPLPlanProfile
1314
from tesseract_robotics.tesseract_time_parameterization import TimeOptimalTrajectoryGeneration, \
1415
InstructionsTrajectory
1516
from tesseract_robotics.tesseract_motion_planners_trajopt import TrajOptDefaultPlanProfile, TrajOptDefaultCompositeProfile, \
16-
TrajOptProblemGeneratorFn, TrajOptMotionPlanner, ProfileDictionary_addProfile_TrajOptPlanProfile, \
17+
TrajOptMotionPlanner, ProfileDictionary_addProfile_TrajOptPlanProfile, \
1718
ProfileDictionary_addProfile_TrajOptCompositeProfile
1819

1920
import os
@@ -115,9 +116,13 @@
115116

116117
time_parameterization = TimeOptimalTrajectoryGeneration()
117118
instructions_trajectory = InstructionsTrajectory(trajopt_results_instruction)
118-
max_velocity = np.array([2.088, 2.082, 3.27, 3.6, 3.3, 3.078],dtype=np.float64)
119-
max_acceleration = np.array([ 1, 1, 1, 1, 1, 1],dtype=np.float64)
120-
assert time_parameterization.computeTimeStamps(instructions_trajectory, max_velocity, max_acceleration)
119+
max_velocity = np.array([[2.088, 2.082, 3.27, 3.6, 3.3, 3.078]],dtype=np.float64)
120+
max_velocity = np.hstack((-max_velocity.T, max_velocity.T))
121+
max_acceleration = np.array([[ 1, 1, 1, 1, 1, 1]],dtype=np.float64)
122+
max_acceleration = np.hstack((-max_acceleration.T, max_acceleration.T))
123+
max_jerk = np.array([[ 1, 1, 1, 1, 1, 1]],dtype=np.float64)
124+
max_jerk = np.hstack((-max_jerk.T, max_jerk.T))
125+
assert time_parameterization.compute(instructions_trajectory, max_velocity, max_acceleration, max_jerk)
121126

122127
trajopt_results = trajopt_results_instruction.flatten()
123128
viewer.update_trajectory(trajopt_results)

tesseract_viewer_python/examples/tesseract_material_mesh_viewer.py

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from tesseract_robotics.tesseract_environment import Environment
2-
from tesseract_robotics.tesseract_common import ResourceLocator, SimpleLocatedResource
2+
from tesseract_robotics.tesseract_common import GeneralResourceLocator
33
import os
44
import re
55
import traceback
@@ -47,36 +47,10 @@
4747
</robot>
4848
"""
4949

50-
TESSERACT_SUPPORT_DIR = os.environ["TESSERACT_SUPPORT_DIR"]
51-
52-
class TesseractSupportResourceLocator(ResourceLocator):
53-
def __init__(self):
54-
super().__init__()
55-
56-
def locateResource(self, url):
57-
try:
58-
try:
59-
if os.path.exists(url):
60-
return SimpleLocatedResource(url, url, self)
61-
except:
62-
pass
63-
url_match = re.match(r"^package:\/\/tesseract_support\/(.*)$",url)
64-
if (url_match is None):
65-
print("url_match failed")
66-
return None
67-
if not "TESSERACT_SUPPORT_DIR" in os.environ:
68-
return None
69-
tesseract_support = os.environ["TESSERACT_SUPPORT_DIR"]
70-
filename = os.path.join(tesseract_support, os.path.normpath(url_match.group(1)))
71-
ret = SimpleLocatedResource(url, filename, self)
72-
return ret
73-
except:
74-
traceback.print_exc()
75-
7650
t_env = Environment()
7751

7852
# locator_fn must be kept alive by maintaining a reference
79-
locator=TesseractSupportResourceLocator()
53+
locator=GeneralResourceLocator()
8054
t_env.init(shapes_urdf, locator)
8155

8256
viewer = TesseractViewer()

0 commit comments

Comments
 (0)