Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
Lego_Robots
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Matthew Baxter
Lego_Robots
Commits
52c1d877
Commit
52c1d877
authored
May 25, 2017
by
isaac.thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finished Python 3 changes, fixed existing commands. Also added new WeDo commands
parent
dcba4b6b
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
355 additions
and
13 deletions
+355
-13
listen.py
listen.py
+46
-7
snap-ev3.py
snap-ev3.py
+3
-2
snap-ev3.xml
snap-ev3.xml
+306
-4
No files found.
listen.py
View file @
52c1d877
from
__future__
import
print_function
from
http.server
import
BaseHTTPRequestHandler
,
HTTPServer
import
socketserver
import
socket
...
...
@@ -6,7 +7,8 @@ import sys
import
ev3dev.ev3
as
ev3
if
len
(
sys
.
argv
)
!=
2
:
print
>>
sys
.
stderr
,
'Syntax:
%
s <port>'
%
(
sys
.
argv
[
0
])
def
eprint
(
*
args
,
**
kwargs
):
print
(
*
args
,
file
=
sys
.
stderr
,
**
kwargs
)
sys
.
exit
(
1
)
class
Handler
(
BaseHTTPRequestHandler
):
...
...
@@ -18,7 +20,7 @@ class Handler(BaseHTTPRequestHandler):
return
f
=
open
(
'
%
s/mode'
%
dir
,
'w'
)
print
>>
f
,
mode
f
.
write
(
mode
)
f
.
close
()
self
.
color_sensor_mode
=
mode
...
...
@@ -27,8 +29,7 @@ class Handler(BaseHTTPRequestHandler):
self
.
send_response
(
200
)
self
.
send_header
(
'Content-Type'
,
'text/plain'
)
self
.
end_headers
()
self
.
wfile
.
write
(
reply
)
self
.
wfile
.
close
()
self
.
wfile
.
write
(
bytes
(
reply
,
'UTF-8'
))
def
find_sensor
(
self
,
driver_name
):
for
s
in
range
(
0
,
4
):
...
...
@@ -42,18 +43,25 @@ class Handler(BaseHTTPRequestHandler):
def
do_GET
(
self
):
parts
=
self
.
path
[
1
:]
.
split
(
'/'
)
print
(
parts
)
if
len
(
parts
)
==
4
and
parts
[
0
]
==
'motor'
:
if
len
(
parts
)
==
4
and
parts
[
0
]
==
'm
ediumm
otor'
:
print
(
'Run
%
s to
%
s at speed
%
s'
%
(
parts
[
1
],
parts
[
2
],
parts
[
3
]))
d
=
ev3
.
MediumMotor
(
'out'
+
parts
[
1
])
d
.
run_timed
(
time_sp
=
3000
,
speed_sp
=
500
)
d
.
run_timed
(
time_sp
=
int
(
parts
[
2
]),
speed_sp
=
int
(
parts
[
3
])
)
#d.run_position_limited(int(parts[2]), int(parts[3]), absolute=False)
self
.
respond
(
'OK'
)
elif
len
(
parts
)
==
4
and
parts
[
0
]
==
'largemotor'
:
print
(
'Run
%
s to
%
s at speed
%
s'
%
(
parts
[
1
],
parts
[
2
],
parts
[
3
]))
d
=
ev3
.
LargeMotor
(
'out'
+
parts
[
1
])
d
.
run_timed
(
time_sp
=
int
(
parts
[
2
]),
speed_sp
=
int
(
parts
[
3
]))
#d.run_position_limited(int(parts[2]), int(parts[3]), absolute=False)
self
.
respond
(
'OK'
)
elif
len
(
parts
)
==
2
and
parts
[
0
]
==
'say'
:
phrase
=
parts
[
1
]
phrase
=
phrase
.
replace
(
'
%20
'
,
' '
)
print
(
'Say
%
s'
%
phrase
)
os
.
system
(
'espeak -a 200 -s 130 -v en-sc --stdout "
%
s" | aplay'
%
phrase
)
self
.
respond
(
'OK'
)
self
.
respond
(
bytes
(
'OK'
,
'UTF-8'
)
)
elif
len
(
parts
)
==
2
and
parts
[
0
]
==
'ir-sensor'
and
parts
[
1
]
==
'proximity'
:
dir
=
self
.
find_sensor
(
'lego-ev3-ir'
)
f
=
open
(
'
%
s/value0'
%
dir
,
'r'
)
...
...
@@ -73,6 +81,37 @@ class Handler(BaseHTTPRequestHandler):
v
=
f
.
readline
()
.
strip
()
f
.
close
()
self
.
respond
(
v
)
elif
len
(
parts
)
==
3
and
parts
[
0
]
==
'mediumtimed'
:
print
(
'Run
%
s at speed
%
s'
%
(
parts
[
1
],
parts
[
2
]))
d
=
ev3
.
MediumMotor
(
'out'
+
parts
[
1
])
d
.
run_timed
(
time_sp
=
int
(
parts
[
2
]),
speed_sp
=
500
)
self
.
respond
(
'OK'
)
elif
len
(
parts
)
==
3
and
parts
[
0
]
==
'largetimed'
:
print
(
'Run
%
s at speed
%
s'
%
(
parts
[
1
],
parts
[
2
]))
d
=
ev3
.
LargeMotor
(
'out'
+
parts
[
1
])
d
.
run_timed
(
time_sp
=
int
(
parts
[
2
]),
speed_sp
=
500
)
self
.
respond
(
'OK'
)
elif
len
(
parts
)
==
2
and
parts
[
0
]
==
'mediumon'
:
print
(
'Run
%
s'
%
(
parts
[
1
]))
d
=
ev3
.
MediumMotor
(
'out'
+
parts
[
1
])
d
.
run_forever
()
self
.
respond
(
'OK'
)
elif
len
(
parts
)
==
2
and
parts
[
0
]
==
'largeon'
:
print
(
'Run
%
s'
%
(
parts
[
1
]))
d
=
ev3
.
LargeMotor
(
'out'
+
parts
[
1
])
d
.
run_forever
()
self
.
respond
(
'OK'
)
elif
len
(
parts
)
==
2
and
parts
[
0
]
==
'mediumoff'
:
print
(
'Stop
%
s'
%
(
parts
[
1
]))
d
=
ev3
.
MediumMotor
(
'out'
+
parts
[
1
])
d
.
stop
()
self
.
respond
(
'OK'
)
elif
len
(
parts
)
==
2
and
parts
[
0
]
==
'largeoff'
:
print
(
'Stop
%
s'
%
(
parts
[
1
]))
d
=
ev3
.
LargeMotor
(
'out'
+
parts
[
1
])
d
.
stop
()
self
.
respond
(
'OK'
)
class
TCPServer
(
socketserver
.
TCPServer
):
def
server_bind
(
self
):
...
...
snap-ev3.py
View file @
52c1d877
...
...
@@ -16,6 +16,7 @@ EV3_IP = '10.42.0.3'
class
Handler
(
SimpleHTTPServer
.
SimpleHTTPRequestHandler
):
def
do_GET
(
self
):
if
self
.
path
==
'/snap-ev3'
:
print
"Opening XML"
f
=
open
(
'snap-ev3.xml'
,
'rb'
)
self
.
send_response
(
200
)
self
.
send_header
(
"Content-type"
,
'text/xml'
)
...
...
@@ -45,8 +46,8 @@ class TCPServer(SocketServer.TCPServer):
self
.
socket
.
bind
(
self
.
server_address
)
print
"Starting listener on EV3"
#
os.system('scp listen.py %s@%s:' % (EV3_USER, EV3_IP))
#os.system('ssh %s@%s -- nohup python listen.py %d &' % (EV3_USER, EV3_IP, EV3_PORT))
os
.
system
(
'scp listen.py
%
s@
%
s:'
%
(
EV3_USER
,
EV3_IP
))
#os.system('ssh %s@%s -- nohup python
3
listen.py %d &' % (EV3_USER, EV3_IP, EV3_PORT))
httpd
=
TCPServer
((
""
,
SNAP_PORT
),
Handler
)
print
"http://snap.berkeley.edu/snapsource/snap.html#open:http://localhost:1330/snap-ev3"
...
...
snap-ev3.xml
View file @
52c1d877
<blocks
app=
"Snap! 4.0, http://snap.berkeley.edu"
version=
"1"
>
<block-definition
category=
"control"
s=
"move
motor %'motor' %'degrees' degree
s at %'speed' speed"
type=
"command"
>
<block-definition
category=
"control"
s=
"move
largemotor %'motor' %'milliseconds' millisecond
s at %'speed' speed"
type=
"command"
>
<inputs>
<input
type=
"%txt"
>
a
</input>
<input
type=
"%txt"
>
A
<options>
A
B
C
D
E
F
G
H
</options>
</input>
<input
type=
"%n"
>
360
</input>
<input
type=
"%n"
>
100
</input>
</inputs>
...
...
@@ -12,10 +21,10 @@
<block
s=
"reportURL"
>
<block
s=
"reportJoinWords"
>
<list>
<l>
localhost:1330/motor/
</l>
<l>
localhost:1330/
large
motor/
</l>
<block
var=
"motor"
/>
<l>
/
</l>
<block
var=
"
degree
s"
/>
<block
var=
"
millisecond
s"
/>
<l>
/
</l>
<block
var=
"speed"
/>
</list>
...
...
@@ -26,6 +35,299 @@
</block>
</script>
</block-definition>
<block-definition
category=
"control"
s=
"move mediummotor %'motor' %'milliseconds' milliseconds at %'speed' speed"
type=
"command"
>
<inputs>
<input
type=
"%txt"
>
A
<options>
A
B
C
D
E
F
G
H
</options>
</input>
<input
type=
"%n"
>
360
</input>
<input
type=
"%n"
>
100
</input>
</inputs>
<script>
<block
s=
"doRun"
>
<block
s=
"reifyReporter"
>
<autolambda>
<block
s=
"reportURL"
>
<block
s=
"reportJoinWords"
>
<list>
<l>
localhost:1330/mediummotor/
</l>
<block
var=
"motor"
/>
<l>
/
</l>
<block
var=
"milliseconds"
/>
<l>
/
</l>
<block
var=
"speed"
/>
</list>
</block>
</block>
</autolambda>
</block>
</block>
</script>
</block-definition>
<block-definition
category=
"control"
s=
"move mediummotor %'motor' %'milliseconds' milliseconds"
type=
"command"
>
<inputs>
<input
type=
"%txt"
>
A
<options>
A
B
C
D
E
F
G
H
</options>
</input>
<input
type=
"%n"
>
360
</input>
</inputs>
<script>
<block
s=
"doRun"
>
<block
s=
"reifyReporter"
>
<autolambda>
<block
s=
"reportURL"
>
<block
s=
"reportJoinWords"
>
<list>
<l>
localhost:1330/mediumtimed/
</l>
<block
var=
"motor"
/>
<l>
/
</l>
<block
var =
"milliseconds"
/>
</list>
</block>
</block>
</autolambda>
</block>
</block>
</script>
</block-definition>
<block-definition
category=
"control"
s=
"move largemotor %'motor' %'milliseconds' milliseconds"
type=
"command"
>
<inputs>
<input
type=
"%txt"
>
A
<options>
A
B
C
D
E
F
G
H
</options>
</input>
<input
type=
"%n"
>
360
</input>
</inputs>
<script>
<block
s=
"doRun"
>
<block
s=
"reifyReporter"
>
<autolambda>
<block
s=
"reportURL"
>
<block
s=
"reportJoinWords"
>
<list>
<l>
localhost:1330/largetimed/
</l>
<block
var=
"motor"
/>
<l>
/
</l>
<block
var =
"milliseconds"
/>
</list>
</block>
</block>
</autolambda>
</block>
</block>
</script>
</block-definition>
<block-definition
category=
"control"
s=
"turn on mediummotor %'motor'"
type=
"command"
>
<inputs>
<input
type=
"%txt"
>
A
<options>
A
B
C
D
E
F
G
H
</options>
</input>
</inputs>
<script>
<block
s=
"doRun"
>
<block
s=
"reifyReporter"
>
<autolambda>
<block
s=
"reportURL"
>
<block
s=
"reportJoinWords"
>
<list>
<l>
localhost:1330/mediumon/
</l>
<block
var=
"motor"
/>
</list>
</block>
</block>
</autolambda>
</block>
</block>
</script>
</block-definition>
<block-definition
category=
"control"
s=
"turn off mediummotor %'motor'"
type=
"command"
>
<inputs>
<input
type=
"%txt"
>
A
<options>
A
B
C
D
E
F
G
H
</options>
</input>
</inputs>
<script>
<block
s=
"doRun"
>
<block
s=
"reifyReporter"
>
<autolambda>
<block
s=
"reportURL"
>
<block
s=
"reportJoinWords"
>
<list>
<l>
localhost:1330/mediumoff/
</l>
<block
var=
"motor"
/>
</list>
</block>
</block>
</autolambda>
</block>
</block>
</script>
</block-definition>
<block-definition
category=
"control"
s=
"turn off largemotor %'motor'"
type=
"command"
>
<inputs>
<input
type=
"%txt"
>
A
<options>
A
B
C
D
E
F
G
H
</options>
</input>
</inputs>
<script>
<block
s=
"doRun"
>
<block
s=
"reifyReporter"
>
<autolambda>
<block
s=
"reportURL"
>
<block
s=
"reportJoinWords"
>
<list>
<l>
localhost:1330/largeoff/
</l>
<block
var=
"motor"
/>
</list>
</block>
</block>
</autolambda>
</block>
</block>
</script>
</block-definition>
<block-definition
category=
"control"
s=
"turn on largemotor %'motor'"
type=
"command"
>
<inputs>
<input
type=
"%txt"
>
A
<options>
A
B
C
D
E
F
G
H
</options>
</input>
</inputs>
<script>
<block
s=
"doRun"
>
<block
s=
"reifyReporter"
>
<autolambda>
<block
s=
"reportURL"
>
<block
s=
"reportJoinWords"
>
<list>
<l>
localhost:1330/largeon/
</l>
<block
var=
"motor"
/>
</list>
</block>
</block>
</autolambda>
</block>
</block>
</script>
</block-definition>
<block-definition
s=
"Being Touched?"
type=
"reporter"
category =
"operators"
>
<script>
<block
s=
"doIfElse"
>
<block
s=
"reportEquals"
>
<custom-block
s=
"touch sensor level"
/>
<l>
1
</l>
</block>
<script>
<block
s=
"doReport"
>
<l>
True
</l>
</block>
</script>
<script>
<block
s=
"doReport"
>
<l>
False
</l>
</block>
</script>
</block>
</script>
</block-definition>
<block-definition
s=
"How Far Away?"
type=
"reporter"
category=
"operators"
>
<header/>
<code/>
<inputs/>
<script>
<block
s=
"doIf"
>
<block
s=
"reportLessThan"
>
<custom-block
s=
"IR sensor proximity"
/>
<l>
33
</l>
</block>
<script>
<block
s=
"doReport"
>
<l>
Close
</l>
</block>
</script>
</block>
<block
s=
"doIfElse"
>
<block
s=
"reportAnd"
>
<block
s=
"reportLessThan"
>
<custom-block
s=
"IR sensor proximity"
/>
<l>
66
</l>
</block>
<block
s=
"reportLessThan"
>
<l>
33
</l>
<custom-block
s=
"IR sensor proximity"
/>
</block>
</block>
<script>
<block
s=
"doReport"
>
<l>
Medium
</l>
</block>
</script>
<script>
<block
s=
"doReport"
>
<l>
Far Away
</l>
</block>
</script>
</block>
</script>
</block-definition>
<block-definition
category=
"control"
s=
"speak %'words'"
type=
"command"
>
<inputs>
<input
type=
"%txt"
>
hello
</input>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment