|
1 | 1 | # Swift |
2 | 2 |
|
| 3 | +[](https://github.com/petercorke/robotics-toolbox-python) |
| 4 | +[](https://qcr.github.io) |
| 5 | + |
3 | 6 | [](https://badge.fury.io/py/swift-sim) |
4 | 7 | [](https://img.shields.io/pypi/pyversions/swift-sim) |
5 | 8 | [](https://opensource.org/licenses/MIT) |
6 | | -[](https://qcr.github.io) |
7 | 9 |
|
8 | 10 | Swift is a light-weight browser-based simulator built on top of the [Robotics Toolbox for Python](https://github.com/petercorke/robotics-toolbox-python). This simulator provides robotics-specific functionality for rapid prototyping of algorithms, research, and education. Built using Python and Javascript, Swift is cross-platform (Linux, MacOS, and Windows) while also leveraging the ubiquity and support of these languages. |
9 | 11 |
|
@@ -31,6 +33,17 @@ Otherwise, Swift can be install by |
31 | 33 | pip3 install swift-sim |
32 | 34 | ``` |
33 | 35 |
|
| 36 | +Available options are: |
| 37 | + |
| 38 | +- `nb` provides the ability for Swift to be embedded within a Jupyter Notebook |
| 39 | +- `vision` implements an RTC communication strategy allowing for visual feedback from Swift and allows Swift to be run on Google Colab |
| 40 | + |
| 41 | +Put the options in a comma-separated list like |
| 42 | + |
| 43 | +```shell script |
| 44 | +pip3 install swift-sim[optionlist] |
| 45 | +``` |
| 46 | + |
34 | 47 | ### From GitHub |
35 | 48 |
|
36 | 49 | To install the latest version from GitHub |
@@ -63,10 +76,12 @@ We will load a model of the Franka-Emika Panda robot and make it travel towards |
63 | 76 | import roboticstoolbox as rtb |
64 | 77 | import spatialmath as sm |
65 | 78 | import numpy as np |
| 79 | +from swift import Swift |
| 80 | + |
66 | 81 |
|
67 | 82 | # Make and instance of the Swift simulator and open it |
68 | | -env = rtb.backends.Swift() |
69 | | -env.launch() |
| 83 | +env = Swift() |
| 84 | +env.launch(realtime=True) |
70 | 85 |
|
71 | 86 | # Make a panda model and set its joint angles to the ready joint configuration |
72 | 87 | panda = rtb.models.Panda() |
@@ -94,3 +109,41 @@ while not arrived: |
94 | 109 | <p align="center"> |
95 | 110 | <img src="./.github/figures/panda.gif"> |
96 | 111 | </p> |
| 112 | + |
| 113 | +### Embed within a Jupyter Notebook |
| 114 | +To embed within a Jupyter Notebook Cell, use the `browser="notebook"` option when launching the simulator. |
| 115 | + |
| 116 | +```python |
| 117 | +# Try this example within a Jupyter Notebook Cell! |
| 118 | +import roboticstoolbox as rtb |
| 119 | +import spatialmath as sm |
| 120 | +import numpy as np |
| 121 | +from swift import Swift |
| 122 | + |
| 123 | +# Make and instance of the Swift simulator and open it |
| 124 | +env = Swift() |
| 125 | +env.launch(realtime=True, browser="notebook") |
| 126 | + |
| 127 | +# Make a panda model and set its joint angles to the ready joint configuration |
| 128 | +panda = rtb.models.Panda() |
| 129 | +panda.q = panda.qr |
| 130 | + |
| 131 | +# Set a desired and effector pose an an offset from the current end-effector pose |
| 132 | +Tep = panda.fkine(panda.q) * sm.SE3.Tx(0.2) * sm.SE3.Ty(0.2) * sm.SE3.Tz(0.45) |
| 133 | + |
| 134 | +# Add the robot to the simulator |
| 135 | +env.add(panda) |
| 136 | + |
| 137 | +# Simulate the robot while it has not arrived at the goal |
| 138 | +arrived = False |
| 139 | +while not arrived: |
| 140 | + |
| 141 | + # Work out the required end-effector velocity to go towards the goal |
| 142 | + v, arrived = rtb.p_servo(panda.fkine(panda.q), Tep, 1) |
| 143 | + |
| 144 | + # Set the Panda's joint velocities |
| 145 | + panda.qd = np.linalg.pinv(panda.jacobe(panda.q)) @ v |
| 146 | + |
| 147 | + # Step the simulator by 50 milliseconds |
| 148 | + env.step(0.05) |
| 149 | +``` |
0 commit comments