Skip to content

Commit b754731

Browse files
docs: updated docs to reflect new changes to tutorial scripts
1 parent 13e3741 commit b754731

File tree

5 files changed

+115
-48
lines changed

5 files changed

+115
-48
lines changed

docs/developing.md

Lines changed: 84 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,91 @@
1-
# Sequence Diagram
1+
# Developer Documentation
22

3-
<body>
4-
<pre class="mermaid">
5-
sequenceDiagram
6-
participant User as User
7-
participant Client as onshape-robotics-toolkit.client
8-
participant Onshape as Onshape Server
9-
participant Robot as onshape-robotics-toolkit.robot
3+
This document provides an overview of how the onshape-robotics-toolkit library works internally and how different components interact with each other.
104

11-
User->>Client: Initialize Client with API Keys
12-
Client->>Onshape: Authenticate with Access Key & Secret Key
13-
Onshape-->>Client: Return Authentication Token
5+
## Architecture Overview
146

15-
User->>Client: Request Document Information (e.g., document URL)
16-
Client->>Onshape: Send GET request for Document Details
17-
Onshape-->>Client: Return Document Metadata (JSON)
18-
Client-->>User: Deliver Document Metadata
7+
The library is organized into several key components:
8+
- **Client**: Handles all communication with the Onshape API
9+
- **Robot**: Manages the robot model creation and URDF export
10+
- **Assembly**: Represents the CAD assembly structure
11+
- **Utilities**: Helper functions for various operations
1912

20-
User->>Client: Request CAD Assembly
21-
Client->>Onshape: Send GET request for Assembly Details
22-
Onshape-->>Client: Return Assembly Data (JSON)
23-
Client-->>User: Deliver Assembly Data
13+
## Workflow Overview
2414

25-
User->>Robot: Initiate URDF Export Workflow
26-
Robot-->>Onshape: Parse Assembly Data for URDF
27-
Robot-->>User: Deliver Robot model (URDF)
15+
### 1. Authentication and Connection
16+
The library first establishes a secure connection with Onshape:
17+
- Users provide API credentials (access key and secret key)
18+
- The Client component handles authentication and maintains the session
19+
- All subsequent API requests use this authenticated session
2820

29-
User->>User: Use URDF for Simulation or Control
21+
### 2. Document Access
22+
Once authenticated:
23+
- The library can access Onshape documents using either URLs or direct document IDs
24+
- Document metadata is retrieved to verify access and get necessary identifiers
25+
- Assembly information is cached to minimize API calls
3026

31-
</body>
27+
### 3. Assembly Processing
28+
The assembly processing workflow:
29+
1. Retrieves the full assembly structure from Onshape
30+
2. Parses the hierarchical relationship between components
31+
3. Identifies joints, mate connectors, and other relevant features
32+
4. Creates an internal representation of the robot structure
33+
34+
### 4. URDF Generation
35+
The URDF export process:
36+
1. Analyzes the assembly structure
37+
2. Maps Onshape constraints to URDF joints
38+
3. Exports geometry in specified formats
39+
4. Generates a complete URDF file with proper kinematics
40+
41+
## Sequence Diagram
42+
43+
The following sequence diagram illustrates the main interactions between components:
44+
45+
<pre class="mermaid">
46+
sequenceDiagram
47+
participant User as User
48+
participant Client as onshape-robotics-toolkit.client
49+
participant Onshape as Onshape Server
50+
participant Robot as onshape-robotics-toolkit.robot
51+
52+
User->>Client: Initialize Client with API Keys
53+
Client->>Onshape: Authenticate with Access Key & Secret Key
54+
Onshape-->>Client: Return Authentication Token
55+
56+
User->>Client: Request Document Information (e.g., document URL)
57+
Client->>Onshape: Send GET request for Document Details
58+
Onshape-->>Client: Return Document Metadata (JSON)
59+
Client-->>User: Deliver Document Metadata
60+
61+
User->>Client: Request CAD Assembly
62+
Client->>Onshape: Send GET request for Assembly Details
63+
Onshape-->>Client: Return Assembly Data (JSON)
64+
Client-->>User: Deliver Assembly Data
65+
66+
User->>Robot: Initiate URDF Export Workflow
67+
Robot-->>Onshape: Parse Assembly Data for URDF
68+
Robot-->>User: Deliver Robot model (URDF)
69+
70+
User->>User: Use URDF for Simulation or Control
71+
</pre>
72+
73+
## Key Classes and Their Roles
74+
75+
### Client Class
76+
- Manages API authentication
77+
- Handles all HTTP requests to Onshape
78+
- Implements rate limiting and error handling
79+
- Caches responses when appropriate
80+
81+
### Robot Class
82+
- Represents the complete robot model
83+
- Manages the conversion from CAD assembly to URDF
84+
- Handles coordinate transformations
85+
- Provides visualization utilities
86+
87+
### Assembly Class
88+
- Represents the CAD assembly structure
89+
- Maintains parent-child relationships
90+
- Tracks mate connections and constraints
91+
- Manages geometric transformations

