Skip to content
Snippets Groups Projects
Commit 12e02f59 authored by Muhamed's avatar Muhamed
Browse files

Merge branch 'Feature-Rover-API' into Develop

parents 5a80cf0f 0385fc25
No related branches found
No related tags found
No related merge requests found
Showing
with 10348 additions and 10 deletions
.aider*
Bildschirmfoto_15-5-2025_221527_.jpeg

171 KiB

......@@ -9,7 +9,6 @@ from telescope import Telescope
from map import Map
import unittest
import telescope
# ---US01: Als Mars Mission Control möchte ich den Mars Rover steuern, um die grundlegende Interaktion und Kontrolle über den Rover zu ermöglichen.
# TC01.01: Gültiger Vorwärtsbefehl: Überprüft, ob der Rover sich korrekt um ein Feld vorwärts bewegt, wenn der Befehl "F" empfangen wird.
......
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
No preview for this file type
api.py 0 → 100644
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)
File moved
File moved
......@@ -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:
"""
......
File moved
rest.txt 0 → 100644
openapi: 3.0.3
info:
title: Drive Endpoint API
version: 1.0.0
description: >
A simple API endpoint that receives a command string and may return:
- the full command string
- a substring of the command string
- an empty response
paths:
/drive:
post:
summary: Process a string input
description: Accepts a string and returns either the same string, a substring of it, or nothing.
requestBody:
required: true
content:
application/json:
schema:
type: object
required:
- input
properties:
input:
type: string
examples:
example1:
summary: Forward backward commands
value:
input: "FFFFBBB"
example2:
summary: Simple command string
value:
input: "FB"
example3:
summary: Alternating directions
value:
input: "RRRRLLLL"
example4:
summary: Mixed commands with invalid at the end
value:
input: "FBRLX"
example5:
summary: Unknown command at start
value:
input: "XFB"
responses:
'200':
description: Response may include the original string, a substring, or an empty string
content:
application/json:
schema:
type: object
properties:
output:
type: string
examples:
fullString:
summary: Full string returned
value:
output: "FFFFBBB"
subString:
summary: Substring returned
value:
output: "FBRL"
empty:
summary: Empty string returned
value:
output: ""
'400':
description: Bad request due to missing or invalid input
content:
application/json:
schema:
type: object
properties:
error:
type: string
example:
error: "Missing or invalid input"
File moved
This diff is collapsed.
This diff is collapsed.
File moved
File moved
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment