diff --git a/new_shit/python/modules/__pycache__/sketchy_machine_motion.cpython-312.pyc b/new_shit/python/modules/__pycache__/sketchy_machine_motion.cpython-312.pyc index c050e9984643295899d81ccd19222b753ca0f7d3..7b0ec9a15f2607c2387b0ee53f37bbd5438c34a2 100644 Binary files a/new_shit/python/modules/__pycache__/sketchy_machine_motion.cpython-312.pyc and b/new_shit/python/modules/__pycache__/sketchy_machine_motion.cpython-312.pyc differ diff --git a/new_shit/python/modules/sketchy_machine_motion.py b/new_shit/python/modules/sketchy_machine_motion.py index 979c149a7f4a145568e76035462dc9d7fbd6edc0..f2d4ab23da435a5cc5c798f8785f619d38f57a15 100644 --- a/new_shit/python/modules/sketchy_machine_motion.py +++ b/new_shit/python/modules/sketchy_machine_motion.py @@ -106,8 +106,8 @@ class SketchyMachineMotion: print_point_transmits = False ), self.queue_planner) - print("Machine / Begin: Waiting for Clocks... ") - await asyncio.sleep(3) + # print("Machine / Begin: Waiting for Clocks... ") + # await asyncio.sleep(3) print("Machine / Begin: Startup MAXL... ") await self._maxl_core.begin() print("Machine / Begin: ... done ") diff --git a/new_shit/python/osap/discovery/__pycache__/netrunner.cpython-312.pyc b/new_shit/python/osap/discovery/__pycache__/netrunner.cpython-312.pyc index 88bfedf68eb77387609d05b1c05334d640bc93d0..2b06e7c3319397c53337764e82055f0607a4b799 100644 Binary files a/new_shit/python/osap/discovery/__pycache__/netrunner.cpython-312.pyc and b/new_shit/python/osap/discovery/__pycache__/netrunner.cpython-312.pyc differ diff --git a/new_shit/python/osap/discovery/__pycache__/netrunner_atomics.cpython-312.pyc b/new_shit/python/osap/discovery/__pycache__/netrunner_atomics.cpython-312.pyc index 34b271659caa5f2882355794d712590f0b51359e..f1cd9586d00161a3f627c4c706ae274c90d31e1d 100644 Binary files a/new_shit/python/osap/discovery/__pycache__/netrunner_atomics.cpython-312.pyc and b/new_shit/python/osap/discovery/__pycache__/netrunner_atomics.cpython-312.pyc differ diff --git a/new_shit/python/osap/discovery/netrunner.py b/new_shit/python/osap/discovery/netrunner.py index 00f4f120a4f29901b54258334da8ab1a2dbd5424..9c23b019bc941140937550d4545bb965457f2d56 100644 --- a/new_shit/python/osap/discovery/netrunner.py +++ b/new_shit/python/osap/discovery/netrunner.py @@ -1,8 +1,9 @@ +import asyncio from dataclasses import dataclass from typing import List, TYPE_CHECKING from osap.packets.routes import Route, route_build from ..utils.keys import PacketKeys -from ..utils.time_utils import get_millisecond_timestamp +from ..utils.time_utils import get_millisecond_timestamp, get_microsecond_timestamp from ..utils.random_gen import random_four_byte_write_new, random_four_byte_check_match from .netrunner_atomics import LinkGatewayInfoResponse, NetRunnerAtomics, PortInfoResponse, RTInfoResponse @@ -178,3 +179,52 @@ class NetRunner: finally: self.map_discovery_is_running = False + + # end update_map + + # properly, this would add a metric for clock stability as well... + async def await_time_settle(self, print_updates = False, await_spread_epsilon_us = 1000): + skew_alpha = 0.95 # fw default is 0.95 + p_gain = 0.000001 # fw default is 0.000001, minimum gain is 0.0000003 + + if self.map_completion_time == 0 or len(self.map.runtimes) == 1: + return + + # initialize settings for each device... + for d, device in enumerate(self.map.runtimes): + if device.protocol_build == 'Python': + continue + + # basically get everyone on-time and with 1.0 skew to start even keeled, + now = get_microsecond_timestamp() + await self.atomics.set_time_config(device.route, now, 1.0, skew_alpha, p_gain, True) + + ok_cycle_count = 0 + ok_cycle_pass = 3 + + # now run a loop where we poll each, get a grouping... and post it ? + while True: + clock_errors = [] + rtts = [] + for d, device in enumerate(self.map.runtimes): + if device.protocol_build == 'Python': + continue + + our_time = get_microsecond_timestamp() + time_stats = await self.atomics.get_time_config(device.route) + device_time = time_stats.system_time - time_stats.rtt / 2 + clock_errors.append(our_time - device_time) + rtts.append(time_stats.rtt) + + print(F"ERRS: {[int(err) for err in clock_errors]}, \tRTT: {[int(rtt) for rtt in rtts]}") + + if all(abs(err) < await_spread_epsilon_us for err in clock_errors): + ok_cycle_count += 1 + else: + ok_cycle_count = 0 + + if ok_cycle_count >= ok_cycle_pass: + print("CLOCKS OK...") + return + else: + await asyncio.sleep(0.25) \ No newline at end of file diff --git a/new_shit/python/sketchy.py b/new_shit/python/sketchy.py index 01669115f0171c99c2b2629d9125c02b9b0d3ce1..ed810e4077f2ee73cd5f22026d07d78825b4fa8e 100644 --- a/new_shit/python/sketchy.py +++ b/new_shit/python/sketchy.py @@ -47,9 +47,14 @@ async def main(): # ... clip 21500, seems like where the fuckups start... # parser = GCodeParser("test_files/3DBenchy_Top.gcode") + print("---------------------------------- collect system ...") + system_map = await osap.netrunner.update_map() system_map.print() + print("---------------------------------- wait for clocks to settle ...") + await osap.netrunner.await_time_settle(print_updates=True) + print("---------------------------------- machine setup ...") machine = SketchyMachineMotion(osap, system_interpolation_interval, system_twin_to_real_ms, extents = machine_extents) await machine.begin() diff --git a/new_shit/python/svg/__pycache__/svg_tools.cpython-312.pyc b/new_shit/python/svg/__pycache__/svg_tools.cpython-312.pyc index e3602598f511f236206844cba7ef9fe04ed31b45..d046940946d8c5a0a97924032433152b4569930f 100644 Binary files a/new_shit/python/svg/__pycache__/svg_tools.cpython-312.pyc and b/new_shit/python/svg/__pycache__/svg_tools.cpython-312.pyc differ