docs/getting-started.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ Access to the Onshape API requires authentication using API keys. Follow these s
5757
Create a `.env` file in the root directory of your project to securely store your API keys:
5858

5959
```plaintext
60-
ACCESS_KEY = <your_access_key>
61-
SECRET_KEY = <your_secret_key>
60+
ONSHAPE_ACCESS_KEY = <your_access_key>
61+
ONSHAPE_SECRET_KEY = <your_secret_key>
6262
```
6363

6464
The `onshape-robotics-toolkit` library will automatically read these keys to authenticate your requests.

docs/tutorials/edit.md

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
In this tutorial, we’ll explore how to edit an Onshape CAD assembly by modifying its variables in the Variable Studio and exporting the resulting assembly to a URDF file using the `onshape-robotics-toolkit` Python library.
1+
In this tutorial, we'll explore how to edit an Onshape CAD assembly by modifying its variables in the Variable Studio and exporting the resulting assembly to a URDF file using the `onshape-robotics-toolkit` Python library.
2+
3+
> 💡 The complete source code for this tutorial can be found in [`examples/edit/main.py`](../../examples/edit/main.py).
24
35
<img src="bike-header.gif" alt="Bike Header" style="width: 100%;">
46

@@ -13,7 +15,7 @@ Before you begin, make sure you have:
1315
pip install onshape-robotics-toolkit
1416
```
1517
- **API Keys**: Set up your Onshape API keys in a `.env` file as outlined in the [Getting Started](../getting-started.md) guide.
16-
- **Access to the Onshape Document**: Use a CAD document with a Variable Studio. For this tutorial, well use the following example:
18+
- **Access to the Onshape Document**: Use a CAD document with a Variable Studio. For this tutorial, we'll use the following example:
1719
<a href="https://cad.onshape.com/documents/a1c1addf75444f54b504f25c/w/0d17b8ebb2a4c76be9fff3c7/e/a86aaf34d2f4353288df8812" target="_blank">Example CAD Document</a>.
1820

1921
---
@@ -25,11 +27,16 @@ Before you begin, make sure you have:
2527
Set up the Onshape API client for authentication and interaction:
2628

2729
```python
28-
import onshape_robotics_toolkit as osa
30+
from onshape_robotics_toolkit.connect import Client
31+
from onshape_robotics_toolkit.log import LOGGER, LogLevel
32+
33+
# Set up logging
34+
LOGGER.set_file_name("edit.log")
35+
LOGGER.set_stream_level(LogLevel.INFO)
2936

