Skip to content

Commit da2de90

Browse files
committed
clean up factors and solving
1 parent f708cbb commit da2de90

File tree

5 files changed

+50
-40
lines changed

5 files changed

+50
-40
lines changed

docs/_toc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ parts:
1414
- caption: Add to Graph 🕶️
1515
chapters:
1616
- file: buildgraph
17-
- caption: Graph Solvers
17+
- caption: Solving Graphs
1818
chapters:
1919
- file: solvers
2020
- caption: Tutorials

docs/buildgraph.md

Lines changed: 42 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -4,61 +4,67 @@ The NavAbilitySDK provides variables and factors useful to robotics. We start w
44

55
As before, let's setup a new client-context to talk with the NavAbility platform:
66
```python
7+
from navability.entities import DFGClient, VariableType, PriorPose2, FullNormal
8+
from navability.services import addVariable, ls, addFactor, lsf
9+
import uuid, random, string
10+
11+
userLabel = "guest@navability.io"
12+
robotLabel = "TestRobot"
13+
sessionLabel = "TestPy"
14+
715
# also create a client connection
8-
client = NavAbilityHttpsClient()
9-
10-
# create a client context user, robot, session
11-
context = Client(
12-
"guest@navability.io",
13-
"ExampleRobot",
14-
"SDKpy_"*(string(uuid4())[1:4]),
15-
)
16+
fgclient = DFGClient(userLabel, robotLabel, sessionLabel)
1617
```
1718

18-
## First Pose
19+
## Adding Variables
20+
21+
:::{warning}
22+
SDK.py@v0.6.0 currently does not support creating new sessions from "guest", but variables and factors can be added to an existing session.
23+
:::
1924

20-
The `addVariable` function with a label `"x0"` and type `:Pose2` adds that variable to to the factor graph.
25+
Let's start with `addVariable`
26+
```{eval-rst}
27+
.. autofunction:: navability.services.addVariable
28+
```
2129

30+
by adding a randomly named variable an existing graph. Here we call `addVariable` as type `VariableTypes.Pose2`. Pose2 here refers to position an orientation on a flat 2D plane -- i.e. the variable represents the estimation problem to find the state of variable with freedoms `[x,y,theta]`:
2231
```python
23-
result_v0 = await addVariable(client, context, "x0", VariableType.Pose2)
32+
# generate a random variable label
33+
vlabel = 'x_'+''.join(random.choices(string.ascii_letters + string.digits, k=4))
34+
35+
# add the variable to the existing session under guest
36+
v = addVariable(fgclient, vlabel, VariableType.Pose2)
37+
# result_v0 = await addVariable(fgclient, "x0", VariableType.Pose2)
2438
```
2539

26-
Note that asynchronous tasks are used to increase the upload performance. Each of these events are queued on the server for processing. While the variable is being created, let's also add a prior factor.
40+
:::{tip}
41+
Note that asynchronous tasks could increase client side upload performance. Each of these events are queued on the server for processing. While the variable is being created.
42+
:::
43+
44+
## Adding Factors
45+
46+
Next, we can also add a factor. Have a look at the `addFactor` function followed by how a user defines the factor measurement and observation model in the next section.
2747

2848
```{eval-rst}
29-
.. autofunction:: navability.services.addVariable
49+
.. autofunction:: navability.services.addFactor
3050
```
3151

32-
### And Zero-Prior
52+
### A Zero-Prior
3353

