lundi 26 août 2019

How to make x variable change each time and read its value from txt file

I am working on my undergraduate project and this is my first time in using use python to control parrot bebop 2 drone and use BCI or BMI technology. I have x variable (int) and I want to read its value from file in the main time I want the program read this file continuously what I mean exactly that my text file input will be changed each time and I want the python code to catch this change and change the value x

for example: if x receive 1 from the text file --> then takeoff the drone in the main time after x receive 1 I want it receives 2 directly (automatically) and do the second command for example: move to the left (but without disconnect the drone "the first command") her is my code, but I had a lot of problems with it, its check the value but no commands work after its know the variable of x:

bebop = Bebop()
print("connecting")
success = bebop.connect(10)
print(success) 
f = open('EEGresults.txt')
lines = f.readlines()
list_of_elements = []
for line in lines:
   list_of_elements += map(int, line.split())
f.close()
print (list_of_elements)
x = list_of_elements[1]

bebop.smart_sleep(5)

 if x == 1:
   print ("Yay! This number is = 1")
   bebop.safe_takeoff(3)

else:
   if x == 2:
      print ("Yay! This number is = 2")
      bebop.move_relative(0,0,0,1.6)

I expect that the code will read x value from text file directly and continuously in the same time it will run the commands depends what it the value of x that it receive it

Aucun commentaire:

Enregistrer un commentaire