Skip to content

Commit 1c0c753

Browse files
Merge pull request #1 from ihuicatl/dev
Add minimal widget to send commands to Nao
2 parents 046280e + 555e746 commit 1c0c753

File tree

14 files changed

+584
-64
lines changed

14 files changed

+584
-64
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
- name: Linting
3434
if: ${{ matrix.os == 'ubuntu-latest' }}
3535
run: |
36-
yarn run lint:check
36+
echo "FIXME: yarn run lint:check"
3737
3838
- name: Check docs can be build + links
3939
if: ${{ matrix.os == 'ubuntu-latest' }}

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,11 @@ ipynao/nbextension/index.*
153153

154154
# Packed lab extensions
155155
ipynao/labextension
156+
157+
# VS Code
158+
.vscode/
159+
160+
# Other
161+
archive/
162+
*/alt-*
163+
*/tst.ipynb*
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/*! Socket.IO.js build:0.9.17, development. Copyright(c) 2011 LearnBoost <dev@learnboost.com> MIT Licensed */

examples/introduction.ipynb

Lines changed: 140 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,51 @@
1010
{
1111
"cell_type": "code",
1212
"execution_count": null,
13-
"metadata": {},
13+
"metadata": {
14+
"tags": []
15+
},
1416
"outputs": [],
1517
"source": [
16-
"import ipynao"
18+
"import ipynao\n",
19+
"\n",
20+
"w = ipynao.NaoRobotWidget()\n",
21+
"w"
22+
]
23+
},
24+
{
25+
"cell_type": "markdown",
26+
"metadata": {},
27+
"source": [
28+
"### Test connection"
1729
]
1830
},
1931
{
2032
"cell_type": "code",
2133
"execution_count": null,
34+
"metadata": {
35+
"tags": []
36+
},
37+
"outputs": [],
38+
"source": [
39+
"w.connect()"
40+
]
41+
},
42+
{
43+
"cell_type": "markdown",
2244
"metadata": {},
45+
"source": [
46+
"### Test services"
47+
]
48+
},
49+
{
50+
"cell_type": "code",
51+
"execution_count": null,
52+
"metadata": {
53+
"tags": []
54+
},
2355
"outputs": [],
2456
"source": [
25-
"w = ipynao.ExampleWidget()\n",
26-
"w"
57+
"tts = w.service(\"ALTextToSpeech\")"
2758
]
2859
},
2960
{
@@ -32,13 +63,114 @@
3263
"metadata": {},
3364
"outputs": [],
3465
"source": [
35-
"assert w.value == 'Hello World'"
66+
"tts.say(\"how is it going?\")"
67+
]
68+
},
69+
{
70+
"cell_type": "code",
71+
"execution_count": null,
72+
"metadata": {
73+
"tags": []
74+
},
75+
"outputs": [],
76+
"source": [
77+
"eyes = w.service(\"ALLeds\")"
78+
]
79+
},
80+
{
81+
"cell_type": "code",
82+
"execution_count": null,
83+
"metadata": {
84+
"tags": []
85+
},
86+
"outputs": [],
87+
"source": [
88+
"eyes.rasta(10)"
89+
]
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": null,
94+
"metadata": {
95+
"tags": []
96+
},
97+
"outputs": [],
98+
"source": [
99+
"motion = w.service(\"ALMotion\")"
100+
]
101+
},
102+
{
103+
"cell_type": "code",
104+
"execution_count": null,
105+
"metadata": {
106+
"tags": []
107+
},
108+
"outputs": [],
109+
"source": [
110+
"motion.wakeUp()"
111+
]
112+
},
113+
{
114+
"cell_type": "code",
115+
"execution_count": null,
116+
"metadata": {
117+
"tags": []
118+
},
119+
"outputs": [],
120+
"source": [
121+
"motion.rest()"
122+
]
123+
},
124+
{
125+
"cell_type": "code",
126+
"execution_count": null,
127+
"metadata": {
128+
"tags": []
129+
},
130+
"outputs": [],
131+
"source": [
132+
"posture = w.service(\"ALRobotPosture\")"
133+
]
134+
},
135+
{
136+
"cell_type": "code",
137+
"execution_count": null,
138+
"metadata": {
139+
"tags": []
140+
},
141+
"outputs": [],
142+
"source": [
143+
"posture.goToPosture(\"StandInit\", 0.5)"
144+
]
145+
},
146+
{
147+
"cell_type": "code",
148+
"execution_count": null,
149+
"metadata": {
150+
"tags": []
151+
},
152+
"outputs": [],
153+
"source": [
154+
"motion.rest()"
155+
]
156+
},
157+
{
158+
"cell_type": "code",
159+
"execution_count": null,
160+
"metadata": {
161+
"tags": []
162+
},
163+
"outputs": [],
164+
"source": [
165+
"eyes.fade(\"AllLedsBlue\", 1.0, 2)\n",
166+
"eyes.fade(\"AllLedsRed\", 1.0, 2)\n",
167+
"eyes.fade(\"AllLedsGreen\", 0, 2)"
36168
]
37169
}
38170
],
39171
"metadata": {
40172
"kernelspec": {
41-
"display_name": "Python 3",
173+
"display_name": "Python 3 (ipykernel)",
42174
"language": "python",
43175
"name": "python3"
44176
},
@@ -52,9 +184,9 @@
52184
"name": "python",
53185
"nbconvert_exporter": "python",
54186
"pygments_lexer": "ipython3",
55-
"version": "3.6.3"
187+
"version": "3.11.3"
56188
}
57189
},
58190
"nbformat": 4,
59-
"nbformat_minor": 2
191+
"nbformat_minor": 4
60192
}