3037
# Initialize the client
31-
client = osa.Client(
32-
env="./.env"
38+
client = Client(
39+
env=".env"
3340
)
3441
```
3542

@@ -40,7 +47,9 @@ client = osa.Client(
4047
Use the CAD document URL to create a `Document` object and fetch its variables:
4148

4249
```python
43-
doc = osa.Document.from_url(
50+
from onshape_robotics_toolkit.models.document import Document
51+
52+
doc = Document.from_url(
4453
url="https://cad.onshape.com/documents/a1c1addf75444f54b504f25c/w/0d17b8ebb2a4c76be9fff3c7/e/a86aaf34d2f4353288df8812"
4554
)
4655

@@ -56,7 +65,7 @@ variables = client.get_variables(doc.did, doc.wid, elements["variables"].id)
5665
Edit the variables to adjust the CAD assembly dimensions. For example, modify the wheel diameter, wheel thickness, and fork angle:
5766

5867
```python
59-
variables["wheelDiameter"].expression = "300 mm"
68+
variables["wheelDiameter"].expression = "180 mm"
6069
variables["wheelThickness"].expression = "71 mm"
6170
variables["forkAngle"].expression = "20 deg"
6271

@@ -83,13 +92,12 @@ from onshape_robotics_toolkit.parse import (
8392
assembly = client.get_assembly(doc.did, doc.wtype, doc.wid, elements["assembly"].id)
8493

8594
# Extract components
86-
instances, occurrences, id_to_name_map = get_instances(assemblymax_depth=1)
95+
instances, occurrences, id_to_name_map = get_instances(assembly, max_depth=1)
8796

8897
subassemblies, rigid_subassemblies = get_subassemblies(assembly, client, instances)
8998
parts = get_parts(assembly, rigid_subassemblies, client, instances)
9099

91100
mates, relations = get_mates_and_relations(assembly, subassemblies, rigid_subassemblies, id_to_name_map, parts)
92-
93101
```
94102

95103
---
@@ -100,13 +108,12 @@ Generate a graph visualization of the assembly structure:
100108

101109
```python
102110
from onshape_robotics_toolkit.graph import create_graph
103-
from onshape_robotics_toolkit.urdf import get_robot
104-
from onshape_robotics_toolkit.models.robot import Robot
111+
from onshape_robotics_toolkit.robot import get_robot
105112

106-
# Create and save the assembly graph
113+
# Create and visualize the assembly graph
107114
graph, root_node = create_graph(occurrences=occurrences, instances=instances, parts=parts, mates=mates)
108-
109115
robot = get_robot(assembly, graph, root_node, parts, mates, relations, client, "test")
116+
robot.show_tree()
110117
robot.show_graph("bike.png")
111118
```
112119

@@ -121,7 +128,7 @@ This will save an image of the assembly graph (`bike.png`) in your current worki
121128
Convert the robot class into a URDF file for robotics applications:
122129

123130
```python
124-
robot.save("bike.urdf")
131+
robot.save()
125132
```
126133

127134
<img src="bike-urdf.gif" alt="Bike URDF" style="width: 100%;">

docs/tutorials/export.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Before you begin, ensure the following:
1515
pip install onshape-robotics-toolkit
1616
```
1717
- **API Keys**: Set up your Onshape API keys in a `.env` file. Refer to the [Getting Started](../getting-started.md) guide if needed.
18-
- **Document URL**: Have the URL of the Onshape assembly you want to export. For this example, well use a quadruped robot assembly.
18+
- **Document URL**: Have the URL of the Onshape assembly you want to export. For this example, we'll use a quadruped robot assembly.
1919

2020
---
2121

@@ -32,7 +32,7 @@ from onshape_robotics_toolkit.log import LOGGER, LogLevel
3232
LOGGER.set_file_name("quadruped.log")
3333
LOGGER.set_stream_level(LogLevel.INFO)
3434

35-
client = Client(env="./.env")
35+
client = Client(env=".env")
3636
```
3737

3838
The logger will save logs to `quadruped.log` and display logs at the `INFO` level in the console.
@@ -73,9 +73,9 @@ This will save the assembly details into a file named `quadruped.json` in the cu
7373

7474
---
7575

76-
### Step 4: Visualize the Assembly Graph
76+
### Step 4: Visualize the Assembly Graph (Optional)
7777

78-
Generate and save a graphical representation of the assemblys structure:
78+
Generate and save a graphical representation of the assembly's structure:
7979

8080
```python
8181
robot.show_graph(file_name="quadruped.png")
@@ -99,10 +99,10 @@ This saves the robot object to disk as a URDF file named `quadruped.robot`.
9999

100100
## Result
101101

102-
After running the script, youll find the following files in your working directory:
102+
After running the script, you'll find the following files in your working directory:
103103

104104
1. **Assembly JSON File** (`quadruped.json`): Contains the complete assembly details.
105105
2. **Assembly Graph** (`quadruped.png`): A visual representation of the assembly’s structure.
106106
3. **Robot URDF File** (`quadruped.urdf`): A URDF file for simulation.
107107

108-
These files can be used for further analysis, simulation, or into other workflows.
108+
These files can be used for further analysis, simulation, or integration into other workflows.

examples/export/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from onshape_robotics_toolkit.utilities.helpers import save_model_as_json
55

66
if __name__ == "__main__":
7-
LOGGER.set_file_name("ballbot.log")
7+
LOGGER.set_file_name("quadruped.log")
88
LOGGER.set_stream_level(LogLevel.INFO)
99
client = Client(env=".env")
1010

@@ -18,5 +18,5 @@
1818

1919
save_model_as_json(robot.assembly, "quadruped.json")
2020

21-
# robot.show_graph(file_name="quadruped.png")
21+
robot.show_graph(file_name="quadruped.png")
2222
robot.save()

0 commit comments

Comments
 (0)