def index(): data = get_data() total_records = len(data) return render_template("index.html", data=data, total_records=total_records)
def main(): data = get_data(db) response = app.response_class(response=data, status=200, mimetype='application/json') return response
import pyb import utime ## A motor object pinENA = pyb.Pin(pyb.Pin.board.PA10, pyb.Pin.OUT_PP) pinIN1A = pyb.Pin(pyb.Pin.board.PB4, pyb.Pin.OUT_PP) pinIN2A = pyb.Pin(pyb.Pin.board.PB5, pyb.Pin.OUT_PP) motor = motor.MotorDriver([pinIN1A, pinIN2A, pinENA], 3, [1, 2]) ## An encoder object encoder = encoder.Encoder([pyb.Pin.board.PB6, pyb.Pin.board.PB7], 4, [1, 2]) ## A controller object controller = controller.Controller(K_p=0.10) # # Positioner # while(True): # motor.set_duty_cycle(controller.run(encoder.read())) # utime.sleep_ms(10) # Step repsonse while (True): controller.clear_data() input('Press "enter" to run a step response test!') controller.set_setpoint(4000) encoder.zero() stop = utime.ticks_add(utime.ticks_ms(), 1000) while (utime.ticks_diff(stop, utime.ticks_ms()) > 0): motor.set_duty_cycle(controller.run(encoder.read())) utime.sleep_ms(10) motor.set_duty_cycle(0) controller.get_data()
import numpy from matplotlib import pyplot as plt from matplotlib import animation from controller import get_data fig = plt.figure() ax = plt.axes(xlim=(-1, 1), ylim=(-1, 1)) point, = ax.plot([], [], 'ro', lw=2) fps = 100 data_generator = get_data() numpy.random.seed(1) wx = numpy.random.randn(8) * 2 wy = numpy.random.randn(8) * 2 x, y = 0, 0 # initialization function: plot the background of each frame. Repeats every second def init(): point.set_data([], []) return point, # animation function. This is called sequentially def animate(i): global x global y data = next(data_generator) x += numpy.dot(data, wx) * 0.0001 y += numpy.dot(data, wy) * 0.0001 point.set_data([x], [y])
def index(): url = request.args.get('url') data = get_data(url) return data