Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
Hochautomatisiertes-Fahren
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Philipp Badenhoop
Hochautomatisiertes-Fahren
Commits
11dc9b1b
Commit
11dc9b1b
authored
6 years ago
by
Hoop77
Browse files
Options
Downloads
Patches
Plain Diff
-
parent
46317538
Branches
Branches containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scripts/.gitignore
+2
-0
2 additions, 0 deletions
scripts/.gitignore
scripts/remote_control.py
+116
-118
116 additions, 118 deletions
scripts/remote_control.py
with
118 additions
and
118 deletions
scripts/.gitignore
0 → 100644
+
2
−
0
View file @
11dc9b1b
.vscode
.idea
\ No newline at end of file
This diff is collapsed.
Click to expand it.
scripts/remote_control.py
+
116
−
118
View file @
11dc9b1b
import
pygame
import
sys
import
time
from
pexpect
import
pxssh
from
pygame.locals
import
*
...
...
@@ -54,143 +53,142 @@ class OdroidConnection(pxssh.pxssh):
def
center
(
src
,
dest
):
src
.
centerx
=
dest
.
centerx
src
.
centery
=
dest
.
centery
src
.
centerx
=
dest
.
centerx
src
.
centery
=
dest
.
centery
class
Button
:
def
__init__
(
self
,
rect
,
label
,
onPressed
=
None
,
onReleased
=
None
):
self
.
rect
=
rect
self
.
label
=
label
self
.
onPressed
=
onPressed
self
.
onReleased
=
onReleased
self
.
pressed
=
False
def
press
(
self
):
if
not
self
.
pressed
and
self
.
onPressed
is
not
None
:
self
.
onPressed
()
self
.
pressed
=
True
def
release
(
self
):
if
self
.
pressed
and
self
.
onReleased
is
not
None
:
self
.
onReleased
()
self
.
pressed
=
False
def
draw
(
self
,
surf
):
# fill
if
not
self
.
pressed
:
pygame
.
draw
.
rect
(
surf
,
(
150
,
150
,
150
),
self
.
rect
)
else
:
pygame
.
draw
.
rect
(
surf
,
(
255
,
100
,
100
),
self
.
rect
)
# frame
pygame
.
draw
.
rect
(
surf
,
(
10
,
10
,
10
),
self
.
rect
,
1
)
# label
font
=
pygame
.
font
.
Font
(
None
,
36
)
text
=
font
.
render
(
self
.
label
,
True
,
(
10
,
10
,
10
))
text_rect
=
text
.
get_rect
()
center
(
text_rect
,
self
.
rect
)
surf
.
blit
(
text
,
text_rect
)
def
__init__
(
self
,
rect
,
label
,
onPressed
=
None
,
onReleased
=
None
):
self
.
rect
=
rect
self
.
label
=
label
self
.
onPressed
=
onPressed
self
.
onReleased
=
onReleased
self
.
pressed
=
False
def
press
(
self
):
if
not
self
.
pressed
and
self
.
onPressed
is
not
None
:
self
.
onPressed
()
self
.
pressed
=
True
def
release
(
self
):
if
self
.
pressed
and
self
.
onReleased
is
not
None
:
self
.
onReleased
()
self
.
pressed
=
False
def
draw
(
self
,
surf
):
# fill
if
not
self
.
pressed
:
pygame
.
draw
.
rect
(
surf
,
(
150
,
150
,
150
),
self
.
rect
)
else
:
pygame
.
draw
.
rect
(
surf
,
(
255
,
100
,
100
),
self
.
rect
)
# frame
pygame
.
draw
.
rect
(
surf
,
(
10
,
10
,
10
),
self
.
rect
,
1
)
# label
font
=
pygame
.
font
.
Font
(
None
,
36
)
text
=
font
.
render
(
self
.
label
,
True
,
(
10
,
10
,
10
))
text_rect
=
text
.
get_rect
()
center
(
text_rect
,
self
.
rect
)
surf
.
blit
(
text
,
text_rect
)
if
__name__
==
'
__main__
'
:
conn
=
OdroidConnection
(
"
10.5.37.195
"
,
"
/root/repos/Hochautomatisiertes\ Fahren/modules/catkin_ws/src/VeloxProtocolLib/cmake-build-debug/TerminalControl
"
)
conn
.
connect
()
FPS
=
60
pygame
.
init
()
fpsClock
=
pygame
.
time
.
Clock
()
BACKGROUND_COLOR
=
(
255
,
255
,
255
)
SCREEN_WIDTH
,
SCREEN_HEIGHT
=
640
,
480
screen
=
pygame
.
display
.
set_mode
((
SCREEN_WIDTH
,
SCREEN_HEIGHT
),
0
,
32
)
background
=
pygame
.
Surface
(
screen
.
get_size
())
background
=
background
.
convert
()
background
.
fill
(
BACKGROUND_COLOR
)
background
.
blit
(
background
,
(
0
,
0
))
clock
=
pygame
.
time
.
Clock
()
pygame
.
key
.
set_repeat
(
1
,
40
)
GRIDSIZE
=
10
GRID_WIDTH
=
SCREEN_WIDTH
/
GRIDSIZE
GRID_HEIGHT
=
SCREEN_HEIGHT
/
GRIDSIZE
UP
=
(
0
,
-
1
)
DOWN
=
(
0
,
1
)
LEFT
=
(
-
1
,
0
)
RIGHT
=
(
1
,
0
)
BUTTON_WIDTH
=
200
BUTTON_HEIGHT
=
100
PADDING
=
10
buttonsSurface
=
pygame
.
Surface
((
3
*
BUTTON_WIDTH
+
2
*
PADDING
,
2
*
BUTTON_HEIGHT
+
PADDING
))
buttonsSurface
=
buttonsSurface
.
convert
()
buttonsSurface
.
fill
(
BACKGROUND_COLOR
)
FPS
=
60
pygame
.
init
()
fpsClock
=
pygame
.
time
.
Clock
()
BACKGROUND_COLOR
=
(
255
,
255
,
255
)
SCREEN_WIDTH
,
SCREEN_HEIGHT
=
640
,
480
screen
=
pygame
.
display
.
set_mode
((
SCREEN_WIDTH
,
SCREEN_HEIGHT
),
0
,
32
)
background
=
pygame
.
Surface
(
screen
.
get_size
())
background
=
background
.
convert
()
background
.
fill
(
BACKGROUND_COLOR
)
background
.
blit
(
background
,
(
0
,
0
))
clock
=
pygame
.
time
.
Clock
()
pygame
.
key
.
set_repeat
(
1
,
40
)
GRIDSIZE
=
10
GRID_WIDTH
=
SCREEN_WIDTH
/
GRIDSIZE
GRID_HEIGHT
=
SCREEN_HEIGHT
/
GRIDSIZE
UP
=
(
0
,
-
1
)
DOWN
=
(
0
,
1
)
LEFT
=
(
-
1
,
0
)
RIGHT
=
(
1
,
0
)
BUTTON_WIDTH
=
200
BUTTON_HEIGHT
=
100
PADDING
=
10
buttonsSurface
=
pygame
.
Surface
((
3
*
BUTTON_WIDTH
+
2
*
PADDING
,
2
*
BUTTON_HEIGHT
+
PADDING
))
buttonsSurface
=
buttonsSurface
.
convert
()
buttonsSurface
.
fill
(
BACKGROUND_COLOR
)
SPEED
=
1
ANGLE
=
20
ZERO_SPEED
=
0
ZERO_ANGLE
=
0
forwards
=
Button
(
pygame
.
Rect
(
1
*
(
BUTTON_WIDTH
+
PADDING
),
0
*
(
BUTTON_HEIGHT
+
PADDING
),
BUTTON_WIDTH
,
BUTTON_HEIGHT
),
"
FORWARDS
"
,
onPressed
=
lambda
:
conn
.
set_speed
(
SPEED
),
forwards
=
Button
(
pygame
.
Rect
(
1
*
(
BUTTON_WIDTH
+
PADDING
),
0
*
(
BUTTON_HEIGHT
+
PADDING
),
BUTTON_WIDTH
,
BUTTON_HEIGHT
),
"
FORWARDS
"
,
onPressed
=
lambda
:
conn
.
set_speed
(
SPEED
),
onReleased
=
lambda
:
conn
.
set_speed
(
ZERO_SPEED
))
backwards
=
Button
(
pygame
.
Rect
(
1
*
(
BUTTON_WIDTH
+
PADDING
),
1
*
(
BUTTON_HEIGHT
+
PADDING
),
BUTTON_WIDTH
,
BUTTON_HEIGHT
),
"
BACKWARDS
"
,
onPressed
=
lambda
:
conn
.
set_speed
(
-
SPEED
),
backwards
=
Button
(
pygame
.
Rect
(
1
*
(
BUTTON_WIDTH
+
PADDING
),
1
*
(
BUTTON_HEIGHT
+
PADDING
),
BUTTON_WIDTH
,
BUTTON_HEIGHT
),
"
BACKWARDS
"
,
onPressed
=
lambda
:
conn
.
set_speed
(
-
SPEED
),
onReleased
=
lambda
:
conn
.
set_speed
(
ZERO_SPEED
))
left
=
Button
(
pygame
.
Rect
(
0
*
(
BUTTON_WIDTH
+
PADDING
),
1
*
(
BUTTON_HEIGHT
+
PADDING
),
BUTTON_WIDTH
,
BUTTON_HEIGHT
),
"
LEFT
"
,
onPressed
=
lambda
:
conn
.
set_angle
(
ANGLE
),
left
=
Button
(
pygame
.
Rect
(
0
*
(
BUTTON_WIDTH
+
PADDING
),
1
*
(
BUTTON_HEIGHT
+
PADDING
),
BUTTON_WIDTH
,
BUTTON_HEIGHT
),
"
LEFT
"
,
onPressed
=
lambda
:
conn
.
set_angle
(
ANGLE
),
onReleased
=
lambda
:
conn
.
set_speed
(
ZERO_ANGLE
))
right
=
Button
(
pygame
.
Rect
(
2
*
(
BUTTON_WIDTH
+
PADDING
),
1
*
(
BUTTON_HEIGHT
+
PADDING
),
BUTTON_WIDTH
,
BUTTON_HEIGHT
),
"
RIGHT
"
,
onPressed
=
lambda
:
conn
.
set_angle
(
-
ANGLE
),
right
=
Button
(
pygame
.
Rect
(
2
*
(
BUTTON_WIDTH
+
PADDING
),
1
*
(
BUTTON_HEIGHT
+
PADDING
),
BUTTON_WIDTH
,
BUTTON_HEIGHT
),
"
RIGHT
"
,
onPressed
=
lambda
:
conn
.
set_angle
(
-
ANGLE
),
onReleased
=
lambda
:
conn
.
set_speed
(
ZERO_ANGLE
))
buttons
=
[
forwards
,
backwards
,
left
,
right
]
buttons_rect
=
buttonsSurface
.
get_rect
()
center
(
buttons_rect
,
background
.
get_rect
())
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
QUIT
:
pygame
.
quit
()
sys
.
exit
()
elif
event
.
type
==
KEYDOWN
:
if
event
.
key
==
K_UP
:
forwards
.
press
()
elif
event
.
key
==
K_DOWN
:
backwards
.
press
()
elif
event
.
key
==
K_LEFT
:
left
.
press
()
elif
event
.
key
==
K_RIGHT
:
right
.
press
()
elif
event
.
type
==
KEYUP
:
if
event
.
key
==
K_UP
:
forwards
.
release
()
elif
event
.
key
==
K_DOWN
:
backwards
.
release
()
elif
event
.
key
==
K_LEFT
:
left
.
release
()
elif
event
.
key
==
K_RIGHT
:
right
.
release
()
background
.
fill
(
BACKGROUND_COLOR
)
for
button
in
buttons
:
button
.
draw
(
buttonsSurface
)
background
.
blit
(
buttonsSurface
,
buttons_rect
)
screen
.
blit
(
background
,
(
0
,
0
))
pygame
.
display
.
update
()
fpsClock
.
tick
(
FPS
)
conn
.
disconnect
()
\ No newline at end of file
buttons
=
[
forwards
,
backwards
,
left
,
right
]
buttons_rect
=
buttonsSurface
.
get_rect
()
center
(
buttons_rect
,
background
.
get_rect
())
while
True
:
for
event
in
pygame
.
event
.
get
():
if
event
.
type
==
QUIT
:
conn
.
disconnect
()
pygame
.
quit
()
sys
.
exit
()
elif
event
.
type
==
KEYDOWN
:
if
event
.
key
==
K_UP
:
forwards
.
press
()
elif
event
.
key
==
K_DOWN
:
backwards
.
press
()
elif
event
.
key
==
K_LEFT
:
left
.
press
()
elif
event
.
key
==
K_RIGHT
:
right
.
press
()
elif
event
.
type
==
KEYUP
:
if
event
.
key
==
K_UP
:
forwards
.
release
()
elif
event
.
key
==
K_DOWN
:
backwards
.
release
()
elif
event
.
key
==
K_LEFT
:
left
.
release
()
elif
event
.
key
==
K_RIGHT
:
right
.
release
()
background
.
fill
(
BACKGROUND_COLOR
)
for
button
in
buttons
:
button
.
draw
(
buttonsSurface
)
background
.
blit
(
buttonsSurface
,
buttons_rect
)
screen
.
blit
(
background
,
(
0
,
0
))
pygame
.
display
.
update
()
fpsClock
.
tick
(
FPS
)
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
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