I am trying to build a project for a working bot from a TX connection.
So, it is Wifi to am335x to UART TX, to motor driver (Dimension Engineering Sabertooth 2 x 12).
The video made is here:
I am working on adding other sensors as we speak... Probably the peripheral access from the ADC to the MaxBotix EZ2 sonar sensor but first...
Some source for the build:
#!/usr/bin/python3
from PySabertooth import Sabertooth
from flask import Flask, render_template
import time
# on the beaglebone related boards, use P9_21 for UART2 and set up config-pin.
# attach P9_21 to S1 on the sabertooth 2 x 12 and attach GND on the sabertooth to GND on your BBB.
saber = Sabertooth("/dev/bone/uart/2", baudrate=9600, address=128, timeout=0.1)
# for instance, sudo config-pin P9.21 uart, that cmd will do it. If using
# Bookworm Distros from beagleboard.org, config-pin is not needed.
# start and enable a service, start a cron job, or make an executable .sh file.
app = Flask(__name__)
@app.route("/")
@app.route("/<state>")
def dire(state=None):
if state == "F":
print ("Robot Moving Forward")
saber.drive(1, 100)
saber.drive(2, 100)
#time.sleep(.2)
if state == "R":
print ("Robot Turning Right")
saber.drive(1, 75)
saber.drive(2, 25)
#time.sleep(.2)
if state == "L":
print ("Robot Turning Left")
saber.drive(1, 25)
saber.drive(2, 75)
#time.sleep(.2)
if state == "S":
print ("Robot Stopped")
saber.drive(1, 0)
saber.drive(2, 0)
saber.stop()
#time.sleep(.2)
template_data = {
"title" : state,
}
return render_template("Saber.html", name=state)
if __name__ == "__main__":
app.run(host="0.0.0.0", port=5000, debug=True)
So, these commands will get you set up properly to run this source on P9.21 and GND from the BBBW to the Sabertooth 2 x 12.
I am using a Bullseye Distro from beagleboard.org for now.
- So, install these libraries before running the above source.
- sudo apt install python3-flask
- Now, make a directory in your cwd called templates.
- In the /templates/ directory, call a file whatever but make sure it is an html file.
- Add this source to your html file:
<!DOCTYPE html>
<head>
<title>{{ title }}</title>
</head>
<body>
<div style="text-align:center">
<h1>Land Motion!</h1>
<hr>
<a href="/F" id="on" class="large_button">FORWARD</a>
<br>
<a href="/L" id="on" class="large_button">LEFT</a>
<a href="/R" id="off" class="large_button">RIGHT</a>
<br>
<a href="/S" id="off" class="large_button">STOP</a>
<br>
<!--- <a href="/REV" id="on" class="large_button">REVERSE</a> --->
</div>
</body>
</html>
Reverse is not supported so far with my small script code. Now, go to https://github.com/MomsFriendlyRobotCompany/pysabertooth to get the file: https://github.com/MomsFriendlyRobotCompany/pysabertooth/blob/master/pysabertooth/PySabertooth.py
That python file will need to be altered a bit. It was used for a combination of pip3 installs and other files within the MIT licensed pysabertooth library online. The license and other attributes can be found here:
MIT License
Copyright (c) 2017 Kevin J. Walchko
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files
(the "Software"), to deal in the Software without
restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.
Just a side note here. pip3 is not needed. You can C & P that PySabertooth file into your cwd alongside the used python3 file listed and use html to serve the server from the BBBW to the Internet on the development desktop.
So, in /etc/systemd/system/, make a file with the suffix .service. Any name will do. We are going to start and enable that file with systemctl.
So, something like this:
sudo nano /etc/systemd/system/start_a_bot.service
In that file, start_a_bot.service, type this data or C & P it:
[Unit]
Description=Explain your File to Yourself
[Service]
ExecStart=/PATH/TO/THE/FILE.py
[Install]
WantedBy=multi-user.target
So, that should be it for now. If you alter the HTML file to suit your needs, add some makes in the comments. Thank you.