Skip to content

Commit

Permalink
add thread handlering (#109)
Browse files Browse the repository at this point in the history
* add thread handlering

Signed-off-by: tkhmy <[email protected]>

* change thread to aiohttp for Async POST

Signed-off-by: tkhmy <[email protected]>

---------

Signed-off-by: tkhmy <[email protected]>
  • Loading branch information
tkhmy committed Aug 22, 2024
1 parent 286e292 commit 9742b74
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# aptで必要なパッケージをインストール
sudo apt update -y
sudo apt -y install python3-pyqt5.qtquick qml-module-qtquick-controls qml-module-qtquick-controls2 qml-module-qtquick-shapes python3-pyqt5.qtmultimedia libasound2-dev

Check warning on line 7 in setup.sh

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (libasound)
sudo pip3 install simpleaudio
sudo pip3 install simpleaudio aiohttp pyserial

Check warning on line 8 in setup.sh

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (simpleaudio)

Check warning on line 8 in setup.sh

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (aiohttp)

Check warning on line 8 in setup.sh

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (pyserial)

# signageのbuild
colcon build
26 changes: 15 additions & 11 deletions src/signage/src/signage/route_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import requests
import json
from datetime import datetime
import aiohttp

Check warning on line 9 in src/signage/src/signage/route_handler.py

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (aiohttp)
import asyncio

Check warning on line 10 in src/signage/src/signage/route_handler.py

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (asyncio)

import signage.signage_utils as utils
from tier4_external_api_msgs.msg import DoorStatus
from autoware_adapi_v1_msgs.msg import (

Check warning on line 14 in src/signage/src/signage/route_handler.py

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (adapi)
Expand Down Expand Up @@ -65,7 +68,7 @@ def __init__(
self._announced_arrive = False
self._trigger_external_signage = False

self.process_station_list_from_fms()
asyncio.run(self.process_station_list_from_fms())

Check warning on line 71 in src/signage/src/signage/route_handler.py

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (asyncio)

self._node.create_timer(0.2, self.route_checker_callback)
self._node.create_timer(0.2, self.emergency_checker_callback)
Expand Down Expand Up @@ -170,15 +173,16 @@ def announce_engage_when_starting(self):
except Exception as e:
self._node.get_logger().error("not able to play the announce, ERROR: {}".format(str(e)))

def process_station_list_from_fms(self, force_update=False):
async def process_station_list_from_fms(self, force_update=False):
try:
respond = requests.post(
"http://{}:4711/v1/services/order".format(self.AUTOWARE_IP),
json=self._fms_payload,
timeout=5,
)
async with aiohttp.ClientSession() as session:

Check warning on line 178 in src/signage/src/signage/route_handler.py

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (aiohttp)
async with session.post(
f"http://{self.AUTOWARE_IP}:4711/v1/services/order",
json=self._fms_payload,
timeout=5,
) as response:
data = await response.json()

data = json.loads(respond.text)
self._fms_check_time = self._node.get_clock().now()

if not data:
Expand Down Expand Up @@ -312,14 +316,14 @@ def route_checker_callback(self):

if self._prev_route_state != RouteState.SET:
if self._autoware.information.route_state == RouteState.SET:
self.process_station_list_from_fms(force_update=True)
asyncio.run(self.process_station_list_from_fms(force_update=True))

Check warning on line 319 in src/signage/src/signage/route_handler.py

View workflow job for this annotation

GitHub Actions / spellcheck

Unknown word (asyncio)

if not self._fms_check_time:
self.process_station_list_from_fms()
asyncio.run(self.process_station_list_from_fms())
elif utils.check_timeout(
self._node.get_clock().now(), self._fms_check_time, self._parameter.check_fms_time
):
self.process_station_list_from_fms()
asyncio.run(self.process_station_list_from_fms())

if self._in_emergency_state:
return
Expand Down

0 comments on commit 9742b74

Please sign in to comment.