def Execute(self): self.count = 0 # counts the number of reading taken self.ResetHeightArray() # set all values of the array to 0 while ( self.loop ): #Loop continues to iterate until mean value of reading is < 25cm time.sleep(0.5) self.reading = Ultrasonic.getReading2() # reads height from ground if self.ValidateReading(): # if 13cm < reading <= 200cm self.count += 1 #increament the count for i in range(self.windowLength - 1): self.heightArray[i] = self.heightArray[ i + 1] #arrange value in the FIFO array self.heightArray[ self.windowLength - 1] = self.reading #attach value at the tail of the array if self.count >= 10: # after ten readings self.count = 0 # reset the count value self.mean = np.mean( self.heightArray) # take the mean value of the arrray print("Mean height: ", self.mean) if self.mean >= 14 and self.mean <= 25: # if 14cm <= mean value <= 25 cm self.nextState = "Landing" # set the next state self.loop = False # break the loop self.Exit()
def VerifyStatus(self): while (True): time.sleep(self.duration / self.windowLength) self.reading = Ultrasonic.getReading2() if self.ValidateReading(): self.count += 1 for i in range(self.windowLength - 1): self.heightArray[i] = self.heightArray[i + 1] self.heightArray[self.windowLength - 1] = self.reading if self.count >= self.windowLength: self.count = 0 self.mean = np.mean(self.heightArray) print("mean height: ", self.mean) if self.mean >= 14 and self.mean <= 18: return True else: print("Go back to state Air") return False
def Execute(self): self.count = 0 self.ResetHeightArray() while (self.loop): time.sleep(0.5) self.reading = Ultrasonic.getReading2() if self.ValidateReading(): self.count += 1 for i in range(self.windowLength - 1): self.heightArray[i] = self.heightArray[i + 1] self.heightArray[self.windowLength - 1] = self.reading if self.count >= 10: self.count = 0 self.mean = np.mean(self.heightArray) print("Mean height: ", self.mean) if self.mean >= 14 and self.mean <= 25: self.nextState = "Landing" self.loop = False self.Exit()
def Execute(self): page = 0 self.ResetHeightArray() while (True): time.sleep(0.5) self.height = Ultrasonic.getReading2() if self.ValidateReading(): page += 1 for i in range(self.windowLength - 1): self.heightArray[i] = self.heightArray[i + 1] self.heightArray[self.windowLength - 1] = self.height print("Height: ", self.heightArray) if (page >= 10): page = 0 self.meanHeight = np.mean(self.heightArray) self.meanHeight = round(self.meanHeight, 0) print("self.meanHeight: ", self.meanHeight) if self.meanHeight >= 25: print("self.meanHeight: ", self.meanHeight) break self.Exit()
def Execute(self): page = 0 self.ResetHeightArray( ) #when this state initiates reset the height array while (True): time.sleep(0.5) # take a reading after half a second break self.height = Ultrasonic.getReading2() # take reading if self.ValidateReading(): page += 1 for i in range(self.windowLength - 1): self.heightArray[i] = self.heightArray[i + 1] self.heightArray[self.windowLength - 1] = self.height print("Height: ", self.heightArray) if (page >= 10): # after ten validated readings page = 0 self.meanHeight = np.mean(self.heightArray) # average height self.meanHeight = round(self.meanHeight, 0) print("self.meanHeight: ", self.meanHeight) if self.meanHeight >= 25: #if height > 25cm then drone is on air print("self.meanHeight: ", self.meanHeight) break self.Exit()
def VerifyStatus(self): # reassures the drone is on ground while (True): # iterate until 10 readings are taken time.sleep(self.duration / self.windowLength) # sleep time is 0.3 se self.reading = Ultrasonic.getReading2() if self.ValidateReading(): # makes sure the reading is credible self.count += 1 for i in range(self.windowLength - 1): self.heightArray[i] = self.heightArray[ i + 1] # rearrange the FIFO array self.heightArray[ self.windowLength - 1] = self.reading #new value is tailed at the array if self.count >= self.windowLength: self.count = 0 self.mean = np.mean(self.heightArray) print("mean height: ", self.mean) if self.mean >= 14 and self.mean <= 18: #if 14 cm <= meanvalue <= 18cm then drone is firmly rested on ground return True else: print("Go back to state Air" ) # returns back to the previous state return False