profexpo-gbt 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of profexpo-gbt might be problematic. Click here for more details.

@@ -0,0 +1,29 @@
1
+ Metadata-Version: 2.3
2
+ Name: profexpo-gbt
3
+ Version: 0.1.0
4
+ Summary: Event web control panel for Geoscan rovers
5
+ Author: r.lazarev
6
+ Author-email: r.lazarev <r.lazarev@geoscan.ru>
7
+ Requires-Dist: aiohttp>=3.10
8
+ Requires-Dist: grpcio>=1.70
9
+ Requires-Dist: geodrive-proto>=0.2.3
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+
13
+ # profexpo-gbt
14
+
15
+ Упрощённый веб-пульт для управления роботом на мероприятии. Панель поднимается локально, управление и телеметрия идут через Geodrive, видео берётся напрямую с MediaMTX робота по WHEP.
16
+
17
+ ```bash
18
+ uv tool install profexpo-gbt
19
+ web-control 192.168.50.151
20
+ ```
21
+
22
+ Либо запуск в окружении проекта:
23
+
24
+ ```bash
25
+ uv add profexpo-gbt
26
+ uv run web-control 192.168.50.151
27
+ ```
28
+
29
+ Откройте `http://localhost:8080`. Видео подключается по адресу `http://<IP-робота>:8889/maincamera/whep`. Для установки из локального checkout: `uv tool install .` или `pip install .` из этой директории.
@@ -0,0 +1,17 @@
1
+ # profexpo-gbt
2
+
3
+ Упрощённый веб-пульт для управления роботом на мероприятии. Панель поднимается локально, управление и телеметрия идут через Geodrive, видео берётся напрямую с MediaMTX робота по WHEP.
4
+
5
+ ```bash
6
+ uv tool install profexpo-gbt
7
+ web-control 192.168.50.151
8
+ ```
9
+
10
+ Либо запуск в окружении проекта:
11
+
12
+ ```bash
13
+ uv add profexpo-gbt
14
+ uv run web-control 192.168.50.151
15
+ ```
16
+
17
+ Откройте `http://localhost:8080`. Видео подключается по адресу `http://<IP-робота>:8889/maincamera/whep`. Для установки из локального checkout: `uv tool install .` или `pip install .` из этой директории.
@@ -0,0 +1,27 @@
1
+ [project]
2
+ name = "profexpo-gbt"
3
+ version = "0.1.0"
4
+ description = "Event web control panel for Geoscan rovers"
5
+ readme = "README.md"
6
+ requires-python = ">=3.10"
7
+ dependencies = [
8
+ "aiohttp>=3.10",
9
+ "grpcio>=1.70",
10
+ "geodrive-proto>=0.2.3",
11
+ ]
12
+
13
+ [[project.authors]]
14
+ name = "r.lazarev"
15
+ email = "r.lazarev@geoscan.ru"
16
+
17
+ [project.scripts]
18
+ web-control = "profexpo_gbt.cli:main"
19
+
20
+ [tool.uv.build-backend]
21
+ module-name = "profexpo_gbt"
22
+ module-root = "src"
23
+ source-include = ["src/profexpo_gbt/web_ui/**/*"]
24
+
25
+ [build-system]
26
+ requires = ["uv_build>=0.13.6,<0.14.0"]
27
+ build-backend = "uv_build"
@@ -0,0 +1,22 @@
1
+ [project]
2
+ name = "profexpo-gbt"
3
+ version = "0.1.0"
4
+ description = "Event web control panel for Geoscan rovers"
5
+ readme = "README.md"
6
+ authors = [
7
+ { name = "r.lazarev", email = "r.lazarev@geoscan.ru" }
8
+ ]
9
+ requires-python = ">=3.10"
10
+ dependencies = ["aiohttp>=3.10", "grpcio>=1.70", "geodrive-proto>=0.2.3"]
11
+
12
+ [project.scripts]
13
+ web-control = "profexpo_gbt.cli:main"
14
+
15
+ [tool.uv.build-backend]
16
+ module-name = "profexpo_gbt"
17
+ module-root = "src"
18
+ source-include = ["src/profexpo_gbt/web_ui/**/*"]
19
+
20
+ [build-system]
21
+ requires = ["uv_build>=0.13.6,<0.14.0"]
22
+ build-backend = "uv_build"
@@ -0,0 +1 @@
1
+ """Profexpo event control panel."""
@@ -0,0 +1,74 @@
1
+ """Run the compact event control panel."""
2
+
3
+ import argparse
4
+ import asyncio
5
+ import ipaddress
6
+ import json
7
+ from pathlib import Path
8
+
9
+ import grpc
10
+ from aiohttp import web
11
+ from geodrive_proto import Empty, RCChannelsCommand, RoverServiceStub
12
+
13
+
14
+ async def serve(robot_ip: str) -> None:
15
+ channel = grpc.aio.insecure_channel(f"{robot_ip}:5656")
16
+ stub = RoverServiceStub(channel)
17
+ try:
18
+ await asyncio.wait_for(stub.get_status(Empty()), timeout=5)
19
+ except Exception as exc:
20
+ await channel.close()
21
+ raise RuntimeError(f"Не удалось подключиться к роботу {robot_ip}: {exc}") from exc
22
+
23
+ async def index(_request):
24
+ html = (Path(__file__).parent / "panel.html").read_text(encoding="utf-8")
25
+ return web.Response(
26
+ text=html.replace("__ROBOT_IP__", robot_ip),
27
+ content_type="text/html",
28
+ )
29
+
30
+ async def websocket(request):
31
+ ws = web.WebSocketResponse()
32
+ await ws.prepare(request)
33
+ channels = {"channel1": 1500, "channel2": 1500, "channel3": 1500, "channel4": 1500}
34
+ try:
35
+ async def commands():
36
+ while not ws.closed:
37
+ yield RCChannelsCommand(**channels)
38
+ await asyncio.sleep(0.05)
39
+
40
+ stream = asyncio.create_task(_consume_rc(stub, commands()))
41
+ async for msg in ws:
42
+ if msg.type == web.WSMsgType.TEXT:
43
+ data = json.loads(msg.data)
44
+ channels.update({key: int(data.get(key, 1500)) for key in channels})
45
+ stream.cancel()
46
+ await asyncio.gather(stream, return_exceptions=True)
47
+ finally:
48
+ channels.update({key: 1500 for key in channels})
49
+ return ws
50
+
51
+ app = web.Application()
52
+ app.router.add_get("/", index)
53
+ app.router.add_get("/control", websocket)
54
+ runner = web.AppRunner(app)
55
+ await runner.setup()
56
+ site = web.TCPSite(runner, "0.0.0.0", 8080)
57
+ await site.start()
58
+ print(f"Панель управления: http://localhost:8080 (робот {robot_ip})")
59
+ try:
60
+ await asyncio.Future()
61
+ finally:
62
+ await runner.cleanup()
63
+ await channel.close()
64
+
65
+
66
+ async def _consume_rc(stub, commands):
67
+ async for _ in stub.stream_rc_channels(commands):
68
+ pass
69
+
70
+
71
+ def main() -> None:
72
+ parser = argparse.ArgumentParser(description="Минимальный WASD-пульт Geoscan")
73
+ parser.add_argument("robot_ip", type=ipaddress.ip_address)
74
+ asyncio.run(serve(str(parser.parse_args().robot_ip)))
@@ -0,0 +1,24 @@
1
+ <!doctype html>
2
+ <html lang="ru"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Profexpo · управление роботом</title>
3
+ <style>
4
+ *{box-sizing:border-box}body{margin:0;background:#101317;color:white;font:16px system-ui,sans-serif}video{position:fixed;inset:0;width:100%;height:100%;object-fit:cover;background:#08090b}.shade{position:fixed;inset:0;background:linear-gradient(90deg,#090b0dbb,transparent 65%),linear-gradient(0deg,#090b0d99,transparent 35%);pointer-events:none}.head,.controls,.hint{position:fixed;z-index:2}.head{top:24px;left:28px;background:#111a;padding:14px 20px;border:1px solid #ffffff22;border-radius:10px}.head b{letter-spacing:.12em}.status{font-size:13px;color:#aaa;margin-top:4px}.controls{left:50%;bottom:42px;transform:translateX(-50%);display:grid;grid-template-columns:repeat(3,64px);gap:8px}.key{height:58px;border:1px solid #ffffff55;border-radius:10px;background:#171b20dd;color:white;font-size:20px}.key.active{background:#ff6d1b}.hint{right:24px;bottom:20px;color:#ddd;text-shadow:0 1px 4px #000}.blank{visibility:hidden}@media(max-width:600px){.head{top:12px;left:12px}.controls{bottom:55px}.hint{right:10px;font-size:12px}}
5
+ </style></head><body>
6
+ <video id="video" autoplay muted playsinline></video><div class="shade"></div><div class="head"><b>PROFEXPO · WEB CONTROL</b><div class="status" id="status">Подключение…</div></div>
7
+ <div class="controls"><button class="key blank"></button><button class="key" data-key="w">W</button><button class="key blank"></button><button class="key" data-key="a">A</button><button class="key" data-key="s">S</button><button class="key" data-key="d">D</button></div><div class="hint">WASD / стрелки · геймпад: левый стик</div>
8
+ <script>
9
+ const statusEl=document.querySelector('#status'), video=document.querySelector('#video');let socket,held=new Set(),gamepad=null;
10
+ const neutral=()=>({channel1:1500,channel2:1500,channel3:1500,channel4:1500});
11
+ function send(){if(!socket||socket.readyState!==1)return;const c=neutral();if(gamepad){c.channel1=gamepad.channel1;c.channel3=gamepad.channel3}if(held.has('a'))c.channel1=2000;if(held.has('d'))c.channel1=1000;if(held.has('w'))c.channel3=1000;if(held.has('s'))c.channel3=2000;socket.send(JSON.stringify(c))}
12
+ function press(k,on){k=k.toLowerCase();if(!'wasd'.includes(k))return;if(on)held.add(k);else held.delete(k);document.querySelector(`[data-key="${k}"]`)?.classList.toggle('active',held.has(k));send()}
13
+ document.querySelectorAll('[data-key]').forEach(b=>{b.onpointerdown=e=>{e.preventDefault();press(b.dataset.key,true)};for(const ev of ['pointerup','pointercancel','pointerleave'])b.addEventListener(ev,()=>press(b.dataset.key,false))});
14
+ window.addEventListener('keydown',e=>{if(['ArrowUp','ArrowDown','ArrowLeft','ArrowRight'].includes(e.key))e.preventDefault();press(({ArrowUp:'w',ArrowDown:'s',ArrowLeft:'a',ArrowRight:'d'})[e.key]||e.key,true)});
15
+ window.addEventListener('keyup',e=>press(({ArrowUp:'w',ArrowDown:'s',ArrowLeft:'a',ArrowRight:'d'})[e.key]||e.key,false));window.addEventListener('blur',()=>{held.clear();send()});
16
+ const deadZone=value=>{if(Math.abs(value)<0.08)return 0;return Math.sign(value)*(Math.abs(value)-0.08)/0.92};
17
+ const pwm=value=>Math.round(1500+Math.max(-1,Math.min(1,value))*500);
18
+ window.addEventListener('gamepaddisconnected',()=>{gamepad=null;statusEl.textContent='Геймпад отключён';send()});
19
+ function pollGamepad(){const pad=Array.from(navigator.getGamepads?.()||[]).find(p=>p?.connected);if(pad){const steer=deadZone(pad.axes[3]||0),throttle=deadZone(pad.axes[2]||0);gamepad={channel1:pwm(steer),channel3:pwm(-throttle)};if(statusEl.textContent!=='Управление подключено · геймпад')statusEl.textContent='Управление подключено · геймпад';send()}else if(gamepad){gamepad=null;statusEl.textContent='Управление подключено';send()}requestAnimationFrame(pollGamepad)}
20
+ window.addEventListener('gamepadconnected',()=>{statusEl.textContent='Геймпад подключён'});requestAnimationFrame(pollGamepad);
21
+ function control(){socket=new WebSocket(`ws://${location.host}/control`);socket.onopen=()=>{statusEl.textContent='Управление подключено';send()};socket.onclose=()=>{statusEl.textContent='Нет связи · переподключение';setTimeout(control,1500)};socket.onerror=()=>socket.close()}
22
+ async function videoConnect(){const pc=new RTCPeerConnection();pc.addTransceiver('video',{direction:'recvonly'});pc.ontrack=e=>video.srcObject=e.streams[0]||new MediaStream([e.track]);try{await pc.setLocalDescription(await pc.createOffer());await new Promise(resolve=>{if(pc.iceGatheringState==='complete')return resolve();pc.onicegatheringstatechange=()=>pc.iceGatheringState==='complete'&&resolve();setTimeout(resolve,1200)});const r=await fetch('http://__ROBOT_IP__:8889/maincamera/whep',{method:'POST',headers:{'Content-Type':'application/sdp'},body:pc.localDescription.sdp});if(!r.ok)throw Error(`WHEP HTTP ${r.status}`);await pc.setRemoteDescription({type:'answer',sdp:await r.text()})}catch(e){statusEl.textContent=`Видео недоступно: ${e.message}`;setTimeout(videoConnect,3000)}}
23
+ control();videoConnect();
24
+ </script></body></html>
File without changes