Advertisement
silver2row

random libs. for motor movement/PySabertooth

Feb 24th, 2025
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. from PySabertooth import *
  4. from flask import Flask, render_template
  5.  
  6. from time import sleep
  7.  
  8. # on the beaglebone related boards, use a known, working UART port on the headers.
  9.  
  10. # For instance, attach P9_21 to S1 on the sabertooth 2 x 12 and attach GND on the sabertooth to GND on your BBB.
  11. # "/dev/ttyS2" has changed in time. Check for changes...
  12.  
  13. saber = Sabertooth("/dev/bone/uart/3", baudrate=9600)
  14.  
  15. # start and enable a service, start a cron job, or make an executable .sh file for use when booting into this file.
  16. app = Flask(__name__)
  17. @app.route("/")
  18. @app.route("/<state>")
  19.  
  20. def arc(state=None):
  21.     if state == "F":
  22.         print("Robot Moving Forward")
  23.         saber.drive(1, 100)
  24.         saber.drive(2, 100)
  25.  
  26.     if state == "R":
  27.         print("Robot Turning Right")
  28.         saber.drive(1, 75)
  29.         saber.drive(2, 25)
  30.  
  31.     if state == "L":
  32.         print("Robot Turning Left")
  33.         saber.drive(1, 25)
  34.         saber.drive(2, 75)
  35.  
  36.     if state == "S":
  37.         print("Robot Stopped")
  38.         saber.drive(1, 0)
  39.         saber.drive(2, 0)
  40. #        saber.stop()
  41.  
  42.     template_data = {
  43.         "title" : state,
  44.     }
  45.     return render_template("Saber.html", state=state)
  46.  
  47. if __name__ == "__main__":
  48.     app.run(host="0.0.0.0", port=5000)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement