wandelbots-isaacsim-api 2.2.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. wandelbots_isaacsim_api/__init__.py +50 -0
  2. wandelbots_isaacsim_api/api/__init__.py +25 -0
  3. wandelbots_isaacsim_api/api/collision_world_api.py +316 -0
  4. wandelbots_isaacsim_api/api/default_api.py +800 -0
  5. wandelbots_isaacsim_api/api/manipulators_motion_group_api.py +1619 -0
  6. wandelbots_isaacsim_api/api/periphery_camera_api.py +3434 -0
  7. wandelbots_isaacsim_api/api/prims_api.py +4963 -0
  8. wandelbots_isaacsim_api/api/stage_api.py +2351 -0
  9. wandelbots_isaacsim_api/api/teaching_api.py +1312 -0
  10. wandelbots_isaacsim_api/api/trajectory_api.py +1686 -0
  11. wandelbots_isaacsim_api/api/ui_api.py +562 -0
  12. wandelbots_isaacsim_api/api_client.py +800 -0
  13. wandelbots_isaacsim_api/api_response.py +21 -0
  14. wandelbots_isaacsim_api/collision/__init__.py +0 -0
  15. wandelbots_isaacsim_api/collision/utils.py +99 -0
  16. wandelbots_isaacsim_api/configuration.py +561 -0
  17. wandelbots_isaacsim_api/exceptions.py +216 -0
  18. wandelbots_isaacsim_api/models/__init__.py +135 -0
  19. wandelbots_isaacsim_api/models/auth0_credentials.py +100 -0
  20. wandelbots_isaacsim_api/models/body_apply_relative_pose.py +99 -0
  21. wandelbots_isaacsim_api/models/body_assign_default_poses.py +91 -0
  22. wandelbots_isaacsim_api/models/body_reset_to_default_poses.py +91 -0
  23. wandelbots_isaacsim_api/models/body_set_joint_state.py +93 -0
  24. wandelbots_isaacsim_api/models/body_set_prim_metadata.py +97 -0
  25. wandelbots_isaacsim_api/models/body_set_prim_visibility.py +103 -0
  26. wandelbots_isaacsim_api/models/body_set_semantic_label.py +93 -0
  27. wandelbots_isaacsim_api/models/body_update_colliders.py +93 -0
  28. wandelbots_isaacsim_api/models/body_update_pose.py +97 -0
  29. wandelbots_isaacsim_api/models/bounding_box2_d.py +98 -0
  30. wandelbots_isaacsim_api/models/bounding_box3_d.py +100 -0
  31. wandelbots_isaacsim_api/models/box.py +119 -0
  32. wandelbots_isaacsim_api/models/box_sweep_parameters.py +111 -0
  33. wandelbots_isaacsim_api/models/capsule.py +105 -0
  34. wandelbots_isaacsim_api/models/collider.py +101 -0
  35. wandelbots_isaacsim_api/models/convex_hull.py +103 -0
  36. wandelbots_isaacsim_api/models/create_ghost_object.py +102 -0
  37. wandelbots_isaacsim_api/models/custom_prim.py +100 -0
  38. wandelbots_isaacsim_api/models/custom_prim_data.py +93 -0
  39. wandelbots_isaacsim_api/models/cylinder.py +105 -0
  40. wandelbots_isaacsim_api/models/ghost_object.py +106 -0
  41. wandelbots_isaacsim_api/models/ghost_object_source.py +93 -0
  42. wandelbots_isaacsim_api/models/gizmo_prim.py +98 -0
  43. wandelbots_isaacsim_api/models/http_validation_error.py +108 -0
  44. wandelbots_isaacsim_api/models/instance_segmentation_data.py +97 -0
  45. wandelbots_isaacsim_api/models/instance_segmentation_info.py +91 -0
  46. wandelbots_isaacsim_api/models/motion_group_configuration.py +99 -0
  47. wandelbots_isaacsim_api/models/motion_stream_configuration.py +101 -0
  48. wandelbots_isaacsim_api/models/patch_trajectory_data.py +107 -0
  49. wandelbots_isaacsim_api/models/plane.py +101 -0
  50. wandelbots_isaacsim_api/models/point_cloud.py +95 -0
  51. wandelbots_isaacsim_api/models/pose.py +137 -0
  52. wandelbots_isaacsim_api/models/pose_position_inner.py +138 -0
  53. wandelbots_isaacsim_api/models/prim.py +165 -0
  54. wandelbots_isaacsim_api/models/prim_selection.py +91 -0
  55. wandelbots_isaacsim_api/models/quat_pose.py +92 -0
  56. wandelbots_isaacsim_api/models/relative_pose_mode.py +39 -0
  57. wandelbots_isaacsim_api/models/response_get_pose.py +134 -0
  58. wandelbots_isaacsim_api/models/response_get_relative_pose.py +134 -0
  59. wandelbots_isaacsim_api/models/response_list_default_poses_value.py +140 -0
  60. wandelbots_isaacsim_api/models/semantic_segmentation_data.py +97 -0
  61. wandelbots_isaacsim_api/models/semantic_segmentation_info.py +91 -0
  62. wandelbots_isaacsim_api/models/shape.py +194 -0
  63. wandelbots_isaacsim_api/models/simulation_state.py +101 -0
  64. wandelbots_isaacsim_api/models/sphere.py +103 -0
  65. wandelbots_isaacsim_api/models/sphere_sweep_parameters.py +107 -0
  66. wandelbots_isaacsim_api/models/stage_units.py +91 -0
  67. wandelbots_isaacsim_api/models/sweep_arguments.py +134 -0
  68. wandelbots_isaacsim_api/models/tcp_source.py +99 -0
  69. wandelbots_isaacsim_api/models/trajectory_data.py +101 -0
  70. wandelbots_isaacsim_api/models/trajectory_marker.py +97 -0
  71. wandelbots_isaacsim_api/models/trajectory_object.py +101 -0
  72. wandelbots_isaacsim_api/models/trajectory_options.py +94 -0
  73. wandelbots_isaacsim_api/models/usd_stage_model.py +91 -0
  74. wandelbots_isaacsim_api/models/validation_error.py +112 -0
  75. wandelbots_isaacsim_api/models/validation_error_loc_inner.py +138 -0
  76. wandelbots_isaacsim_api/models/ws_pose.py +92 -0
  77. wandelbots_isaacsim_api/py.typed +0 -0
  78. wandelbots_isaacsim_api/rest.py +212 -0
  79. wandelbots_isaacsim_api/trajectory/__init__.py +17 -0
  80. wandelbots_isaacsim_api/trajectory/trajectory_viewer.py +111 -0
  81. wandelbots_isaacsim_api/trajectory/utils.py +154 -0
  82. wandelbots_isaacsim_api-2.2.2.dist-info/LICENSE +201 -0
  83. wandelbots_isaacsim_api-2.2.2.dist-info/METADATA +60 -0
  84. wandelbots_isaacsim_api-2.2.2.dist-info/RECORD +85 -0
  85. wandelbots_isaacsim_api-2.2.2.dist-info/WHEEL +4 -0
