Python Forum
Web app controlling step by step motors - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html)
+--- Thread: Web app controlling step by step motors (/thread-8291.html)

Pages: 1 2


Web app controlling step by step motors - dnbbrain - Feb-13-2018

Hi,
I have an basic html page, with an input button that controls 2 step by step motors.
If I input the number 50, the motors will both open at half of course and this is perfect.
How can I make the motors to make 2, or 3, or 4 runs? right now I manage to make them run once.

p = lambda:None
p.__dict__ = json.loads(request.data)
concentration = int(p.concentration)
concentrationSteps = concentration*10
motors.rotate_motor('A', concentrationSteps, 1, 20)
motors.rotate_motor('B', concentrationSteps, 1, 20)
time.sleep(duration)
motors.rotate_motor('A', concentrationSteps, -1, 20)
motors.rotate_motor('B', concentrationSteps, -1, 20)
return "0";



RE: Web app controlling step by step motors - nilamo - Feb-13-2018

A for loop?


RE: Web app controlling step by step motors - dnbbrain - Feb-13-2018

A is the 1st motor, B is the 2nd motor. I was thinking about inputing a number from the keyboard and the motors should execute that number, for example if I enter 5, both the motors should run 5 times, opening and closing


RE: Web app controlling step by step motors - nilamo - Feb-13-2018

number_of_rotations = int(input("How many rotations? "))
for num in range(number_of_rotations):
    # your current code here



RE: Web app controlling step by step motors - dnbbrain - Feb-13-2018

Thank you nilamo, I will post tomorrow updates with this.


RE: Web app controlling step by step motors - dnbbrain - Feb-14-2018

No mather were I put
for num in range(number_of_rotations):

it gives IndentationError: expected an indented block.
Can't figure out were how to indent the for?


RE: Web app controlling step by step motors - nilamo - Feb-14-2018

https://docs.python.org/3/tutorial/controlflow.html#for-statements

You don't indent the for statement, you indent the block you're looping over.


RE: Web app controlling step by step motors - dnbbrain - Feb-15-2018

from flask import Flask, render_template, request
import time
import ConfigParser
import motors
import json

app = Flask(__name__)
parser = ConfigParser.SafeConfigParser()

@app.route("/")
def main():
    templateData = {
        'pins' : 1
        }
    return render_template('main.html', **templateData)

@app.route("/start-admission", methods = ['POST'])
def start_admission():
    print request.data

    p = lambda:None
    p.__dict__ = json.loads(request.data)
    
    concentration = float(p.concentration) #input a number to proceed
    concentrationSteps = concentration*10
    volumeI = 100
    volumeII = 150
    p_volumeI = float(volumeI*p.concentration)/66
    p_volumeII  = float(volumeII*p.concentration)/66
    
    duration = int(p.duration)
    speed = int(p.speed)
    admissionSteps = 1000/speed
    
    number_of_rotation_1 = float(p_volumeI) #must execute the nr of turns p_volumeI
    for num in range(number_of_rotation_1):
        
    motors.rotate_motor('A', concentrationSteps, 1, 20)
    motors.rotate_motor('B', concentrationSteps, 1, 20)

    time.sleep(duration)
    
    number_of_rotation_2 = float(p_volumeII) #must execute the nr of turns p_volumeII
    for num in range(number_of_rotation_2):

    motors.rotate_motor('B', concentrationSteps, -1, 20)
    motors.rotate_motor('A', concentrationSteps, -1, 20)  
   
    return "0";


if __name__ == "__main__":
   app.run(host='0.0.0.0', port=9000, debug=True)
still the same IndentationError: expected an indented block.


RE: Web app controlling step by step motors - snippsat - Feb-15-2018

(Feb-15-2018, 02:52 PM)dnbbrain Wrote: still the same IndentationError: expected an indented block.
You most indent code under line 36 and line 44.
My guess.
from flask import Flask, render_template, request
import time
import ConfigParser
import motors
import json

app = Flask(__name__)
parser = ConfigParser.SafeConfigParser()

@app.route("/")
def main():
    templateData = {
        'pins': 1
    }
    return render_template('main.html', **templateData)

@app.route("/start-admission", methods=['POST'])
def start_admission():
    print request.data

    def p(): return None
    p.__dict__ = json.loads(request.data)
    concentration = float(p.concentration)  # input a number to proceed
    concentrationSteps = concentration * 10
    volumeI = 100
    volumeII = 150
    p_volumeI = float(volumeI * p.concentration) / 66
    p_volumeII = float(volumeII * p.concentration) / 66
    duration = int(p.duration)
    speed = int(p.speed)
    admissionSteps = 1000 / speed
    # must execute the nr of turns p_volumeI
    number_of_rotation_1 = float(p_volumeI)
    for num in range(number_of_rotation_1):
        motors.rotate_motor('A', concentrationSteps, 1, 20)
        motors.rotate_motor('B', concentrationSteps, 1, 20)
        time.sleep(duration)
        # must execute the nr of turns p_volumeII
        number_of_rotation_2 = float(p_volumeII)
    for num in range(number_of_rotation_2):
        motors.rotate_motor('B', concentrationSteps, -1, 20)
        motors.rotate_motor('A', concentrationSteps, -1, 20)
    return "0"

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=9000, debug=True)



RE: Web app controlling step by step motors - dnbbrain - Feb-15-2018

It was so simple jezz, just used TAB and was ok, so it should do some calculus, if I enter 3 the first motor should do 4.5 runs, clockwise - counter clocwise, and the second motor should do 6.8 runs open - close, instead they run like non stop, like in a loop. Any ideeas? Thank you