ready to migrate to dronecommander

This commit is contained in:
Alihan
2023-05-15 23:53:16 +03:00
parent cffd35cf90
commit 2c03e4b96d
4 changed files with 35 additions and 15 deletions

View File

@@ -2,7 +2,11 @@ from brain_openai import CloudChatBrain
brain = CloudChatBrain() brain = CloudChatBrain()
while True: while True:
brain.listen() try:
brain.understand() brain.listen()
brain.command() brain.understand()
brain.command()
except Exception as e:
print(f"##### SOMETHING WENT WRONG ###### \n {e}")

View File

@@ -1,20 +1,27 @@
import requests import sys
import requests
from requests.exceptions import ConnectionError
from settings.config import settings
class CommandHandler: class CommandHandler:
def __init__(self): def __init__(self):
self.COMMANDER_ROOT_URL = "http://0.0.0.0:8889" self.COMMANDER_COMMANDS_URL = f"{settings.COMMANDER_ROOT_URL}/command"
self.COMMANDER_COMMANDS_URL = f"{self.COMMANDER_ROOT_URL}/command"
self._check_commander_health() self._check_commander_health()
def _check_commander_health(self): def _check_commander_health(self):
response = requests.get(f"{self.COMMANDER_ROOT_URL}/test/health") try:
status = response.json() response = requests.get(f"{settings.COMMANDER_ROOT_URL}/test/health")
status = response.json()
except ConnectionError:
print(f"commander service is unavailable: {settings.COMMANDER_ROOT_URL}"); sys.exit(1)
#raise Exception(f"commander service is unavailable: {settings.COMMANDER_ROOT_URL}")
if status["msg"] != "ok": if status["msg"] != "ok":
raise Exception(f"commander service is unavailable: {self.COMMANDER_ROOT_URL}") print("connected to commander service")
def _move(self, direction, distance): def _move(self, direction, distance):
response = requests.get(f"{self.COMMANDER_COMMANDS_URL}/move/{direction}/{distance}") response = requests.get(f"{self.COMMANDER_COMMANDS_URL}/move/{direction}/{distance}")

View File

@@ -1,10 +1,11 @@
#!/bin/bash #!/bin/bash
DRONE_INTERFACE=$(yq '.commander.drone_interface' < config.yml) DRONE_INTERFACE=$(yq '.commander.drone_interface' < settings/admin.yml)
DRONE_WPA_SUPP_CONF=$(yq '.commander.drone_wpa_supp' < config.yml) DRONE_WPA_SUPP_CONF=$(yq '.commander.drone_wpa_supp' < settings/admin.yml)
NET_INTERFACE=$(yq '.commander.net_interface' < config.yml) NET_INTERFACE=$(yq '.commander.net_interface' < settings/admin.yml)
NET_WPA_SUPP_CONF=$(yq '.commander.net_wpa_supp' < config.yml) NET_WPA_SUPP_CONF=$(yq '.commander.net_wpa_supp' < settings/admin.yml)
ENV_FOR_DYNACONF=$(yq '.commander.env_for_dynaconf' < settings/admin.yml)
list_related_network_interface_status() { list_related_network_interface_status() {
@@ -35,6 +36,10 @@ start_commander_service() {
venv/bin/python commander/commander.py $1 venv/bin/python commander/commander.py $1
} }
talk_to_drone() {
ENV_FOR_DYNACONF=$ENV_FOR_DYNACONF python brain/brain.py
}
kill_everything() { kill_everything() {
for p in $pids_dir/*.txt; do echo "killing $p"; pkill $(cat "$p"); done for p in $pids_dir/*.txt; do echo "killing $p"; pkill $(cat "$p"); done
} }
@@ -141,8 +146,10 @@ elif [ "$1" == "finish-flight" ]; then
./manage.sh disconnect-drone ./manage.sh disconnect-drone
./manage.sh kill-dhcp ./manage.sh kill-dhcp
./manage.sh stop-commander ./manage.sh stop-commander
#kill_everything
echo "flight finished" echo "flight finished"
exit 0 elif [ "$1" == "start-talking" ]; then
talk_to_drone
else else
echo "Invalid command. Please use one of: echo "Invalid command. Please use one of:
@@ -153,6 +160,7 @@ else
- start-/ stop-jupyter - start-/ stop-jupyter
- start-/ stop-cs - start-/ stop-cs
- start-/ stop-commander [port] - start-/ stop-commander [port]
- start-talking
- stop-all - stop-all
- prepare-/ finish-flight" - prepare-/ finish-flight"
fi fi

View File

@@ -7,4 +7,5 @@ commander:
wpa_supp_djituad0_plus.conf wpa_supp_djituad0_plus.conf
net_wpa_supp: net_wpa_supp:
wpa_supp_uadis.conf wpa_supp_uadis.conf
env_for_dynaconf:
tuncel