forked from PriyanshuRaut/RRL_OpenSource
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
33 lines (29 loc) · 1.01 KB
/
app.py
File metadata and controls
33 lines (29 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from flask import Flask, render_template, request, jsonify
import rrl # assumes rrl.py is in the same folder
app = Flask(__name__, static_folder='static', template_folder='templates')
@app.route("/")
def index():
return render_template("index.html")
@app.route("/run", methods=["POST"])
def run_code():
data = request.json or {}
code = data.get("code", "")
out = []
try:
result = rrl.run_rrl_code(code, capture_output=out)
env = result.get("env", {})
# extract robot state safely for JSON
robot = env.get("robot")
robot_state = None
if robot:
robot_state = {
"position": robot.position,
"heading": robot.heading,
"battery": robot.battery,
"status": robot.status
}
return jsonify({"ok": True, "output": out, "robot": robot_state})
except Exception as e:
return jsonify({"ok": False, "error": str(e)}), 400
if __name__ == "__main__":
app.run(debug=True)