34-
We now have a factor graph with one variable, but to solve it we need some additional information. In this example, we need the estimated starting point of our robot.
54+
Let's first add a Prior. Priors are absolute information about variables.
55+
:::{tip}
56+
NavAbility factor graph solutions at this time require a gauge to exist for the graph being solved, hence enough prior information must be included in the graph to constrain the solution (bundles/orbits/locii) to a single solution. **Note** that this does not imply solutions are necessarily unimodal (Gaussian).
57+
:::
58+
59+
In this example, we'll use the estimated starting point of our robot.
3560
We use unary factors called priors to represent absolute information to be introduced. In this case we use `PriorPose2`, as our variable type is also `Pose2`.
3661
Since factors represent a probabilistic interaction between variables, we need to specify the distribution our factor will represent. Here we use `FullNormal` which is a [multivariate normal distribution](https://en.wikipedia.org/wiki/Multivariate_normal_distribution).
3762

3863
Let's create a `PriorPose2` unary factor with zero mean and a covariance matrix of (`diagm([0.05,0.05,0.01].^2)`):
3964
```python
4065
prior_distribution = FullNormal(mu=np.zeros(3), cov=np.power(np.diag([0.1, 0.1, 0.1]),2))
41-
result_f0 = await addFactor(client, context, ["x0"], PriorPose2(Z=prior_distribution))
42-
```
43-
44-
After adding a batch of variables and factors, we can wait on the upload status to ensure the new graph elements have been processed:
45-
```python
46-
# Wait for variable and factor to be loaded to be loaded.
47-
await waitForCompletion(client, [result_v0, result_f0])
48-
```
49-
50-
As before, we can use the NavAbility App to visualize the factor graph
51-
```python
52-
# Click on the generated URL or graphic to open the NavAbility App Graph visualization page for this session
53-
GraphVizApp(context, variableStartsWith="")
54-
```
55-
56-
<!-- ```{eval-rst}
57-
.. automodule:: navability.services
58-
:members: addVariable
59-
``` -->
60-
```{eval-rst}
61-
.. autofunction:: navability.services.addFactor
66+
result_f0 = addFactor(fgclient, ["x0"], PriorPose2(Z=prior_distribution))
67+
result_f0 = await addFactorAsync(fgclient, ["x0"], PriorPose2(Z=prior_distribution))
6268
```
6369

6470
## Odometry Factor

docs/nvatutorials.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# NavAbility Tutorials
22

33
These Tutorials can be read as static pages or be run live via Binder. Either of the options below should work.
4-
## Run Via NavAbility App
4+
<!-- ## Run Via NavAbility App
55
66
A free tier access to NavAbility servers is provided through the user `guest@navability.io`. To learn more about using the guest user, consider trying the [NavAbility Tutorials](https://app.navability.io/get-started/tutorials).
77
88
<a href="https://app.navability.io/get-started/tutorials"><p align="center">
99
<img src="https://user-images.githubusercontent.com/6412556/218645925-4fa31c70-8c93-49d8-a43d-f18ffde5e28f.png" width="480px" border="0" />
1010
</p></a>
1111
12-
Including SDK.jl version of Tutorial 5 not yet available in JupyterBook links below.
12+
Including SDK.jl version of Tutorial 5 not yet available in JupyterBook links below. -->
1313

1414
## Run Via Jupyter Book
1515

docs/solvers.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Non parametric solving can support a much wider range of measurement probability
2424
- as well as multihypothesis features per factor -- i.e. `Categorical`.
2525

2626
Many more probability types are natively supported by the solver and yet directly exposed through the SDK, including
27-
- Manifold Kernel Densities,
27+
- `ManifoldKernelDensities`,
2828
- Heatmaps or Intensity maps,
2929
- Levelsets,
3030
- Most common parametric probability models.

docs/variables.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ Returns `["l1","x0","x1","x2","x3","x4","x5","x6"]`. The `await ... Async` vers
3737
.. autofunction:: navability.services.listVariablesAsync
3838
```
3939

40+
:::{tip}
41+
There is a handy alias familiar to Linux, `ls = listVariables`, e.g. `ls(fgclient)` returns all the variables in the graph.
42+
:::
43+
4044
### Getting a Variable
4145

4246
The main purpose of using a factor graph is not only as data index but also to deeply connect with the mapping and localization problem. Variables in the factor graph represent the states to be estimated from the relevant measurement data. The numerical values for each variable are computed by any number of solver operations. The numerical results are primarily stored in a variables `solverData` field, such that either parametric or non-parametric inference results can be used:

0 commit comments

Comments
 (0)