|
5 | 5 | ```python
|
6 | 6 | from navability.entities import *
|
7 | 7 | from navability.services import *
|
8 |
| -import asyncio |
9 | 8 | from uuid import uuid4
|
10 | 9 | import numpy as np
|
| 10 | +# import asyncio |
11 | 11 |
|
12 | 12 |
|
13 | 13 | userLabel = "guest@navability.io"
|
14 | 14 | robotLabel = "TestRobot"
|
15 | 15 | sessionLabel = "TestHex"
|
16 |
| -fgclient = DFGClient(userLabel, robotLabel, sessionLabel) |
17 | 16 |
|
18 |
| -variables = await listVariablesAsync(fgclient) |
| 17 | +# for private (non-guest) use, get a token after login at app.navability.io, Connect page. |
| 18 | +auth_token = '' |
19 | 19 |
|
20 |
| -entries = await listBlobEntriesAsync(fgclient, "x1") |
| 20 | +fgclient = DFGClient(userLabel, robotLabel, sessionLabel, auth_token=auth_token) |
21 | 21 |
|
22 |
| -``` |
23 |
| - |
24 |
| -## Legacy Example |
25 |
| - |
26 |
| -This script will create variables and factors, list the graph, and solve the session for SLAM estimates. |
27 |
| - |
28 |
| -> NOTES: |
29 |
| -> * You'll need to start Python using `python -m asyncio` to support the `await` command. |
30 |
| -> * You'll need numpy to run the example. |
31 |
| -
|
32 |
| -```python |
33 |
| -from uuid import uuid4 |
34 |
| -import numpy as np |
35 |
| -import json |
36 |
| -from navability.entities import ( |
37 |
| - Client, |
38 |
| - Factor, |
39 |
| - FactorData, |
40 |
| - FullNormal, |
41 |
| - NavAbilityHttpsClient, |
42 |
| - Pose2Pose2, |
43 |
| - PriorPose2, |
44 |
| - Variable, |
45 |
| - VariableType, |
46 |
| -) |
47 |
| -from navability.services import ( |
48 |
| - addFactor, |
49 |
| - addVariable, |
50 |
| - solveSession, |
51 |
| - ls, |
52 |
| - lsf, |
53 |
| - waitForCompletion, |
54 |
| - getVariable |
55 |
| -) |
| 22 | +variables = listVariables(fgclient) |
| 23 | +# variables = await listVariablesAsync(fgclient) |
56 | 24 |
|
57 |
| -navability_client = NavAbilityHttpsClient() |
58 |
| -client = Client("Guest", "MyUser", "Session_" + str(uuid4())[0:8]) |
| 25 | +# get one of the variables from the graph |
| 26 | +x1 = getVariable(fgclient, 'x1') |
| 27 | +# xl1 = await getVariableAsync(fgclient, 'x1') |
| 28 | +print('The tags on this variable are', x1.tags) |
59 | 29 |
|
60 |
| -# Create variables x0, x1, and x2 |
61 |
| -variables = [ |
62 |
| - Variable("x0", VariableType.Pose2.value), |
63 |
| - Variable("x1", VariableType.Pose2.value), |
64 |
| - Variable("x2", VariableType.Pose2.value), |
65 |
| -] |
| 30 | +# which blob entries (list of labels) are there on this variable |
| 31 | +be_labels = listBlobEntries(fgclient, "x1") |
| 32 | +# be_labels = await listBlobEntriesAsync(fgclient, "x1") |
66 | 33 |
|
67 |
| -# Create factors between them |
68 |
| -factors = [ |
69 |
| - Factor( |
70 |
| - "x0f1", |
71 |
| - "PriorPose2", |
72 |
| - ["x0"], |
73 |
| - FactorData( |
74 |
| - fnc=PriorPose2( |
75 |
| - Z=FullNormal(mu=np.zeros(3), cov=np.diag([0.1, 0.1, 0.1])) |
76 |
| - ).dump() # This is a generator for a PriorPose2 |
77 |
| - ), |
78 |
| - ), |
79 |
| - Factor( |
80 |
| - "x0x1f1", |
81 |
| - "Pose2Pose2", |
82 |
| - ["x0", "x1"], |
83 |
| - FactorData( |
84 |
| - fnc=Pose2Pose2( |
85 |
| - Z=FullNormal( |
86 |
| - mu=[1, 1, np.pi / 3], cov=np.diag([0.1, 0.1, 0.1]) |
87 |
| - ) |
88 |
| - ).dump() # This is a generator for a PriorPose2 |
89 |
| - ), |
90 |
| - ), |
91 |
| - Factor( |
92 |
| - "x1x2f1", |
93 |
| - "Pose2Pose2", |
94 |
| - ["x1", "x2"], |
95 |
| - FactorData( |
96 |
| - fnc=Pose2Pose2( |
97 |
| - Z=FullNormal( |
98 |
| - mu=[1, 1, np.pi / 3], cov=np.diag([0.1, 0.1, 0.1]) |
99 |
| - ) |
100 |
| - ).dump() # This is a generator for a PriorPose2 |
101 |
| - ), |
102 |
| - ), |
103 |
| - ] |
| 34 | +# fetch fetch one of the blob entries (note not the blob itself yet) |
| 35 | +entry = getBlobEntry(fgclient, "x1", be_labels[0]) |
104 | 36 |
|
105 |
| -# Get the result IDs so we can check on their completion |
106 |
| -print("Adding variables and factors..\r\n") |
107 |
| -variable_results = [await addVariable(navability_client, client, v) for v in variables] |
108 |
| -factor_results = [await addFactor(navability_client, client, f) for f in factors] |
109 |
| -result_ids = variable_results + factor_results |
| 37 | +## fetch binary data blob from one of the blobstores |
| 38 | +store = NavAbilityBlobStore(fgclient.client, userLabel) |
| 39 | +blob = getBlob(store, str(entry.blobId)) |
| 40 | +# blob = await getBlobAsync(store, entry.id) |
110 | 41 |
|
111 |
| -# Wait for them to be inserted if they havent already |
112 |
| -print("Waiting for them to be loaded..\r\n") |
113 |
| -await waitForCompletion(navability_client, result_ids, maxSeconds=120) |
| 42 | +## which neighbors does this variable have |
| 43 | +x1_nei = listNeighbors(fgclient, 'x1') |
114 | 44 |
|
115 |
| -# Interrogate the graph |
116 |
| -# Get the variables |
117 |
| -print("Listing all the variables and factors in the session:\r\n") |
118 |
| -vs = await ls(navability_client, client) |
119 |
| -print("Variables: " + json.dumps(vs, indent=4, sort_keys=True)) |
120 |
| -# Get the factors |
121 |
| -fs = await lsf(navability_client, client) |
122 |
| -print("Factors: " + json.dumps(fs, indent=4, sort_keys=True)) |
123 |
| -# There's some pretty neat functionality with searching, but we'll save that for more comprehensive tutorials |
| 45 | +## which factors are there |
| 46 | +fcts = listFactors(fgclient) |
124 | 47 |
|
125 |
| -# Request a SLAM multimodal solve and wait for the response |
126 |
| -# Note: Guest sessions solve a little slower than usual because they're using some small hardware we put down for community use. Feel free to reach out if you want faster solving. |
127 |
| -print("Requesting that the graph be solved to determine the positions of the variables (poses)...") |
128 |
| -request_id = await solveSession(navability_client, client) |
129 |
| -await waitForCompletion(navability_client, [request_id], maxSeconds=120) |
130 |
| - |
131 |
| -# Get the solves positions of the variables (these are stores in the PPEs structure) |
132 |
| -print("Getting the estimates of the variables (poses)...") |
133 |
| -estimates = {v.label: (await getVariable(navability_client, client, v.label)).ppes['default'].suggested for v in variables} |
134 |
| -print("Solved estimates for the positions:\r\n") |
135 |
| -print(json.dumps(estimates, indent=4, sort_keys=True)) |
136 |
| -``` |
| 48 | +## get a specific factor |
| 49 | +fc = getFactor(fgclient, 'x1x2f1') |
| 50 | +``` |
0 commit comments