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:

import sys  
import os
from time import sleep
from pyparrot.Bebop import Bebop
import math

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


if x == 1:
   print ("Yay! This number is = 1")

   if x == 2:
      print ("Yay! This number is = 2")

      if x == 3:
         print ("Yay! This number is = 3")

         print("DONE - disconnecting")

print("DONE - disconnecting")
  • $\begingroup$ get as much information as possible about the state of the running program ... print the value of line and also the value of x ... do you see what you expect to see? $\endgroup$ – jsotola Aug 26 '19 at 0:01
  • $\begingroup$ since x = list_of_elements[1] , when I run the program its give me the correct answer which is 2, which is the second number I wrote it in the text file, but what I need is how I can make x a changed value that can receive a number from the text file automatically and do the commands, e.g, if x == 1 (which is the first number in the file) then takeoff the drone, else if x == 2, then turn left.. etc. $\endgroup$ – Fatima Aug 26 '19 at 7:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.