|
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", |
| 28 | + "from ipymovehub.movehub import MoveHubLaneProxy\n", |
29 | 29 | "\n", |
30 | 30 | "# the robot's LED supports the following colors\n", |
31 | 31 | "colors = [\n", |
32 | | - "\n", |
33 | 32 | " LedColor.pink,\n", |
34 | 33 | " LedColor.purple,\n", |
35 | 34 | " LedColor.blue,\n", |
|
58 | 57 | "metadata": { |
59 | 58 | "scrolled": true |
60 | 59 | }, |
61 | | - "outputs": [ |
62 | | - { |
63 | | - "data": { |
64 | | - "application/vnd.jupyter.widget-view+json": { |
65 | | - "model_id": "a58eafee0b6946458034ba2966c7d767", |
66 | | - "version_major": 2, |
67 | | - "version_minor": 0 |
68 | | - }, |
69 | | - "text/plain": [ |
70 | | - "MoveHubWidget(n_lanes=4)" |
71 | | - ] |
72 | | - }, |
73 | | - "metadata": {}, |
74 | | - "output_type": "display_data" |
75 | | - } |
76 | | - ], |
| 60 | + "outputs": [], |
77 | 61 | "source": [ |
78 | 62 | "# number of concurrent \"lanes\"\n", |
79 | 63 | "n_lanes = 4\n", |
80 | 64 | "widget = MoveHubWidget(n_lanes=n_lanes)\n", |
81 | | - "output = Output()\n", |
82 | 65 | "display(widget)" |
83 | 66 | ] |
84 | 67 | }, |
85 | 68 | { |
86 | 69 | "cell_type": "code", |
87 | | - "execution_count": 8, |
| 70 | + "execution_count": null, |
88 | 71 | "id": "9b5f6086-3605-47ee-a170-57d3b97600e2", |
89 | 72 | "metadata": {}, |
90 | 73 | "outputs": [], |
91 | 74 | "source": [ |
92 | 75 | "# Case 1 : Execute this cell if there is no MoveHub connected\n", |
93 | | - "widget.connect(output=output)" |
| 76 | + "widget.connect()" |
94 | 77 | ] |
95 | 78 | }, |
96 | 79 | { |
97 | 80 | "cell_type": "code", |
98 | | - "execution_count": 9, |
| 81 | + "execution_count": null, |
99 | 82 | "id": "514c7c39-8b62-4caa-a506-4abb79891592", |
100 | 83 | "metadata": {}, |
101 | 84 | "outputs": [], |
102 | 85 | "source": [ |
103 | 86 | "# Case 2 : Execute this cell if there is/are one/some MoveHub(s) connected\n", |
104 | 87 | "# Choose one of them and paste its identifier\n", |
105 | 88 | "widget.identifier = \"dcRIlxx9l8bQ3T6UVofW8Q==\"\n", |
106 | | - "widget.connect(output=output, identifier=widget.identifier)" |
| 89 | + "widget.connect(identifier=widget.identifier)" |
107 | 90 | ] |
108 | 91 | }, |
109 | 92 | { |
110 | 93 | "cell_type": "code", |
111 | | - "execution_count": 10, |
| 94 | + "execution_count": null, |
112 | 95 | "id": "e2b06dac-4056-435f-800a-60134c48c27e", |
113 | 96 | "metadata": {}, |
114 | | - "outputs": [ |
115 | | - { |
116 | | - "data": { |
117 | | - "application/vnd.jupyter.widget-view+json": { |
118 | | - "model_id": "a58eafee0b6946458034ba2966c7d767", |
119 | | - "version_major": 2, |
120 | | - "version_minor": 0 |
121 | | - }, |
122 | | - "text/plain": [ |
123 | | - "MoveHubWidget(identifier='dcRIlxx9l8bQ3T6UVofW8Q==', n_lanes=4)" |
124 | | - ] |
125 | | - }, |
126 | | - "metadata": {}, |
127 | | - "output_type": "display_data" |
128 | | - } |
129 | | - ], |
| 97 | + "outputs": [], |
130 | 98 | "source": [ |
131 | 99 | "display(widget)" |
132 | 100 | ] |
|
141 | 109 | }, |
142 | 110 | { |
143 | 111 | "cell_type": "code", |
144 | | - "execution_count": 11, |
| 112 | + "execution_count": null, |
145 | 113 | "id": "62924267-c398-4274-8780-91739cdacafe", |
146 | 114 | "metadata": { |
147 | 115 | "scrolled": true |
148 | 116 | }, |
149 | 117 | "outputs": [], |
150 | 118 | "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);" |
| 119 | + "lane_proxy = MoveHubLaneProxy (movehub = widget, lane = 0, identifier = widget.identifier)\n", |
| 120 | + "for color in colors:\n", |
| 121 | + " print(color)\n", |
| 122 | + " #log(f\"set color to {color.value}\")\n", |
| 123 | + " await lane_proxy.set_led_async(color)\n", |
| 124 | + " await asyncio.sleep(2)" |
161 | 125 | ] |
162 | 126 | }, |
163 | 127 | { |
|
178 | 142 | "speed = 50\n", |
179 | 143 | "d_forward = 200\n", |
180 | 144 | "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 | 145 | "\n", |
189 | | - "widget.run_async_program(main, output=output);\n", |
190 | | - "output" |
| 146 | + "for i in range(4):\n", |
| 147 | + " await lane_proxy.set_led_async(\"red\")\n", |
| 148 | + " await lane_proxy.motor_angle_multi_async(angle=d_forward, power_a=speed,power_b=speed)\n", |
| 149 | + " await lane_proxy.set_led_async(\"green\")\n", |
| 150 | + " await lane_proxy.motor_angle_multi_async(angle=d_rotate, power_a=speed,power_b=-1.0*speed)" |
191 | 151 | ] |
192 | | - }, |
193 | | - { |
194 | | - "cell_type": "code", |
195 | | - "execution_count": null, |
196 | | - "id": "86ec19bd-f82c-4181-819b-f862932610f2", |
197 | | - "metadata": {}, |
198 | | - "outputs": [], |
199 | | - "source": [] |
200 | 152 | } |
201 | 153 | ], |
202 | 154 | "metadata": { |
|
0 commit comments