Python Forum
if-loop does not respond to input
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
if-loop does not respond to input
#1
Hey, I recently bought a dobot magician and have been playing around with controlling it using python. However, Im very new to this programming language, and I dont know whether my syntax is off base, or if its the script, or maybe (probably) both. My plan is to control the robot coordinate inputs from an external component, and in the meantime I just want to leave a placeholder for i=input, where i simply just write the number 1 to run the if-loop. However whenever I type 1, nothing happens. Is this because the if-loop does not wait for a command, and the script just moves along with its life?
I also want the script to run endlessly, meaning that once it has checked for i=1 once, it should go back and do this over and over again. How do I go about this?

import threading
import DobotDllType as dType
  
CON_STR = {
    dType.DobotConnect.DobotConnect_NoError: "DobotConnect_NoError",
    dType.DobotConnect.DobotConnect_NotFound: "DobotConnect_NotFound",
    dType.DobotConnect.DobotConnect_Occupied: "DobotConnect_Occupied"}


# Load Dll
api = dType.load()  # Loader biblioteket som gjør at det er mulig å bruke dobot sine funksjoner i python

# Connect
state = dType.ConnectDobot(api, "", 115200)[0]
print("Connect status:", CON_STR[state])

if (state == dType.DobotConnect.DobotConnect_NoError):
    # Clean Command Queued
    dType.SetQueuedCmdClear(api)

    # code

i = input("Enter a number  ")


while (i ==1):
        dType.SetPTPCmdEx(api, 0, 250, 0, 60, 0, 1)
        dType.SetPTPCmdEx(api, 0, 20, 285, 30, 0, 1)
        dType.SetPTPCmdEx(api, 0, 20, 299, (-26), 0, 1)
        dType.SetEndEffectorParamsEx(api, 59.7, 0, 0, 1)
        dType.SetEndEffectorGripperEx(api, 1, 1)
        dType.SetWAITCmdEx(api, 0.4, 1)
        dType.SetPTPCmdEx(api, 0, 200, (-200), 30, 0, 1)
        current_pose = dType.GetPose(api)
        dType.SetPTPCmdEx(api, 2, 0, (-250), (-26), current_pose[3], 1)
        dType.SetEndEffectorGripperEx(api, 1, 0)
        dType.SetPTPCmdEx(api, 0, 250, 0, 60, 0, 1)
        dType.SetPTPCmdEx(api, 0, 0, (-250), (-26), 0, 1)
        dType.SetEndEffectorGripperEx(api, 1, 1)
        dType.SetWAITCmdEx(api, 0.4, 1)
        dType.SetPTPCmdEx(api, 0, 20, 299, 50, 0, 1)
        dType.SetPTPCmdEx(api, 7, 0, 0, (-76), 0, 1)
        dType.SetEndEffectorGripperEx(api, 1, 0)
        dType.SetPTPCmdEx(api, 0, 250, 0, 60, 0, 1)
        dType.SetEndEffectorGripperEx(api, 0, 1)
else:
        dType.SetPTPCmdEx(api, 0, 250, 0, 60, 0, 1)
        dType.SetEndEffectorGripperEx(api, 0, 1)
        
Reply
#2
your while loop has no terminator, ( i is never changed ), so it's happily going to run forever in the loop and only reach the else clause i was input as something other than 1
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to make a telegram bot respond to the specific word in a sentence? Metodolog 2 2,122 Dec-22-2020, 07:30 AM
Last Post: martabassof
  I want to check if the input is str or is int & if it's str repeat the loop HLD202 4 646 Nov-23-2020, 11:01 PM
Last Post: perfringo
  Loop back through loop based on user input, keeping previous changes loop made? hbkpancakes 2 907 Nov-21-2020, 02:35 AM
Last Post: hbkpancakes
  Nested Loop for user input Ads 2 1,551 Dec-30-2019, 11:44 AM
Last Post: Ads
  How to Loop my calculator input Michael1 2 1,531 Dec-13-2019, 04:57 AM
Last Post: ICanIBB
  Server infinite loop input from user tomislav91 1 1,677 May-23-2019, 02:18 PM
Last Post: heiner55
  How to continue in loop until correct input received sunnyarora 10 4,119 May-04-2019, 02:37 PM
Last Post: Yoriz
  How to rerun the program in a loop with different input? bharaths 3 1,688 Nov-23-2018, 09:36 AM
Last Post: bharaths
  Read from a file, get user input in a while loop lynden 8 2,103 Nov-05-2018, 12:31 PM
Last Post: lynden
  [Help] sorted() in while loop with user's input() {Screenshot attached} vanicci 5 1,992 Aug-04-2018, 08:59 PM
Last Post: vanicci

Forum Jump:

User Panel Messages

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