Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MarsRover
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Muhamed Alici
MarsRover
Commits
eefae1c6
Commit
eefae1c6
authored
1 month ago
by
Muhamed (aider)
Browse files
Options
Downloads
Patches
Plain Diff
feat: Implement REST API for rover to receive commands from mission control
parent
83ca85a3
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
api.py
+30
-0
30 additions, 0 deletions
api.py
mission_control.py
+21
-9
21 additions, 9 deletions
mission_control.py
with
51 additions
and
9 deletions
api.py
0 → 100644
+
30
−
0
View file @
eefae1c6
from
flask
import
Flask
,
request
,
jsonify
from
rover
import
Rover
from
plateau
import
Plateau
app
=
Flask
(
__name__
)
# Initialisierung des Rovers und des Plateaus
plateau
=
Plateau
(
10
,
10
)
# Standardgröße, kann angepasst werden
rover
=
Rover
()
rover
.
set_plateau_size
(
plateau
.
size_x
,
plateau
.
size_y
)
@app.route
(
'
/drive
'
,
methods
=
[
'
POST
'
])
def
drive_rover
():
"""
Endpunkt zum Steuern des Rovers.
Erwartet ein JSON mit dem Schlüssel
"
Input
"
, der die Befehlssequenz enthält.
Gibt die erfolgreich ausgeführten Befehle zurück.
"""
data
=
request
.
get_json
()
if
not
data
or
'
Input
'
not
in
data
:
return
jsonify
({
'
error
'
:
'
Ungültige Anfrage.
"
Input
"
fehlt.
'
}),
400
commands
=
data
[
'
Input
'
]
result
=
rover
.
drive
(
commands
)
return
jsonify
({
'
executed_commands
'
:
result
})
if
__name__
==
'
__main__
'
:
app
.
run
(
debug
=
True
)
This diff is collapsed.
Click to expand it.
mission_control.py
+
21
−
9
View file @
eefae1c6
...
...
@@ -28,7 +28,7 @@ class MissionControl:
def
send_commands
(
self
,
cmd
:
str
)
->
str
:
"""
Sendet einen Befehl an den Rover.
Sendet einen Befehl an den Rover
über die REST-API
.
Args:
cmd: Der zu sendende Befehl
...
...
@@ -36,15 +36,27 @@ class MissionControl:
Returns:
Die erfolgreich ausgeführten Befehle
"""
# Synchronisiere die Hindernisse zwischen Mars und Rover
# Der Rover sollte die Hindernisse nicht direkt kennen
# Stattdessen sollte er selbst stoppen, wenn ein Hindernis vorliegt
# Da wir aber keine direkte Verbindung zwischen Rover und Mars haben,
# müssen wir die Hindernisse hier synchronisieren
if
hasattr
(
self
.
mars
,
'
plateau
'
)
and
hasattr
(
self
.
mars
.
plateau
,
'
obstacles
'
):
self
.
rover
.
obstacles
=
self
.
mars
.
plateau
.
obstacles
import
requests
import
json
return
self
.
rover
.
drive
(
cmd
)
try
:
# Synchronisiere die Hindernisse zwischen Mars und Rover
if
hasattr
(
self
.
mars
,
'
plateau
'
)
and
hasattr
(
self
.
mars
.
plateau
,
'
obstacles
'
):
self
.
rover
.
obstacles
=
self
.
mars
.
plateau
.
obstacles
# Sende Befehl über REST-API
response
=
requests
.
post
(
'
http://localhost:5000/drive
'
,
json
=
{
'
Input
'
:
cmd
},
headers
=
{
'
Content-Type
'
:
'
application/json
'
})
if
response
.
status_code
==
200
:
result
=
response
.
json
()
return
result
[
'
executed_commands
'
]
else
:
return
f
"
Fehler:
{
response
.
status_code
}
,
{
response
.
text
}
"
except
Exception
as
e
:
# Fallback: Direkter Aufruf, wenn API nicht erreichbar
return
self
.
rover
.
drive
(
cmd
)
def
observe_plateau
(
self
)
->
list
:
"""
...
...
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