|
23 | 23 | "outputs": [], |
24 | 24 | "source": [ |
25 | 25 | "import asyncio\n", |
26 | | - "from jupyter_bluetooth_manager import MoveHubWidget,LedColor,Port, Sensor\n", |
27 | | - "from ipywidgets import Output\n", |
| 26 | + "from ipymovehub import MoveHubWidget, LedColor, Port, Sensor\n", |
28 | 27 | "from IPython.display import display\n", |
29 | 28 | "\n", |
30 | 29 | "# the robot's LED supports the following colors\n", |
31 | 30 | "colors = [\n", |
32 | | - "\n", |
33 | 31 | " LedColor.pink,\n", |
34 | 32 | " LedColor.purple,\n", |
35 | 33 | " LedColor.blue,\n", |
|
62 | 60 | { |
63 | 61 | "data": { |
64 | 62 | "application/vnd.jupyter.widget-view+json": { |
65 | | - "model_id": "a58eafee0b6946458034ba2966c7d767", |
| 63 | + "model_id": "5e916fd00a0542169e70cf4eb25f3aa9", |
66 | 64 | "version_major": 2, |
67 | 65 | "version_minor": 0 |
68 | 66 | }, |
|
78 | 76 | "# number of concurrent \"lanes\"\n", |
79 | 77 | "n_lanes = 4\n", |
80 | 78 | "widget = MoveHubWidget(n_lanes=n_lanes)\n", |
81 | | - "output = Output()\n", |
82 | 79 | "display(widget)" |
83 | 80 | ] |
84 | 81 | }, |
85 | 82 | { |
86 | 83 | "cell_type": "code", |
87 | | - "execution_count": 8, |
| 84 | + "execution_count": null, |
88 | 85 | "id": "9b5f6086-3605-47ee-a170-57d3b97600e2", |
89 | 86 | "metadata": {}, |
90 | 87 | "outputs": [], |
91 | 88 | "source": [ |
92 | 89 | "# Case 1 : Execute this cell if there is no MoveHub connected\n", |
93 | | - "widget.connect(output=output)" |
| 90 | + "widget.connect()" |
94 | 91 | ] |
95 | 92 | }, |
96 | 93 | { |
97 | 94 | "cell_type": "code", |
98 | | - "execution_count": 9, |
| 95 | + "execution_count": null, |
99 | 96 | "id": "514c7c39-8b62-4caa-a506-4abb79891592", |
100 | 97 | "metadata": {}, |
101 | 98 | "outputs": [], |
102 | 99 | "source": [ |
103 | 100 | "# Case 2 : Execute this cell if there is/are one/some MoveHub(s) connected\n", |
104 | 101 | "# Choose one of them and paste its identifier\n", |
105 | 102 | "widget.identifier = \"dcRIlxx9l8bQ3T6UVofW8Q==\"\n", |
106 | | - "widget.connect(output=output, identifier=widget.identifier)" |
| 103 | + "widget.connect(identifier=widget.identifier)" |
107 | 104 | ] |
108 | 105 | }, |
109 | 106 | { |
110 | 107 | "cell_type": "code", |
111 | | - "execution_count": 10, |
| 108 | + "execution_count": 6, |
112 | 109 | "id": "e2b06dac-4056-435f-800a-60134c48c27e", |
113 | 110 | "metadata": {}, |
114 | 111 | "outputs": [ |
115 | 112 | { |
116 | 113 | "data": { |
117 | 114 | "application/vnd.jupyter.widget-view+json": { |
118 | | - "model_id": "a58eafee0b6946458034ba2966c7d767", |
| 115 | + "model_id": "5e916fd00a0542169e70cf4eb25f3aa9", |
119 | 116 | "version_major": 2, |
120 | 117 | "version_minor": 0 |
121 | 118 | }, |
122 | 119 | "text/plain": [ |
123 | | - "MoveHubWidget(identifier='dcRIlxx9l8bQ3T6UVofW8Q==', n_lanes=4)" |
| 120 | + "MoveHubWidget(n_lanes=4)" |
124 | 121 | ] |
125 | 122 | }, |
126 | 123 | "metadata": {}, |
|
141 | 138 | }, |
142 | 139 | { |
143 | 140 | "cell_type": "code", |
144 | | - "execution_count": 11, |
| 141 | + "execution_count": null, |
145 | 142 | "id": "62924267-c398-4274-8780-91739cdacafe", |
146 | 143 | "metadata": { |
147 | 144 | "scrolled": true |
148 | 145 | }, |
149 | | - "outputs": [], |
| 146 | + "outputs": [ |
| 147 | + { |
| 148 | + "name": "stdout", |
| 149 | + "output_type": "stream", |
| 150 | + "text": [ |
| 151 | + "LedColor.pink\n" |
| 152 | + ] |
| 153 | + }, |
| 154 | + { |
| 155 | + "ename": "AttributeError", |
| 156 | + "evalue": "'int' object has no attribute 'set_led_async'", |
| 157 | + "output_type": "error", |
| 158 | + "traceback": [ |
| 159 | + "\u001b[31m---------------------------------------------------------------------------\u001b[39m", |
| 160 | + "\u001b[31mAttributeError\u001b[39m Traceback (most recent call last)", |
| 161 | + "\u001b[36mCell\u001b[39m\u001b[36m \u001b[39m\u001b[32mIn[14]\u001b[39m\u001b[32m, line 6\u001b[39m\n\u001b[32m 2\u001b[39m lane = widget.n_lanes\n\u001b[32m 3\u001b[39m \u001b[38;5;28;01mfor\u001b[39;00m color \u001b[38;5;28;01min\u001b[39;00m colors:\n\u001b[32m 4\u001b[39m print(color)\n\u001b[32m 5\u001b[39m \u001b[38;5;66;03m#log(f\"set color to {color.value}\")\u001b[39;00m\n\u001b[32m----> \u001b[39m\u001b[32m6\u001b[39m \u001b[38;5;28;01mawait\u001b[39;00m lane.set_led_async(color)\n\u001b[32m 7\u001b[39m \u001b[38;5;28;01mawait\u001b[39;00m asyncio.sleep(\u001b[32m2\u001b[39m)\n", |
| 162 | + "\u001b[31mAttributeError\u001b[39m: 'int' object has no attribute 'set_led_async'" |
| 163 | + ] |
| 164 | + } |
| 165 | + ], |
150 | 166 | "source": [ |
151 | | - "output = Output()\n", |
152 | | - "async def main(lane, log, identifier):\n", |
153 | | - "\n", |
154 | | - " for color in colors:\n", |
155 | | - " print(color)\n", |
156 | | - " log(f\"set color to {color.value}\")\n", |
157 | | - " await lane.set_led_async(color)\n", |
158 | | - " await asyncio.sleep(2)\n", |
159 | | - "\n", |
160 | | - "widget.run_async_program(main,output=output);" |
| 167 | + "lane_proxy = MoveHubLaneProxy (movehub = widget, lane = 0, identifier = widget.identifier)\n", |
| 168 | + "for color in colors:\n", |
| 169 | + " print(color)\n", |
| 170 | + " #log(f\"set color to {color.value}\")\n", |
| 171 | + " await lane_proxy.set_led_async(color)\n", |
| 172 | + " await asyncio.sleep(2)" |
161 | 173 | ] |
162 | 174 | }, |
163 | 175 | { |
|
178 | 190 | "speed = 50\n", |
179 | 191 | "d_forward = 200\n", |
180 | 192 | "d_rotate = 300\n", |
181 | | - "output = Output()\n", |
182 | | - "async def main(lane,log, identifier):\n", |
183 | | - " for i in range(4):\n", |
184 | | - " await lane.set_led_async(\"red\")\n", |
185 | | - " await lane.motor_angle_multi_async(angle=d_forward, power_a=speed,power_b=speed)\n", |
186 | | - " await lane.set_led_async(\"green\")\n", |
187 | | - " await lane.motor_angle_multi_async(angle=d_rotate, power_a=speed,power_b=-1.0*speed)\n", |
188 | 193 | "\n", |
189 | | - "widget.run_async_program(main, output=output);\n", |
190 | | - "output" |
| 194 | + "for i in range(4):\n", |
| 195 | + " await lane_proxy.set_led_async(\"red\")\n", |
| 196 | + " await lane_proxy.motor_angle_multi_async(angle=d_forward, power_a=speed,power_b=speed)\n", |
| 197 | + " await lane_proxy.set_led_async(\"green\")\n", |
| 198 | + " await lane_proxy.motor_angle_multi_async(angle=d_rotate, power_a=speed,power_b=-1.0*speed)" |
191 | 199 | ] |
192 | | - }, |
193 | | - { |
194 | | - "cell_type": "code", |
195 | | - "execution_count": null, |
196 | | - "id": "86ec19bd-f82c-4181-819b-f862932610f2", |
197 | | - "metadata": {}, |
198 | | - "outputs": [], |
199 | | - "source": [] |
200 | 200 | } |
201 | 201 | ], |
202 | 202 | "metadata": { |
|
0 commit comments