Hello,

I know there is a lot going on in the development world right now. 

...

Does the MotorCape still work on the 4GB SD IoT image on 
http://beagleboard.org/latest-images?

I have some source I was trying to use w/ radio buttons via html and flask 
w/ Adafruit_BBIO.

The source used to work. I have not been able to figure out why it does not 
work any longer.

If things are changing and dev. need whatever to take place, okay. I would 
still like to harden some learned skills from the past and promote those 
skills now currently.

Seth

-- 
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 [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/beagleboard/87fdebf6-0437-4e33-b614-e739ff4b6ed0n%40googlegroups.com.
from flask import Flask, render_template
import Adafruit_BBIO.GPIO as GPIO
import Adafruit_BBIO.PWM as PWM
from rangeI import Range

sonar = Range("/dev/ttyS2")

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):
        if value == self.value:
            return

        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)

def set_motors( v1, v2, v3, v4 ):
    motor1.set( v1 )
    motor2.set( v2 )
    motor3.set( v3 )
    motor4.set( v4 )


app = Flask(__name__)

@app.route("/")
def homepage( title="homepage" ):
    return render_template( "BootI.html", title=title )

@app.route("/distance")
def distance():
    distance = sonar.measure()
    print("distance =", distance, "inch")

    if distance < 8:
        set_motors( 0, 0, 0, 0 )
        print("Stopping Motors!")
                
     return homepage( title="distance" )

def add_motors_route( state, v1, v2, v3, v4 ):
    @app.route( "/" + state, endpoint=state )
    def handler():
        set_motors( v1, v2, v3, v4 )
        return homepage( title=state )

add_motors_route( "F",           100,  100,  100,  100 )
add_motors_route( "L",            15,   85,   15,   85 )
add_motors_route( "R",            85,   15,   85,   15 )
add_motors_route( "S",             0,    0,    0,    0 )
add_motors_route( "REV",         -75,  -75,  -75,  -75 )
add_motors_route( "REV_L",       -75,  -25,  -75,  -25 )
add_motors_route( "REV_R",       -25,  -75,  -25,  -75 )
add_motors_route( "SPIN_LEFT",   100, -100,  100, -100 )
add_motors_route( "SPIN_RIGHT", -100,  100, -100,  100 )

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000, debug=False)

Reply via email to