@@ -0,0 +1,92 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Wandelbots Omniservice
5
+
6
+ A microservice-based framework for managing Omniverse functionalities
7
+
8
+ The version of the OpenAPI document: 2.2.2
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ from __future__ import annotations
16
+ import pprint
17
+ import re # noqa: F401
18
+ import json
19
+
20
+ from pydantic import BaseModel, ConfigDict, Field, StrictFloat, StrictInt
21
+ from typing import Any, ClassVar, Dict, List, Optional, Union
22
+ from typing_extensions import Annotated
23
+ from typing import Optional, Set
24
+ from typing_extensions import Self
25
+
26
+ class WSPose(BaseModel):
27
+ """
28
+ WSPose
29
+ """ # noqa: E501
30
+ pose: Optional[Annotated[List[Union[StrictFloat, StrictInt]], Field(min_length=6, max_length=6)]] = Field(default=None, description="Pose in rotation vector format (WS)")
31
+ __properties: ClassVar[List[str]] = ["pose"]
32
+
33
+ model_config = ConfigDict(
34
+ populate_by_name=True,
35
+ validate_assignment=True,
36
+ protected_namespaces=(),
37
+ )
38
+
39
+
40
+ def to_str(self) -> str:
41
+ """Returns the string representation of the model using alias"""
42
+ return pprint.pformat(self.model_dump(by_alias=True, exclude_none=True))
43
+
44
+ def to_json(self) -> str:
45
+ """
46
+ Returns the JSON representation of the model using alias
47
+
48
+ Do not use pydantic v2 .model_dump_json(by_alias=True, exclude_unset=True) here!
49
+ It is unable to resolve nested types generated by openapi-generator.
50
+ """
51
+ return json.dumps(self.to_dict())
52
+
53
+ @classmethod
54
+ def from_json(cls, json_str: str) -> Optional[Self]:
55
+ """Create an instance of WSPose from a JSON string"""
56
+ return cls.from_dict(json.loads(json_str))
57
+
58
+ def to_dict(self) -> Dict[str, Any]:
59
+ """Return the dictionary representation of the model using alias.
60
+
61
+ This has the following differences from calling pydantic's
62
+ `self.model_dump(by_alias=True)`:
63
+
64
+ * `None` is only added to the output dict for nullable fields that
65
+ were set at model initialization. Other fields with value `None`
66
+ are ignored.
67
+ """
68
+ excluded_fields: Set[str] = set([
69
+ ])
70
+
71
+ _dict = self.model_dump(
72
+ by_alias=True,
73
+ exclude=excluded_fields,
74
+ exclude_none=True,
75
+ )
76
+ return _dict
77
+
78
+ @classmethod
79
+ def from_dict(cls, obj: Optional[Dict[str, Any]]) -> Optional[Self]:
80
+ """Create an instance of WSPose from a dict"""
81
+ if obj is None:
82
+ return None
83
+
84
+ if not isinstance(obj, dict):
85
+ return cls.model_validate(obj)
86
+
87
+ _obj = cls.model_validate({
88
+ "pose": obj.get("pose")
89
+ })
90
+ return _obj
91
+
92
+
File without changes
@@ -0,0 +1,212 @@
1
+ # coding: utf-8
2
+
3
+ """
4
+ Wandelbots Omniservice
5
+
6
+ A microservice-based framework for managing Omniverse functionalities
7
+
8
+ The version of the OpenAPI document: 2.2.2
9
+ Generated by OpenAPI Generator (https://openapi-generator.tech)
10
+
11
+ Do not edit the class manually.
12
+ """ # noqa: E501
13
+
14
+
15
+ import io
16
+ import json
17
+ import re
18
+ import ssl
19
+ from typing import Optional, Union
20
+
21
+ import aiohttp
22
+ import aiohttp_retry
23
+
24
+ from wandelbots_isaacsim_api.exceptions import ApiException, ApiValueError
25
+
26
+ RESTResponseType = aiohttp.ClientResponse
27
+
28
+ ALLOW_RETRY_METHODS = frozenset({'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT', 'TRACE'})
29
+
30
+ class RESTResponse(io.IOBase):
31
+
32
+ def __init__(self, resp) -> None:
33
+ self.response = resp
34
+ self.status = resp.status
35
+ self.reason = resp.reason
36
+ self.data = None
37
+
38
+ async def read(self):
39
+ if self.data is None:
40
+ self.data = await self.response.read()
41
+ return self.data
42
+
43
+ def getheaders(self):
44
+ """Returns a CIMultiDictProxy of the response headers."""
45
+ return self.response.headers
46
+
47
+ def getheader(self, name, default=None):
48
+ """Returns a given response header."""
49
+ return self.response.headers.get(name, default)
50
+
51
+
52
+ class RESTClientObject:
53
+
54
+ def __init__(self, configuration) -> None:
55
+
56
+ # maxsize is number of requests to host that are allowed in parallel
57
+ self.maxsize = configuration.connection_pool_maxsize
58
+
59
+ self.ssl_context = ssl.create_default_context(
60
+ cafile=configuration.ssl_ca_cert
61
+ )
62
+ if configuration.cert_file:
63
+ self.ssl_context.load_cert_chain(
64
+ configuration.cert_file, keyfile=configuration.key_file
65
+ )
66
+
67
+ if not configuration.verify_ssl:
68
+ self.ssl_context.check_hostname = False
69
+ self.ssl_context.verify_mode = ssl.CERT_NONE
70
+
71
+ self.proxy = configuration.proxy
72
+ self.proxy_headers = configuration.proxy_headers
73
+
74
+ self.retries = configuration.retries
75
+
76
+ self.pool_manager: Optional[aiohttp.ClientSession] = None
77
+ self.retry_client: Optional[aiohttp_retry.RetryClient] = None
78
+
79
+ async def close(self) -> None:
80
+ if self.pool_manager:
81
+ await self.pool_manager.close()
82
+ if self.retry_client is not None:
83
+ await self.retry_client.close()
84
+
85
+ async def request(
86
+ self,
87
+ method,
88
+ url,
89
+ headers=None,
90
+ body=None,
91
+ post_params=None,
92
+ _request_timeout=None
93
+ ):
94
+ """Execute request
95
+
96
+ :param method: http request method
97
+ :param url: http request url
98
+ :param headers: http request headers
99
+ :param body: request json body, for `application/json`
100
+ :param post_params: request post parameters,
101
+ `application/x-www-form-urlencoded`
102
+ and `multipart/form-data`
103
+ :param _request_timeout: timeout setting for this request. If one
104
+ number provided, it will be total request
105
+ timeout. It can also be a pair (tuple) of
106
+ (connection, read) timeouts.
107
+ """
108
+ method = method.upper()
109
+ assert method in [
110
+ 'GET',
111
+ 'HEAD',
112
+ 'DELETE',
113
+ 'POST',
114
+ 'PUT',
115
+ 'PATCH',
116
+ 'OPTIONS'
117
+ ]
118
+
119
+ if post_params and body:
120
+ raise ApiValueError(
121
+ "body parameter cannot be used with post_params parameter."
122
+ )
123
+
124
+ post_params = post_params or {}
125
+ headers = headers or {}
126
+ # url already contains the URL query string
127
+ timeout = _request_timeout or 5 * 60
128
+
129
+ if 'Content-Type' not in headers:
130
+ headers['Content-Type'] = 'application/json'
131
+
132
+ args = {
133
+ "method": method,
134
+ "url": url,
135
+ "timeout": timeout,
136
+ "headers": headers
137
+ }
138
+
139
+ if self.proxy:
140
+ args["proxy"] = self.proxy
141
+ if self.proxy_headers:
142
+ args["proxy_headers"] = self.proxy_headers
143
+
144
+ # For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
145
+ if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
146
+ if re.search('json', headers['Content-Type'], re.IGNORECASE):
147
+ if body is not None:
148
+ body = json.dumps(body)
149
+ args["data"] = body
150
+ elif headers['Content-Type'] == 'application/x-www-form-urlencoded':
151
+ args["data"] = aiohttp.FormData(post_params)
152
+ elif headers['Content-Type'] == 'multipart/form-data':
153
+ # must del headers['Content-Type'], or the correct
154
+ # Content-Type which generated by aiohttp
155
+ del headers['Content-Type']
156
+ data = aiohttp.FormData()
157
+ for param in post_params:
158
+ k, v = param
159
+ if isinstance(v, tuple) and len(v) == 3:
160
+ data.add_field(
161
+ k,
162
+ value=v[1],
163
+ filename=v[0],
164
+ content_type=v[2]
165
+ )
166
+ else:
167
+ # Ensures that dict objects are serialized
168
+ if isinstance(v, dict):
169
+ v = json.dumps(v)
170
+ elif isinstance(v, int):
171
+ v = str(v)
172
+ data.add_field(k, v)
173
+ args["data"] = data
174
+
175
+ # Pass a `bytes` or `str` parameter directly in the body to support
176
+ # other content types than Json when `body` argument is provided
177
+ # in serialized form
178
+ elif isinstance(body, str) or isinstance(body, bytes):
179
+ args["data"] = body
180
+ else:
181
+ # Cannot generate the request from given parameters
182
+ msg = """Cannot prepare a request message for provided
183
+ arguments. Please check that your arguments match
184
+ declared content type."""
185
+ raise ApiException(status=0, reason=msg)
186
+
187
+ pool_manager: Union[aiohttp.ClientSession, aiohttp_retry.RetryClient]
188
+
189
+ # https pool manager
190
+ if self.pool_manager is None:
191
+ self.pool_manager = aiohttp.ClientSession(
192
+ connector=aiohttp.TCPConnector(limit=self.maxsize, ssl=self.ssl_context),
193
+ trust_env=True,
194
+ )
195
+ pool_manager = self.pool_manager
196
+
197
+ if self.retries is not None and method in ALLOW_RETRY_METHODS:
198
+ if self.retry_client is None:
199
+ self.retry_client = aiohttp_retry.RetryClient(
200
+ client_session=self.pool_manager,
201
+ retry_options=aiohttp_retry.ExponentialRetry(
202
+ attempts=self.retries,
203
+ factor=2.0,
204
+ start_timeout=0.1,
205
+ max_timeout=120.0
206
+ )
207
+ )
208
+ pool_manager = self.retry_client
209
+
210
+ r = await pool_manager.request(**args)
211
+
212
+ return RESTResponse(r)
@@ -0,0 +1,17 @@
1
+ from .trajectory_viewer import (
2
+ TrajectoryViewer,
3
+ TrajectoryPlanResultConfiguration,
4
+ )
5
+ from .utils import (
6
+ draw_pose_trajectory,
7
+ draw_joint_trajectory,
8
+ TrajectoryDrawOptimization,
9
+ )
10
+
11
+ __all__ = [
12
+ "TrajectoryViewer",
13
+ "TrajectoryPlanResultConfiguration",
14
+ "draw_pose_trajectory",
15
+ "draw_joint_trajectory",
16
+ "TrajectoryDrawOptimization",
17
+ ]
@@ -0,0 +1,111 @@
1
+ from typing import Sequence
2
+ from nova import Nova
3
+ from attr import dataclass
4
+ import wandelbots_isaacsim_api as isaac_sim_api
5
+ import wandelbots_api_client as nova_api
6
+ from nova.viewers import Viewer, manager as viewer_manager
7
+ from nova.actions import Action
8
+ import nova.core.motion_group
9
+ import os
10
+ from . import utils as trajectory_utils
11
+ from nova.core.exceptions import PlanTrajectoryFailed
12
+
13
+
14
+ @dataclass
15
+ class TrajectoryPlanResultConfiguration:
16
+ parent_prim_path: str = "/World"
17
+ name: str = "PlannedTrajectory"
18
+ options: isaac_sim_api.models.TrajectoryOptions = (
19
+ isaac_sim_api.models.TrajectoryOptions(color=[255, 255, 255], width=20),
20
+ )
21
+ optimization: trajectory_utils.TrajectoryDrawOptimization = (
22
+ trajectory_utils.TrajectoryDrawOptimization()
23
+ )
24
+
25
+
26
+ class TrajectoryViewer(Viewer):
27
+ """Viewer for visualizing trajectories in Omniverse."""
28
+
29
+ def __init__(
30
+ self,
31
+ omniverse_host: str = None,
32
+ trajectory_success=TrajectoryPlanResultConfiguration(name="PlannedTrajectory"),
33
+ trajectory_failure=TrajectoryPlanResultConfiguration(
34
+ name="PlannedTrajectoryFailed",
35
+ options=isaac_sim_api.models.TrajectoryOptions(color=[255, 0, 0], width=20),
36
+ ),
37
+ ) -> None:
38
+ """Initialize viewer.
39
+
40
+ Args:
41
+ omniverse_host (str, optional): Custom host to omniverse. If None OMNIVERSE_HOST env variable will be used. Defaults to None.
42
+ trajectory_success (_type_, optional): Settings of success callback.
43
+ trajectory_failure (_type_, optional): Settings of failure callback.
44
+ """
45
+
46
+ viewer_manager.register_viewer(self)
47
+ self._omniverse_host = omniverse_host
48
+
49
+ self.trajectory_success = trajectory_success
50
+ self.trajectory_failure = trajectory_failure
51
+
52
+ def configure(self, nova: Nova) -> None:
53
+ """Configure the viewer with the Nova instance."""
54
+ self.nova = nova
55
+
56
+ def cleanup(self) -> None:
57
+ """Clean up the viewer resources."""
58
+ pass
59
+
60
+ async def log_planning_success(
61
+ self,
62
+ actions: Sequence[Action],
63
+ trajectory: nova_api.models.JointTrajectory,
64
+ tcp: str,
65
+ motion_group: nova.core.motion_group.MotionGroup,
66
+ ) -> None:
67
+ host = self._omniverse_host or os.getenv("OMNIVERSE_HOST")
68
+ async with isaac_sim_api.ApiClient(
69
+ isaac_sim_api.Configuration(host=host)
70
+ ) as isaac_sim_api_client:
71
+ await trajectory_utils.draw_joint_trajectory(
72
+ api_client=isaac_sim_api_client,
73
+ nova_api_client=self.nova._api_client._api_client,
74
+ joint_trajectory=trajectory,
75
+ cell=motion_group._cell,
76
+ motion_group=motion_group.motion_group_id,
77
+ tcp=tcp,
78
+ parent_prim_path=self.trajectory_success.parent_prim_path,
79
+ name=self.trajectory_success.name,
80
+ options=self.trajectory_success.options,
81
+ optimiation=self.trajectory_success.optimization,
82
+ overwrite_existing=True,
83
+ )
84
+
85
+ async def log_planning_failure(
86
+ self,
87
+ actions: Sequence[Action],
88
+ error: Exception,
89
+ tcp: str,
90
+ motion_group: nova.core.motion_group.MotionGroup,
91
+ ) -> None:
92
+ if not isinstance(error, PlanTrajectoryFailed):
93
+ return
94
+ host = self._omniverse_host or os.getenv("OMNIVERSE_HOST")
95
+
96
+ async with isaac_sim_api.ApiClient(
97
+ isaac_sim_api.Configuration(host=host)
98
+ ) as omniservice_api_client:
99
+ await trajectory_utils.draw_joint_trajectory(
100
+ api_client=omniservice_api_client,
101
+ nova_api_client=self.nova._api_client._api_client,
102
+ joint_trajectory=error.error.joint_trajectory,
103
+ cell=motion_group._cell,
104
+ motion_group=motion_group.motion_group_id,
105
+ tcp=tcp,
106
+ parent_prim_path=self.trajectory_failure.parent_prim_path,
107
+ name=self.trajectory_failure.name,
108
+ options=self.trajectory_failure.options,
109
+ optimiation=self.trajectory_failure.optimization,
110
+ overwrite_existing=True,
111
+ )
@@ -0,0 +1,154 @@
1
+ from attr import dataclass
2
+ import wandelbots_isaacsim_api as isaac_sim_api
3
+ import wandelbots_api_client as nova_api
4
+
5
+
6
+ @dataclass
7
+ class TrajectoryDrawOptimization:
8
+ min_time_delta_seconds: float = 0.5
9
+ min_pose_distance_millimeters: float = 10.0
10
+
11
+
12
+ async def draw_joint_trajectory(
13
+ api_client: isaac_sim_api.ApiClient,
14
+ nova_api_client: nova_api.ApiClient,
15
+ joint_trajectory: nova_api.models.JointTrajectory,
16
+ cell: str,
17
+ motion_group: str,
18
+ tcp="Flange",
19
+ parent_prim_path="/World",
20
+ name="JointTrajectory",
21
+ options: isaac_sim_api.models.TrajectoryOptions = isaac_sim_api.models.TrajectoryOptions(
22
+ color=[255, 255, 255], width=20
23
+ ),
24
+ optimiation: TrajectoryDrawOptimization = TrajectoryDrawOptimization(),
25
+ overwrite_existing=True,
26
+ ) -> None:
27
+ kinematic_api = nova_api.MotionGroupKinematicApi(nova_api_client)
28
+
29
+ joint_trajectory = _resacle_trajectory_timeline(
30
+ joint_trajectory, min_time_delta_seconds=optimiation.min_time_delta_seconds
31
+ )
32
+
33
+ poses = [
34
+ await kinematic_api.calculate_forward_kinematic(
35
+ cell=cell,
36
+ motion_group=motion_group,
37
+ tcp_pose_request=nova_api.models.TcpPoseRequest(
38
+ motion_group=motion_group,
39
+ tcp=tcp,
40
+ joint_position=joint_state,
41
+ ),
42
+ )
43
+ for joint_state in joint_trajectory.joint_positions
44
+ ]
45
+ await draw_pose_trajectory(
46
+ api_client,
47
+ poses=poses,
48
+ parent_prim_path=parent_prim_path,
49
+ name=name,
50
+ options=options,
51
+ overwrite_existing=overwrite_existing,
52
+ min_pose_distance_millimeters=optimiation.min_pose_distance_millimeters,
53
+ )
54
+
55
+
56
+ async def draw_pose_trajectory(
57
+ api_client: isaac_sim_api.ApiClient,
58
+ poses: list[nova_api.models.Pose],
59
+ name="Trajectory",
60
+ parent_prim_path="/World",
61
+ options: isaac_sim_api.models.TrajectoryOptions = isaac_sim_api.models.TrajectoryOptions(
62
+ color=[255, 255, 255], width=20
63
+ ),
64
+ overwrite_existing=True,
65
+ min_pose_distance_millimeters=10.0,
66
+ ) -> None:
67
+ trajectory_api = isaac_sim_api.TrajectoryApi(api_client)
68
+ update_trajectory = False
69
+
70
+ poses = _reduce_pose_overlap(poses, min_pose_distance_millimeters)
71
+
72
+ poses = [
73
+ [
74
+ pose.position.x,
75
+ pose.position.y,
76
+ pose.position.z,
77
+ pose.orientation.x,
78
+ pose.orientation.y,
79
+ pose.orientation.z,
80
+ ]
81
+ for pose in poses
82
+ ]
83
+
84
+ if overwrite_existing:
85
+ update_trajectory = f"{parent_prim_path}/{name}" in [
86
+ f"{parent_prim_path}/{trajectory.name}"
87
+ for trajectory in await trajectory_api.list_trajectories()
88
+ ]
89
+
90
+ if update_trajectory:
91
+ await trajectory_api.update_trajectory(
92
+ name=name,
93
+ patch_trajectory_data=isaac_sim_api.models.PatchTrajectoryData(
94
+ poses=poses,
95
+ options=options,
96
+ ),
97
+ )
98
+ else:
99
+ await trajectory_api.create_trajectory(
100
+ isaac_sim_api.models.TrajectoryData(
101
+ name=name,
102
+ parent_prim_path=parent_prim_path,
103
+ poses=poses,
104
+ options=options,
105
+ )
106
+ )
107
+
108
+
109
+ def _resacle_trajectory_timeline(
110
+ trajectory: nova_api.models.JointTrajectory, min_time_delta_seconds=0.5
111
+ ) -> nova_api.models.JointTrajectory:
112
+ time_rescaled_trajectory = nova_api.models.JointTrajectory(
113
+ joint_positions=[], times=[], locations=[]
114
+ )
115
+ last_time = 0.0
116
+ last_index = -1
117
+ for time_idx, time in enumerate(trajectory.times):
118
+ # Do not skip starting point
119
+ if time < last_time + min_time_delta_seconds and time_idx != 0:
120
+ continue
121
+ time_rescaled_trajectory.joint_positions.append(
122
+ trajectory.joint_positions[time_idx]
123
+ )
124
+ time_rescaled_trajectory.times.append(time)
125
+ time_rescaled_trajectory.locations.append(trajectory.locations[time_idx])
126
+ last_time += min_time_delta_seconds
127
+
128
+ # do not forget to add the last point if it was not added
129
+ # its the most noticeable point if removed
130
+ if last_index != len(trajectory.times):
131
+ time_rescaled_trajectory.joint_positions.append(trajectory.joint_positions[-1])
132
+ time_rescaled_trajectory.times.append(trajectory.times[-1])
133
+ time_rescaled_trajectory.locations.append(trajectory.locations[-1])
134
+ return time_rescaled_trajectory
135
+
136
+
137
+ def _reduce_pose_overlap(
138
+ poses: list[nova_api.models.Pose], min_pose_distance_millimeters=10.0
139
+ ) -> list[nova_api.models.Pose]:
140
+ if len(poses) < 2:
141
+ return poses
142
+ last_point = poses[0]
143
+
144
+ reduced_poses = [last_point]
145
+ for pose in poses[1:]:
146
+ distance = (
147
+ (pose.position.x - last_point.position.x) ** 2
148
+ + (pose.position.y - last_point.position.y) ** 2
149
+ + (pose.position.z - last_point.position.z) ** 2
150
+ ) ** 0.5
151
+ if distance >= min_pose_distance_millimeters:
152
+ reduced_poses.append(pose)
153
+ last_point = pose
154
+ return reduced_poses