From 44fe3361a36fda9fbfef8977fd57f2c78215a3de Mon Sep 17 00:00:00 2001 From: BinarySandia04 Date: Wed, 22 Apr 2026 13:41:39 +0200 Subject: [PATCH] Now working --- backend/main.py | 27 ++++++++++++++++++--------- quibot-web/app/app.vue | 10 +++++++--- 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/backend/main.py b/backend/main.py index ee21435..d37222d 100644 --- a/backend/main.py +++ b/backend/main.py @@ -18,7 +18,7 @@ GPIO.setup(STEP, GPIO.OUT) GPIO.setup(DIR, GPIO.OUT) GPIO.setup(EN, GPIO.OUT) -GPIO.output(EN, GPIO.HIGH) +GPIO.output(EN, GPIO.LOW) motor_thread = None @@ -32,13 +32,11 @@ def step_motor(steps, direction, delay=0.001): GPIO.output(STEP, GPIO.LOW) time.sleep(delay) -def motor_step(): - GPIO.output(EN, GPIO.LOW) # enable driver - +def motor_step(dir): + dir_pin = GPIO.HIGH if dir == "forward" else GPIO.LOW + time.sleep(0.02) # small delay before starting print("Motor running...") - step_motor(400, GPIO.LOW, 0.001) - - GPIO.output(EN, GPIO.HIGH) # disable driver + step_motor(200, dir_pin, 0.001) # ------------------------- @@ -70,7 +68,7 @@ def run_task(task: str, token: str): return {"error": e.output} -@app.post("/motor/step") +@app.post("/motor/step/forward") def start_motor(token: str): global motor_thread @@ -78,12 +76,23 @@ def start_motor(token: str): raise HTTPException(status_code=403, detail="Unauthorized") - motor_thread = threading.Thread(target=motor_step, daemon=True) + motor_thread = threading.Thread(target=motor_step, args=("forward",), daemon=True) motor_thread.start() return {"status": "motor started"} +@app.post("/motor/step/backwards") +def start_motor(token: str): + global motor_thread + if token != "MY_SECRET_TOKEN": + raise HTTPException(status_code=403, detail="Unauthorized") + + + motor_thread = threading.Thread(target=motor_step, args=("backwards",), daemon=True) + motor_thread.start() + + return {"status": "motor started"} @app.post("/motor/stop") def stop_motor(token: str): diff --git a/quibot-web/app/app.vue b/quibot-web/app/app.vue index 1ea8239..1ba1929 100644 --- a/quibot-web/app/app.vue +++ b/quibot-web/app/app.vue @@ -3,8 +3,12 @@

Quibot Motor Control

- + +