#!/usr/bin/python3
# w/ help from #beagle on Freenode
from flask import Flask, render_template import Adafruit_BBIO.GPIO as GPIO import Adafruit_BBIO.PWM as PWM import time
class Motor: def __init__(self, dir_pin, pwm_pin, pwm_freq): self.dir_pin = dir_pin self.pwm_pin = pwm_pin self.value = 0
PWM.start(pwm_pin, 0, pwm_freq) GPIO.setup(dir_pin, GPIO.OUT)
def set(self, value): assert -100 <= value <= 100 if (value < 0) != (self.value < 0): # changing direction PWM.set_duty_cycle(self.pwm_pin, 0) GPIO.output(self.dir_pin, value < 0) PWM.set_duty_cycle(self.pwm_pin, abs(value)) self.value = value
motor1 = Motor(dir_pin="P8_18", pwm_pin="P9_16", pwm_freq=2000) #motor2 = Motor(dir_pin="P8_16", pwm_pin="P9_14", pwm_freq=2000) #motor3 = Motor(dir_pin="P8_14", pwm_pin="P8_13", pwm_freq=2000) motor4 = Motor(dir_pin="P8_26", pwm_pin="P8_19", pwm_freq=2000)
app = Flask(__name__) @app.route("/") @app.route("/<state>")
def updates(state=None): if state == "F": motor1.set(100) motor4.set(100) time.sleep(.2) if state == "L": motor1.set(0) motor4.set(85) time.sleep(.2) if state == "R": motor1.set(85) motor4.set(0) time.sleep(.2) if state == "S": motor1.set(0) motor4.set(0) time.sleep(.2) if state == "REV": motor1.set(-75) motor4.set(-75) time.sleep(.2) if state == "REV_L": motor1.set(-75) motor4.set(0) time.sleep(.2) if state == "REV_R": motor1.set(0) motor4.set(-75) time.sleep(.2)
template_data = { "title" : state, } return render_template("boboIV.html", **template_data)
if __name__ == "__main__": app.run(host="0.0.0.0", port=5000, debug=True)
<!DOCTYPE html> <html lang="en"> <head> <title>{{ status }}</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </head> <body>
<div class="jumbotron text-center"> <h1>MotorCape and BBBW!</h1> <p>This is a quick example on making motors move!</p> </div> <div class="container"> <div class="row"> <div class="col-sm-4 text-center"> <h3>Agent One</h3> <p>More text and fun makings in life...</p> <p>Get ready to control some motors!</p> </div>
<div class="col-sm-4 text-center"> <h3>Agent Two</h3> <p>This bunch of online buttons will make your motors move</p> <!-- <img src=" http://0.0.0.0/?" "action=stream" alt="Unable to get video feed" width="300" height="300"> --> <a href="/F" id="on" class="button">FORWARD</a> <br><br> <a href="/L" id="on" class="button">LEFT</a> <a href="/R" id="on" class="button">RIGHT</a> <br><br> <a href="/S" id="on" class="button">STOP</a> <br><br> <a href="/REV" id="on" class="button">REVERSE</a> <br><br> <a href="/REV_L" id="on" class="button">REVERSE_L</a> <a href="/REV_R" id="on" class="button">REVERSE_R</a> </div>
<div class="col-sm-4 text-center"> <h3>Agent Three</h3> <p>I hope you had fun controlling your motors!</p> <p>Two, DC motors, a 12v battery, and a BBBW w/ MotorCape!</p> </div> </div> </div>
</body> </html>
Oh and Sir,One last thing...there are many ways to fix this "issue." There was a nice person on Freenode at #beagle that was kind enough to help me w/ software ideas in Python.
...I could rewire the motors, use this person's software, and/or change the complete idea of the software entirely.SethP.S. I was thinking that the MotorCape, w/ the placement of the L298 drivers, was in accordance w/ the schematic. I think while the Cape is in accordance w/ the schematic, I should not expect anything other than rewiring my motors (well...two of them anyhow). If I was to use the software from Freenode, it may get more complicated on my end but may be worth it (learning and trying new things in software programming is the idea). So um, this is what I am hinting towards right now. Should I expect the MotorCape to run in a loop if all motors are told to move forward b/c of the placement of the L298 drivers?
Yea, I think that is it for now. I will try to stay patient. I have too many ideas and little time. I am showing off the bot, BeagleBone Black Wireless, and MotorCape at a tiny Maker Faire soon. Um...yep. That is all for now. Sorry for the PS crap and this elongated explanation.
On Sunday, March 10, 2019 at 10:45:23 PM UTC-5, Jason Kridner wrote:Can you take a picture of how you have it wired?
On Sun, Mar 10, 2019 at 11:33 PM Mala Dies <fun...@gmail.com> wrote:Hello Once More,Just for reference, the web application comes up w/ me enabling a .service file on the BBBW. The website has worked w/ other BBBW related flask-motor-html pages and motor movement.
...Another factor is this...the bot, this four motor machine, moves w/ one board w/ the same software but not the other BBBW w/ the same software.
SethP.S. If you have any ideas, please do not hesitate to ask any questions for more info. and/or give advice. I have this date coming up and I want to have this bot working for this specific date, e.g. w/ the BBBW, MotorCape, and four motors.
On Sunday, March 10, 2019 at 10:18:29 PM UTC-5, Mala Dies wrote:Hello,I have a BBBW and MotorCape. I have tested some motors on each of the screw connectors on the MotorCape. Success! Anyway, when controlling four motors at once, I have come across some issues.
def updates(state=None):
motor1.set(-100)
motor2.set(100)
motor3.set(-100)
motor4.set(100)
--
For more options, visit http://beagleboard.org/discuss
---
You received this message because you are subscribed to the Google Groups "BeagleBoard" group.
To unsubscribe from this group and stop receiving emails from it, send an email to beagleboard...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/beagleboard/ee8425aa-f160-4fb5-bfde-15800568ee72%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.