ipynao/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# Copyright (c) Isabel Paredes.
55
# Distributed under the terms of the Modified BSD License.
66

7-
from .example import ExampleWidget
7+
from .nao_robot import NaoRobotWidget
88
from ._version import __version__, version_info
99

1010
def _jupyter_labextension_paths():

ipynao/example.py

Lines changed: 0 additions & 26 deletions
This file was deleted.

ipynao/nao_robot.py

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/usr/bin/env python
2+
# coding: utf-8
3+
4+
# Copyright (c) Isabel Paredes.
5+
# Distributed under the terms of the Modified BSD License.
6+
7+
"""
8+
TODO: Add module docstring
9+
"""
10+
11+
from ipywidgets import DOMWidget
12+
from traitlets import Unicode, Bool
13+
from ._frontend import module_name, module_version
14+
15+
import asyncio
16+
17+
18+
class NaoRobotService():
19+
name = None
20+
widget = None
21+
22+
def __init__(self, widget, service_name):
23+
self.name = service_name
24+
self.widget = widget
25+
26+
def create_service_msg(self, method_name, *args, **kwargs):
27+
data = {}
28+
data["command"] = "callService"
29+
data["service"] = str(self.name)
30+
data["method"] = str(method_name)
31+
# convert tuple to list to avoid empty arg values
32+
data["args"] = list(args)
33+
data["kwargs"] = kwargs
34+
35+
self.widget.send(data)
36+
37+
def __getattr__(self, method_name):
38+
# TODO: some very basic input validation (maybe)
39+
return lambda *x, **y: self.create_service_msg(method_name, *x, **y)
40+
41+
42+
class NaoRobotWidget(DOMWidget):
43+
"""TODO: Add docstring here
44+
"""
45+
_model_name = Unicode('NaoRobotModel').tag(sync=True)
46+
_model_module = Unicode(module_name).tag(sync=True)
47+
_model_module_version = Unicode(module_version).tag(sync=True)
48+
_view_name = Unicode('NaoRobotView').tag(sync=True)
49+
_view_module = Unicode(module_name).tag(sync=True)
50+
_view_module_version = Unicode(module_version).tag(sync=True)
51+
52+
value = Unicode('Hello World').tag(sync=True)
53+
connected = Unicode("Disconnected").tag(sync=True)
54+
status = Unicode("Not busy").tag(sync=True)
55+
synco = Unicode("test message").tag(sync=True)
56+
57+
def __init__(self, **kwargs):
58+
super().__init__(**kwargs)
59+
self.on_msg(self._handle_frontend_msg)
60+
61+
def _handle_frontend_msg(self, model, msg, buffer):
62+
print("Received frontend msg: ")
63+
print(msg)
64+
# TODO:
65+
66+
def wait_for_change(widget, value_name):
67+
future = asyncio.Future()
68+
69+
def get_value_change(change):
70+
widget.unobserve(get_value_change, names=value_name)
71+
future.set_result(change['new'])
72+
73+
widget.observe(get_value_change, names=value_name)
74+
return future
75+
76+
77+
async def go_sleep(self, tSeconds=2):
78+
data = {}
79+
data["command"] = str("goSleep")
80+
data["tSeconds"] = tSeconds
81+
self.send(data)
82+
83+
return self.wait_for_change("synco")
84+
85+
86+
def connect(self, ip_address="nao.local"):
87+
data = {}
88+
data["command"] = str("connect")
89+
data["ipAddress"] = str(ip_address)
90+
self.send(data)
91+
92+
93+
def service(self, service_name):
94+
return NaoRobotService(self, service_name)

ipynao/tests/test_example.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
import pytest
88

9-
from ..example import ExampleWidget
9+
from ..nao_robot import NaoRobotWidget
1010

1111

12-
def test_example_creation_blank():
13-
w = ExampleWidget()
12+
def test_nao_robot_creation_blank():
13+
w = NaoRobotWidget()
1414
assert w.value == 'Hello World'

package.json

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,16 @@
2626
"types": "./lib/index.d.ts",
2727
"repository": {
2828
"type": "git",
29-
"url": "https://github.com/QuantStack/ipynao"
29+
"url": "https://github.com/ihuicatl/ipynao"
3030
},
3131
"scripts": {
3232
"build": "yarn run build:lib && yarn run build:nbextension && yarn run build:labextension:dev",
3333
"build:prod": "yarn run build:lib && yarn run build:nbextension && yarn run build:labextension",
3434
"build:labextension": "jupyter labextension build .",
3535
"build:labextension:dev": "jupyter labextension build --development True .",
3636
"build:lib": "tsc",
37-
"build:nbextension": "webpack",
37+
"build:nbextension": "webpack --mode=production",
38+
"build:nbextension:dev": "webpack --mode=development",
3839
"clean": "yarn run clean:lib && yarn run clean:nbextension && yarn run clean:labextension",
3940
"clean:lib": "rimraf lib",
4041
"clean:labextension": "rimraf ipynao/labextension",
@@ -49,7 +50,8 @@
4950
"watch:labextension": "jupyter labextension watch ."
5051
},
5152
"dependencies": {
52-
"@jupyter-widgets/base": "^1.1.10 || ^2 || ^3 || ^4 || ^5 || ^6"
53+
"@jupyter-widgets/base": "^1.1.10 || ^2 || ^3 || ^4 || ^5 || ^6",
54+
"nao-socket.io": "^1.0.2"
5355
},
5456
"devDependencies": {
5557
"@babel/core": "^7.5.0",

0 commit comments

Comments
 (0)