Make flaps work correct when used in single steps

Signed-off-by: merspieler <merspieler@users.noreply.github.com>
This commit is contained in:
merspieler 2018-02-21 19:46:17 +01:00
parent 47488c2cea
commit a71336cb73

View file

@ -75,23 +75,18 @@ class FlightGearCopilotSkill(MycroftSkill):
tn = self.connect() tn = self.connect()
# get acid # get acid
tn.write("get /sim/aircraft\r\n") acid = self.get_prop(tn, "/sim/aircraft")
acid = tn.read_until("\n")
# read acid to know which profile to use # read acid to know which profile to use
profile = None profile = None
for i_profiles in self.settings['profiles']: for i_profiles in self.settings['profiles']:
for i_acid in i_profiles['acid']: for i_acid in i_profiles['acid']:
if str(i_acid) == str(acid): if i_acid == acid:
profile = i_profiles profile = i_profiles
break break
if profile != None: if profile != None:
break break
# BYPASS THE PROFILE CHECK
# TODO REMOVE THIS BYPASS
profile = self.settings['profiles'][0]
# check if the profile was found # check if the profile was found
if profile == None: if profile == None:
# TODO when creation of profiles via voice is possible, add dialog how to # TODO when creation of profiles via voice is possible, add dialog how to
@ -99,8 +94,7 @@ class FlightGearCopilotSkill(MycroftSkill):
self.exit(tn) self.exit(tn)
# get kias # get kias
tn.write("get /velocities/airspeed-kt\r\n") kias = int(float(self.get_prop(tn, "/velocities/airspeed-kt")))
kias = float(tn.read_until("\n"))
# find the flaps value for the flaps id # find the flaps value for the flaps id
o_flaps = None o_flaps = None
@ -109,13 +103,12 @@ class FlightGearCopilotSkill(MycroftSkill):
o_flaps = i_flaps o_flaps = i_flaps
break break
# cheick if flaps setting is known # check if flaps setting is known
if o_flaps == None: if o_flaps == None:
self.speak_dialog("flaps.setting.unknown") self.speak_dialog("flaps.setting.unknown")
self.exit(tn) self.exit(tn)
tn.write("get " + str(profile['flaps-path']) + "\r\n") flaps = int(self.get_prop(tn, str(profile['flaps-path'])))
flaps = tn.read_until("\n")
# check if extend or retract flaps # check if extend or retract flaps
# TODO add handling up|down|full is already set # TODO add handling up|down|full is already set
@ -133,8 +126,7 @@ class FlightGearCopilotSkill(MycroftSkill):
self.exit(tn) self.exit(tn)
# get ground speed # get ground speed
tn.write("get /velocities/groundspeed-kt\r\n") gs = int(float(self.get_prop(tn, "/velocities/groundspeed-kt")))
gs = float(tn.read_until("\n"))
# skip speed check is speed is <= 30 # skip speed check is speed is <= 30
if gs > 30: if gs > 30:
@ -152,7 +144,14 @@ class FlightGearCopilotSkill(MycroftSkill):
else: else:
self.speak("Speed checked.") self.speak("Speed checked.")
# TODO set flaps in fg # TODO check flaps setting and change it again if needed
if flaps_mov == "extend":
# TBC CONTINUE HERE!!!!
flaps = int(self.get_prop(tn, str(profile['flaps-path'])))
self.nasal_exec(tn, "controls.flapsDown(1);")
else:
flaps = int(self.get_prop(tn, str(profile['flaps-path'])))
self.nasal_exec(tn, "controls.flapsDown(-1);")
self.speak("Flaps " + str(flaps_request)) self.speak("Flaps " + str(flaps_request))
tn.close tn.close
@ -167,8 +166,13 @@ class FlightGearCopilotSkill(MycroftSkill):
@intent_handler(IntentBuilder('GearUpIntent').require('gearup')) @intent_handler(IntentBuilder('GearUpIntent').require('gearup'))
def handle_gear_up_intent(self, message): def handle_gear_up_intent(self, message):
# TODO add connection to fg tn = self.connect()
# TODO read acid from fg
# get acid
tn.write("get /sim/aircraft\r\n")
acid = tn.read_until("\n")
profile = None
# read acid to know which profile to use # read acid to know which profile to use
for i_profiles in self.settings['profiles']: for i_profiles in self.settings['profiles']:
@ -179,22 +183,32 @@ class FlightGearCopilotSkill(MycroftSkill):
if profile != None: if profile != None:
break break
# BYPASS THE PROFILE CHECK
# TODO REMOVE THIS BYPASS
profile = self.settings['profiles'][0]
if profile == None: if profile == None:
# TODO when creation of profiles via voice is possible, add dialog how to # TODO when creation of profiles via voice is possible, add dialog how to
self.speak("Profile not found") self.speak("Profile not found")
self.exit(tn) self.exit(tn)
if profile['gear-retractable'] == true: if profile['gear-retractable'] == "true":
# TODO set gear up in fg
self.speak("Gear up") self.speak("Gear up")
# TODO puts the gear down right now... fix
self.nasal_exec(tn, "controls.gearDown(-1)")
else: else:
self.speak_dialog("gear.not.retractable") self.speak_dialog("gear.not.retractable")
@intent_handler(IntentBuilder('GearDownIntent').require('geardown')) @intent_handler(IntentBuilder('GearDownIntent').require('geardown'))
def handle_gear_down_intent(self, message): def handle_gear_down_intent(self, message):
# TODO add connection to fg tn = self.connect()
# TODO read acid from fg
# get acid
tn.write("get /sim/aircraft\r\n")
acid = tn.read_until("\n")
profile = None
# read acid to know which profile to use # read acid to know which profile to use
for i_profiles in self.settings['profiles']: for i_profiles in self.settings['profiles']:
@ -205,14 +219,18 @@ class FlightGearCopilotSkill(MycroftSkill):
if profile != None: if profile != None:
break break
# BYPASS THE PROFILE CHECK
# TODO REMOVE THIS BYPASS
profile = self.settings['profiles'][0]
if profile == None: if profile == None:
# TODO when creation of profiles via voice is possible, add dialog how to # TODO when creation of profiles via voice is possible, add dialog how to
self.speak("Profile not found") self.speak("Profile not found")
self.exit(tn) self.exit(tn)
if profile['gear-retractable'] == true: if profile['gear-retractable'] == "true":
# TODO set gear down in fg
self.speak("Gear down") self.speak("Gear down")
self.nasal_exec(tn, "controls.gearDown(1)")
else: else:
self.speak_dialog("gear.not.retractable") self.speak_dialog("gear.not.retractable")
@ -223,8 +241,8 @@ class FlightGearCopilotSkill(MycroftSkill):
# # # #
################################################################# #################################################################
# TODO add all possible checklist
# TODO make it possible, to play a .mp3 file instead of tts # TODO make it possible, to play a .mp3 file instead of tts
# TODO read checklists from fg
################################# #################################
# # # #
@ -253,7 +271,7 @@ class FlightGearCopilotSkill(MycroftSkill):
self.speak("Checklist not completed") self.speak("Checklist not completed")
sys.exit(0) sys.exit(0)
response = self.get_response("check.before.start.signs") response = self.get_response("check.general.signs")
if response == None: if response == None:
self.speak("Checklist not completed") self.speak("Checklist not completed")
sys.exit(0) sys.exit(0)
@ -262,7 +280,7 @@ class FlightGearCopilotSkill(MycroftSkill):
self.speak("Checklist not completed") self.speak("Checklist not completed")
sys.exit(0) sys.exit(0)
response = self.get_response("check.before.start.adirs") response = self.get_response("check.general.adirs")
if response == None: if response == None:
self.speak("Checklist not completed") self.speak("Checklist not completed")
sys.exit(0) sys.exit(0)
@ -392,10 +410,24 @@ class FlightGearCopilotSkill(MycroftSkill):
@intent_handler(IntentBuilder('TaxiCheckIntent').require('taxi.check')) @intent_handler(IntentBuilder('TaxiCheckIntent').require('taxi.check'))
def handle_taxi_check_intent(self, message): def handle_taxi_check_intent(self, message):
# TODO make checklist plane specific # TODO make checklist plane specific
self.speak("Flight controls checked") response = self.get_response("check.taxi.flight.controls")
sleep(4) if response == None:
self.speak("Flight instruments checked") self.speak("Checklist not completed")
sleep(4) sys.exit(0)
match = re.search(r'checked|check', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
response = self.get_response("check.taxi.flight.instruments")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'checked|check', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
response = self.get_response("check.general.briefing") response = self.get_response("check.general.briefing")
if response == None: if response == None:
self.speak("Checklist not completed") self.speak("Checklist not completed")
@ -454,7 +486,7 @@ class FlightGearCopilotSkill(MycroftSkill):
if response == None: if response == None:
self.speak("Checklist not completed") self.speak("Checklist not completed")
sys.exit(0) sys.exit(0)
match = re.search(r'confirmed', response, re.I) match = re.search(r'confirmed|advised', response, re.I)
if match == None: if match == None:
self.speak("Checklist not completed") self.speak("Checklist not completed")
sys.exit(0) sys.exit(0)
@ -562,7 +594,7 @@ class FlightGearCopilotSkill(MycroftSkill):
self.speak("Checklist not completed") self.speak("Checklist not completed")
sys.exit(0) sys.exit(0)
response = self.get_response("check.appr.seat.belts") response = self.get_response("check.general.seat.belts")
if response == None: if response == None:
self.speak("Checklist not completed") self.speak("Checklist not completed")
sys.exit(0) sys.exit(0)
@ -620,8 +652,212 @@ class FlightGearCopilotSkill(MycroftSkill):
self.speak("Landing checklist completed") self.speak("Landing checklist completed")
#################################
# #
# After LDG Check #
# #
#################################
@intent_handler(IntentBuilder('AfterLDGCheckIntent').require('after.ldg.check'))
def handle_after_ldg_check_intent(self, message):
# TODO make checklist plane specific
response = self.get_response("check.general.flaps")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'up|retracted', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
response = self.get_response("check.after.ldg.spoilers")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'disarmed', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
response = self.get_response("check.after.ldg.apu")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'off|on|start', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
response = self.get_response("check.after.ldg.radar")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'off', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
response = self.get_response("check.after.ldg.wx")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'off', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
self.speak("After landing checklist completed")
#################################
# #
# Parking Check #
# #
#################################
@intent_handler(IntentBuilder('ParkingCheckIntent').require('parking.check'))
def handle_parking_check_intent(self, message):
# TODO make checklist plane specific
response = self.get_response("check.general.apu.bleed")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'on', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
response = self.get_response("check.parking.eng")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'off', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
response = self.get_response("check.general.seat.belts")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'off', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
response = self.get_response("check.parking.lights")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'off', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
response = self.get_response("check.parking.fuel.pumps")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'off', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
response = self.get_response("check.general.parking.break")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'on|off|set', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
self.speak("Parking checklist completed")
#################################
# #
# Securing Check #
# #
#################################
@intent_handler(IntentBuilder('SecuringCheckIntent').require('securing.check'))
def handle_securing_check_intent(self, message):
# TODO make checklist plane specific
response = self.get_response("check.general.adirs")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'off', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
response = self.get_response("check.securing.oxygen")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'off', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
response = self.get_response("check.general.apu.bleed")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'off', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
response = self.get_response("check.securing.emer.exit.lt")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'off', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
response = self.get_response("check.general.signs")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'off', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
response = self.get_response("check.securing.apu.bat")
if response == None:
self.speak("Checklist not completed")
sys.exit(0)
match = re.search(r'off', response, re.I)
if match == None:
self.speak("Checklist not completed")
sys.exit(0)
@intent_handler(IntentBuilder('FlightControlCheckIntent').require('flight.control.check'))
def handle_securing_check_intent(self, message):
self.speak("Full up")
sleep(2)
self.speak("Full down")
sleep(2)
self.speak("Neutral")
sleep(2)
self.speak("Full left")
sleep(2)
self.speak("Full right")
sleep(2)
self.speak("Neutral")
sleep(2)
self.speak("Full left")
sleep(4)
self.speak("Full right")
sleep(4)
self.speak("Neutral")
sleep(2)
self.speak("Flight controls checked")
# TODO add flt/ctl check
################################################################# #################################################################
# # # #
@ -642,6 +878,19 @@ class FlightGearCopilotSkill(MycroftSkill):
return tn return tn
# running an nasal command
def nasal_exec(self, tn, call):
tn.write("nasal\r\n")
tn.write(call + "\r\n")
tn.write("##EOF##\r\n")
# get a prop from the property tree
def get_prop(self, tn, prop):
tn.write("get " + prop + "\r\n")
ret = tn.read_until("\r")
tn.read_until("\n")
return ret[:-1]
# exit routine to properly close the tn con # exit routine to properly close the tn con
def exit(self, tn): def exit(self, tn):
tn.close tn.close