Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
CS437-Lab-2
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
royzhao2
CS437-Lab-2
Commits
deef3825
Unverified
Commit
deef3825
authored
4 months ago
by
Roy Zhao
Committed by
GitHub
4 months ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #2 from JiaqiZhao2004/royzhao2
step 3 car control
parents
9074bbf5
a7208838
Branches
activity2
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
.idea/.gitignore
+8
-0
8 additions, 0 deletions
.idea/.gitignore
electron/index.js
+28
-21
28 additions, 21 deletions
electron/index.js
electron/server.py
+38
-20
38 additions, 20 deletions
electron/server.py
with
74 additions
and
41 deletions
.idea/.gitignore
0 → 100644
+
8
−
0
View file @
deef3825
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
This diff is collapsed.
Click to expand it.
electron/index.js
+
28
−
21
View file @
deef3825
...
...
@@ -34,29 +34,36 @@ function client(){
// for detecting which key is been pressed w,a,s,d
function
updateKey
(
e
)
{
e
=
e
||
window
.
event
;
if
(
e
.
keyCode
==
'
87
'
)
{
// up (w)
document
.
getElementById
(
"
upArrow
"
).
style
.
color
=
"
green
"
;
send_data
(
"
87
"
);
}
else
if
(
e
.
keyCode
==
'
83
'
)
{
// down (s)
document
.
getElementById
(
"
downArrow
"
).
style
.
color
=
"
green
"
;
send_data
(
"
83
"
);
}
else
if
(
e
.
keyCode
==
'
65
'
)
{
// left (a)
document
.
getElementById
(
"
leftArrow
"
).
style
.
color
=
"
green
"
;
send_data
(
"
65
"
);
}
else
if
(
e
.
keyCode
==
'
68
'
)
{
// right (d)
document
.
getElementById
(
"
rightArrow
"
).
style
.
color
=
"
green
"
;
send_data
(
"
68
"
);
}
const
net
=
require
(
'
net
'
);
const
client
=
net
.
createConnection
({
port
:
server_port
,
host
:
server_addr
},
()
=>
{
if
(
e
.
keyCode
==
'
87
'
)
{
// up (w)
document
.
getElementById
(
"
upArrow
"
).
style
.
color
=
"
green
"
;
client
.
write
(
`87\r\n`
);
}
else
if
(
e
.
keyCode
==
'
83
'
)
{
// down (s)
document
.
getElementById
(
"
downArrow
"
).
style
.
color
=
"
green
"
;
client
.
write
(
`83\r\n`
);
}
else
if
(
e
.
keyCode
==
'
65
'
)
{
// left (a)
document
.
getElementById
(
"
leftArrow
"
).
style
.
color
=
"
green
"
;
client
.
write
(
`65\r\n`
);
}
else
if
(
e
.
keyCode
==
'
68
'
)
{
// right (d)
document
.
getElementById
(
"
rightArrow
"
).
style
.
color
=
"
green
"
;
client
.
write
(
`68\r\n`
);
}
client
.
end
();
});
client
.
on
(
'
error
'
,
(
err
)
=>
{
console
.
log
(
'
Error:
'
,
err
);
});
}
// reset the key to the start state
...
...
This diff is collapsed.
Click to expand it.
electron/server.py
+
38
−
20
View file @
deef3825
import
socket
from
time
import
sleep
from
picarx
import
Picarx
# HOST = "172.16.213.108" # Khushi's Raspberry PI
HOST
=
"
100.85.99.31
"
# Roy's Raspberry PI
PORT
=
65432
# Port to listen on (non-privileged ports are > 1023)
def
callback
(
data
):
if
data
==
'
87
'
:
def
callback
(
px
,
data
):
data
=
data
.
strip
()
if
data
==
b
'
87
'
:
print
(
"
forward (w)
"
)
# forward (w)
pass
elif
data
==
'
83
'
:
px
.
set_dir_servo_angle
(
0
)
px
.
forward
(
10
)
sleep
(
0.3
)
px
.
stop
()
elif
data
==
b
'
83
'
:
# down (s)
pass
elif
data
==
'
65
'
:
print
(
"
backward (s)
"
)
px
.
set_dir_servo_angle
(
0
)
px
.
backward
(
10
)
sleep
(
0.3
)
px
.
stop
()
elif
data
==
b
'
65
'
:
# left (a)
pass
elif
data
==
'
68
'
:
print
(
'
left (a)
'
)
px
.
set_dir_servo_angle
(
-
35
)
px
.
forward
(
10
)
sleep
(
0.3
)
px
.
stop
()
elif
data
==
b
'
68
'
:
# right (d)
pass
print
(
'
right (d)
'
)
px
.
set_dir_servo_angle
(
35
)
px
.
forward
(
10
)
sleep
(
0.3
)
px
.
stop
()
with
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
as
s
:
s
.
bind
((
HOST
,
PORT
))
s
.
listen
()
px
=
Picarx
()
try
:
while
1
:
client
,
clientInfo
=
s
.
accept
()
print
(
"
server recv from:
"
,
clientInfo
)
data
=
client
.
recv
(
1024
)
# receive 1024 Bytes of message in binary format
callback
(
data
)
if
data
!=
b
""
:
print
(
data
)
client
.
sendall
(
data
)
# Echo back to client
except
:
callback
(
px
,
data
)
except
:
print
(
"
Closing socket
"
)
client
.
close
()
s
.
close
()
s
.
close
()
px
.
stop
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment