This repository has been archived by the owner on Oct 28, 2023. It is now read-only.
forked from plarailers/gogatsusai2023
-
Notifications
You must be signed in to change notification settings - Fork 1
PTCS Update 4 #11
Merged
Merged
PTCS Update 4 #11
Changes from 10 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
4e095b2
停止目標を設置
n4o847 5f7b3b8
Commit from GitHub Actions (Build and commit ptcs_ui)
github-actions[bot] c142268
架線柱との通信を確認
n4o847 915d763
Merge branch 'main' into feature/ptcs-update-4
n4o847 893e616
TrainClient に対しては速度ではなくモーター入力を送る
n4o847 11928ee
古い bridge のコードを削除
n4o847 776600a
関数を整理
n4o847 23e7d33
mft2023 用の bridge の設定を分離
n4o847 92f4c7e
終了処理を修正
n4o847 f5a8334
アドレスを追加
n4o847 14c0ed3
サーボの角度を調整
n4o847 fa45ea1
APS を設置、実機で確認
n4o847 d16eb08
駅を一旦除いて安定性を確認
n4o847 eb8f230
Merge branch 'main' into feature/ptcs-update-4
n4o847 9f78cc1
Commit from GitHub Actions (Build and commit ptcs_ui)
github-actions[bot] b426122
voltage を統合
n4o847 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,33 @@ | ||
import asyncio | ||
|
||
from .train_base import TrainBase | ||
from .wire_pole_client import WirePoleClient | ||
|
||
|
||
class Bridge2: | ||
trains: dict[str, TrainBase] | ||
obstacles: dict[str, WirePoleClient] | ||
|
||
def __init__(self) -> None: | ||
self.trains = {} | ||
self.obstacles = {} | ||
|
||
def add_train(self, train: TrainBase) -> None: | ||
assert train.id not in self.trains | ||
self.trains[train.id] = train | ||
|
||
def add_obstacle(self, obstacle: WirePoleClient) -> None: | ||
assert obstacle.id not in self.obstacles | ||
self.obstacles[obstacle.id] = obstacle | ||
|
||
async def connect_all(self) -> None: | ||
await asyncio.gather(*(train.connect() for train in self.trains.values())) | ||
await asyncio.gather( | ||
*(train.connect() for train in self.trains.values()), | ||
*(obstacle.connect() for obstacle in self.obstacles.values()), | ||
) | ||
|
||
async def disconnect_all(self) -> None: | ||
await asyncio.gather(*(train.disconnect() for train in self.trains.values())) | ||
await asyncio.gather( | ||
*(train.disconnect() for train in self.trains.values()), | ||
*(obstacle.disconnect() for obstacle in self.obstacles.values()), | ||
) |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import logging | ||
from typing import Callable | ||
from uuid import UUID | ||
|
||
from bleak import BleakClient | ||
from bleak.backends.characteristic import BleakGATTCharacteristic | ||
|
||
NotifyCollapseCallback = Callable[["WirePoleClient", bool], None] | ||
|
||
|
||
SERVICE_WIRE_POLE_UUID = UUID("62dd9b52-2995-7978-82e2-6abf1ae56555") | ||
CHARACTERISTIC_COLLAPSE_UUID = UUID("79fe0b5c-754c-3fe0-941f-3dc191cf09bf") | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class WirePoleClient: | ||
id: str | ||
_client: BleakClient | ||
|
||
def __init__(self, id: str, address: str) -> None: | ||
self.id = id | ||
self._client = BleakClient(address) | ||
|
||
def __str__(self) -> str: | ||
return f"WirePoleClient({self.id}, {self._client.address})" | ||
|
||
async def connect(self) -> None: | ||
await self._client.connect() | ||
logger.info("%s connected", self) | ||
|
||
async def disconnect(self) -> None: | ||
await self._client.disconnect() | ||
logger.info("%s disconnected", self) | ||
|
||
async def start_notify_collapse(self, callback: NotifyCollapseCallback) -> None: | ||
def wrapped_callback(_characteristic: BleakGATTCharacteristic, data: bytearray): | ||
assert len(data) == 1 | ||
is_collapsed = bool(data[0]) | ||
logger.info("%s notify collapse %s", self, is_collapsed) | ||
callback(self, is_collapsed) | ||
|
||
service = self._client.services.get_service(SERVICE_WIRE_POLE_UUID) | ||
assert service is not None | ||
characteristic = service.get_characteristic(CHARACTERISTIC_COLLAPSE_UUID) | ||
assert characteristic is not None | ||
|
||
await self._client.start_notify(characteristic, wrapped_callback) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import platform | ||
|
||
from ptcs_bridge.bridge2 import Bridge2 | ||
from ptcs_bridge.train_client import TrainClient | ||
from ptcs_bridge.train_simulator import TrainSimulator | ||
from ptcs_bridge.wire_pole_client import WirePoleClient | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [flake8] <401> reported by reviewdog 🐶 |
||
|
||
if platform.system() == "Windows": | ||
ADDRESS_T0 = "e0:5a:1b:e2:7a:f2" | ||
ADDRESS_T1 = "94:b5:55:84:15:42" | ||
ADDRESS_T2 = "e0:5a:1b:e2:7b:1e" | ||
ADDRESS_T3 = "1c:9d:c2:66:84:32" | ||
ADDRESS_T4 = "24:4c:ab:f5:c6:3e" | ||
elif platform.system() == "Darwin": | ||
ADDRESS_T0 = "00B55AE6-34AA-23C2-8C7B-8C11E6998E12" | ||
ADDRESS_T1 = "F2158243-18BB-D34C-88BC-F8F193CAD15E" | ||
ADDRESS_T2 = "EB57E065-90A0-B6D0-98BA-81096FA5765E" | ||
ADDRESS_T3 = "4AA3AAE5-A039-8484-013C-32AD94F50BE0" | ||
ADDRESS_T4 = "FC44FB3F-CF7D-084C-EA29-7AFD10C47A57" | ||
else: | ||
raise Exception(f"{platform.system()} not supported") | ||
|
||
|
||
def create_bridge() -> Bridge2: | ||
bridge = Bridge2() | ||
bridge.add_train(TrainSimulator("t0")) | ||
# bridge.add_train(TrainClient("t0", ADDRESS_T0)) | ||
bridge.add_train(TrainSimulator("t1")) | ||
bridge.add_train(TrainSimulator("t2")) | ||
bridge.add_train(TrainSimulator("t3")) | ||
bridge.add_train(TrainSimulator("t4")) | ||
# bridge.add_obstacle(WirePoleClient("obstacle_0", "24:62:AB:E3:67:9A")) | ||
return bridge |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[flake8] <401> reported by reviewdog 🐶
'ptcs_bridge.train_client.TrainClient' imported but unused