Robot Control with flask + PWM ? - Raspberry Pi Forums
hi i'm using following code launch robot. robot has 2 motor uses pwm control speed. code: select all try: import rpi.gpio gpio except runtimeerror: print("error importing rpi.gpio! must run root using sudo") flask import flask, render_template # initialize flask application app = flask(__name__) ######################### # motor pins motor1a = 17 #left fwd motor1b = 18 #left rev motor2a = 23 #right fwd motor2b = 22 #right rev # freq of pwm outputs pwm_freq = 50 #50hz # uses processor pin numbering gpio.setmode(gpio.bcm) # speed = pwm duty cycle, 0 = off, 100 = max speed = 100 # (1,1) = fwd, (2,2) = rev, (1,2) = left, (0,0) = right, (1,0) = fwd left, (0,1) = fwd right, (2,0) = rev left, (0,2) = rev right current_direction = (0, 0) # setup pins gpio.setup(motor1a, gpio.out) gpio.setup(motor1b, gpio.out) gpio.setup(motor2a, gpio.out) gpio.setup(motor2b, gpio.out) #gpio.setup(pwm_all, gpio.out) pin1a = gpio.pwm(motor1a, pwm_freq) pin1b = gpio.pw...