Python Forum
Web app controlling step by step motors
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Web app controlling step by step motors
#1
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";
Reply
#2
A for loop?
Reply
#3
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
Reply
#4
number_of_rotations = int(input("How many rotations? "))
for num in range(number_of_rotations):
    # your current code here
Reply
#5
Thank you nilamo, I will post tomorrow updates with this.
Reply
#6
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?
Reply
#7
https://docs.python.org/3/tutorial/contr...statements

You don't indent the for statement, you indent the block you're looping over.
Reply
#8
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.
Reply
#9
(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)
Reply
#10
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Next step? oldbean 1 2,126 Apr-05-2020, 06:13 PM
Last Post: keuninkske

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020