diff --git a/logs/gcode_commands.log b/logs/gcode_commands.log index f930be6..9276e10 100644 --- a/logs/gcode_commands.log +++ b/logs/gcode_commands.log @@ -2513,3 +2513,11 @@ 2026-04-20T13:21:53.153Z ::ffff:172.21.0.5: G91 G1 Y-5 F100 2026-04-20T13:21:59.310Z ::ffff:172.21.0.5: G91 G1 Y5 F100 2026-04-20T13:22:03.991Z ::ffff:172.21.0.5: G91 G1 Y5 F100 +2026-04-20T13:44:08.329Z ::ffff:172.21.0.5: FShow +2026-04-20T13:44:18.817Z ::ffff:172.21.0.5: G28 +2026-04-20T13:44:27.274Z ::ffff:172.21.0.5: G91 G1 Y-10 F100 +2026-04-20T13:44:27.492Z ::ffff:172.21.0.5: G91 G1 Y-10 F100 +2026-04-20T14:04:27.382Z ::ffff:172.21.0.5: FShow +2026-04-20T14:04:29.744Z ::ffff:172.21.0.5: G28 +2026-04-20T14:05:42.215Z ::ffff:172.21.0.5: FShow +2026-04-20T14:05:43.968Z ::ffff:172.21.0.5: G91 G1 Y-5 F100 diff --git a/logs/pings.log b/logs/pings.log index 613a358..0ca9392 100644 --- a/logs/pings.log +++ b/logs/pings.log @@ -11680,3 +11680,259 @@ 2026-04-20T13:22:52.097Z ::ffff:172.21.0.5: Ping 2026-04-20T13:22:57.088Z ::ffff:172.21.0.5: Ping 2026-04-20T13:23:02.101Z ::ffff:172.21.0.5: Ping +2026-04-20T13:23:07.095Z ::ffff:172.21.0.5: Ping +2026-04-20T13:23:12.094Z ::ffff:172.21.0.5: Ping +2026-04-20T13:23:17.095Z ::ffff:172.21.0.5: Ping +2026-04-20T13:23:22.091Z ::ffff:172.21.0.5: Ping +2026-04-20T13:23:27.090Z ::ffff:172.21.0.5: Ping +2026-04-20T13:23:32.098Z ::ffff:172.21.0.5: Ping +2026-04-20T13:23:37.095Z ::ffff:172.21.0.5: Ping +2026-04-20T13:23:42.086Z ::ffff:172.21.0.5: Ping +2026-04-20T13:23:47.095Z ::ffff:172.21.0.5: Ping +2026-04-20T13:23:52.091Z ::ffff:172.21.0.5: Ping +2026-04-20T13:23:57.093Z ::ffff:172.21.0.5: Ping +2026-04-20T13:24:02.092Z ::ffff:172.21.0.5: Ping +2026-04-20T13:24:07.105Z ::ffff:172.21.0.5: Ping +2026-04-20T13:24:12.101Z ::ffff:172.21.0.5: Ping +2026-04-20T13:24:17.097Z ::ffff:172.21.0.5: Ping +2026-04-20T13:24:22.103Z ::ffff:172.21.0.5: Ping +2026-04-20T13:24:27.103Z ::ffff:172.21.0.5: Ping +2026-04-20T13:24:32.097Z ::ffff:172.21.0.5: Ping +2026-04-20T13:24:37.101Z ::ffff:172.21.0.5: Ping +2026-04-20T13:24:42.096Z ::ffff:172.21.0.5: Ping +2026-04-20T13:24:47.087Z ::ffff:172.21.0.5: Ping +2026-04-20T13:24:52.087Z ::ffff:172.21.0.5: Ping +2026-04-20T13:24:57.088Z ::ffff:172.21.0.5: Ping +2026-04-20T13:25:02.087Z ::ffff:172.21.0.5: Ping +2026-04-20T13:25:07.097Z ::ffff:172.21.0.5: Ping +2026-04-20T13:25:12.091Z ::ffff:172.21.0.5: Ping +2026-04-20T13:25:17.091Z ::ffff:172.21.0.5: Ping +2026-04-20T13:25:22.091Z ::ffff:172.21.0.5: Ping +2026-04-20T13:25:27.091Z ::ffff:172.21.0.5: Ping +2026-04-20T13:25:32.093Z ::ffff:172.21.0.5: Ping +2026-04-20T13:25:37.089Z ::ffff:172.21.0.5: Ping +2026-04-20T13:25:42.099Z ::ffff:172.21.0.5: Ping +2026-04-20T13:25:47.096Z ::ffff:172.21.0.5: Ping +2026-04-20T13:25:52.096Z ::ffff:172.21.0.5: Ping +2026-04-20T13:25:57.101Z ::ffff:172.21.0.5: Ping +2026-04-20T13:26:02.097Z ::ffff:172.21.0.5: Ping +2026-04-20T13:26:07.095Z ::ffff:172.21.0.5: Ping +2026-04-20T13:26:12.098Z ::ffff:172.21.0.5: Ping +2026-04-20T13:26:17.093Z ::ffff:172.21.0.5: Ping +2026-04-20T13:26:22.095Z ::ffff:172.21.0.5: Ping +2026-04-20T13:26:28.740Z ::ffff:172.21.0.5: Ping +2026-04-20T13:26:32.089Z ::ffff:172.21.0.5: Ping +2026-04-20T13:26:37.092Z ::ffff:172.21.0.5: Ping +2026-04-20T13:26:42.089Z ::ffff:172.21.0.5: Ping +2026-04-20T13:26:47.085Z ::ffff:172.21.0.5: Ping +2026-04-20T13:26:52.091Z ::ffff:172.21.0.5: Ping +2026-04-20T13:26:57.093Z ::ffff:172.21.0.5: Ping +2026-04-20T13:27:02.091Z ::ffff:172.21.0.5: Ping +2026-04-20T13:27:07.094Z ::ffff:172.21.0.5: Ping +2026-04-20T13:27:12.088Z ::ffff:172.21.0.5: Ping +2026-04-20T13:27:17.089Z ::ffff:172.21.0.5: Ping +2026-04-20T13:27:22.098Z ::ffff:172.21.0.5: Ping +2026-04-20T13:27:27.096Z ::ffff:172.21.0.5: Ping +2026-04-20T13:27:32.099Z ::ffff:172.21.0.5: Ping +2026-04-20T13:27:37.095Z ::ffff:172.21.0.5: Ping +2026-04-20T13:27:42.580Z ::ffff:172.21.0.5: Ping +2026-04-20T13:27:47.590Z ::ffff:172.21.0.5: Ping +2026-04-20T13:27:52.577Z ::ffff:172.21.0.5: Ping +2026-04-20T13:27:57.590Z ::ffff:172.21.0.5: Ping +2026-04-20T13:28:02.590Z ::ffff:172.21.0.5: Ping +2026-04-20T13:28:07.594Z ::ffff:172.21.0.5: Ping +2026-04-20T13:28:12.589Z ::ffff:172.21.0.5: Ping +2026-04-20T13:28:17.591Z ::ffff:172.21.0.5: Ping +2026-04-20T13:28:22.585Z ::ffff:172.21.0.5: Ping +2026-04-20T13:28:27.583Z ::ffff:172.21.0.5: Ping +2026-04-20T13:28:32.582Z ::ffff:172.21.0.5: Ping +2026-04-20T13:28:37.588Z ::ffff:172.21.0.5: Ping +2026-04-20T13:28:47.587Z ::ffff:172.21.0.5: Ping +2026-04-20T13:29:47.580Z ::ffff:172.21.0.5: Ping +2026-04-20T13:29:52.083Z ::ffff:172.21.0.5: Ping +2026-04-20T13:29:57.096Z ::ffff:172.21.0.5: Ping +2026-04-20T13:30:02.090Z ::ffff:172.21.0.5: Ping +2026-04-20T13:30:07.089Z ::ffff:172.21.0.5: Ping +2026-04-20T13:30:12.083Z ::ffff:172.21.0.5: Ping +2026-04-20T13:30:17.093Z ::ffff:172.21.0.5: Ping +2026-04-20T13:30:22.099Z ::ffff:172.21.0.5: Ping +2026-04-20T13:30:27.583Z ::ffff:172.21.0.5: Ping +2026-04-20T13:30:32.586Z ::ffff:172.21.0.5: Ping +2026-04-20T13:30:37.597Z ::ffff:172.21.0.5: Ping +2026-04-20T13:30:42.576Z ::ffff:172.21.0.5: Ping +2026-04-20T13:30:47.591Z ::ffff:172.21.0.5: Ping +2026-04-20T13:30:52.584Z ::ffff:172.21.0.5: Ping +2026-04-20T13:30:57.586Z ::ffff:172.21.0.5: Ping +2026-04-20T13:31:02.585Z ::ffff:172.21.0.5: Ping +2026-04-20T13:31:07.587Z ::ffff:172.21.0.5: Ping +2026-04-20T13:31:12.579Z ::ffff:172.21.0.5: Ping +2026-04-20T13:31:17.593Z ::ffff:172.21.0.5: Ping +2026-04-20T13:31:22.588Z ::ffff:172.21.0.5: Ping +2026-04-20T13:31:47.602Z ::ffff:172.21.0.5: Ping +2026-04-20T13:32:47.623Z ::ffff:172.21.0.5: Ping +2026-04-20T13:33:47.575Z ::ffff:172.21.0.5: Ping +2026-04-20T13:34:47.639Z ::ffff:172.21.0.5: Ping +2026-04-20T13:35:47.595Z ::ffff:172.21.0.5: Ping +2026-04-20T13:36:11.297Z ::ffff:172.21.0.5: Ping +2026-04-20T13:36:12.156Z ::ffff:172.21.0.5: Ping +2026-04-20T13:36:17.588Z ::ffff:172.21.0.5: Ping +2026-04-20T13:36:22.192Z ::ffff:172.21.0.5: Ping +2026-04-20T13:36:27.619Z ::ffff:172.21.0.5: Ping +2026-04-20T13:36:32.635Z ::ffff:172.21.0.5: Ping +2026-04-20T13:36:37.346Z ::ffff:172.21.0.5: Ping +2026-04-20T13:36:42.108Z ::ffff:172.21.0.5: Ping +2026-04-20T13:36:47.080Z ::ffff:172.21.0.5: Ping +2026-04-20T13:36:52.119Z ::ffff:172.21.0.5: Ping +2026-04-20T13:36:57.136Z ::ffff:172.21.0.5: Ping +2026-04-20T13:37:02.581Z ::ffff:172.21.0.5: Ping +2026-04-20T13:37:07.581Z ::ffff:172.21.0.5: Ping +2026-04-20T13:37:12.577Z ::ffff:172.21.0.5: Ping +2026-04-20T13:37:17.583Z ::ffff:172.21.0.5: Ping +2026-04-20T13:37:22.583Z ::ffff:172.21.0.5: Ping +2026-04-20T13:37:27.586Z ::ffff:172.21.0.5: Ping +2026-04-20T13:37:32.575Z ::ffff:172.21.0.5: Ping +2026-04-20T13:37:37.588Z ::ffff:172.21.0.5: Ping +2026-04-20T13:37:42.582Z ::ffff:172.21.0.5: Ping +2026-04-20T13:37:47.587Z ::ffff:172.21.0.5: Ping +2026-04-20T13:37:52.586Z ::ffff:172.21.0.5: Ping +2026-04-20T13:37:57.589Z ::ffff:172.21.0.5: Ping +2026-04-20T13:38:47.618Z ::ffff:172.21.0.5: Ping +2026-04-20T13:39:47.579Z ::ffff:172.21.0.5: Ping +2026-04-20T13:40:47.580Z ::ffff:172.21.0.5: Ping +2026-04-20T13:41:47.582Z ::ffff:172.21.0.5: Ping +2026-04-20T13:42:47.579Z ::ffff:172.21.0.5: Ping +2026-04-20T13:43:47.591Z ::ffff:172.21.0.5: Ping +2026-04-20T13:44:13.583Z ::ffff:172.21.0.5: Ping +2026-04-20T13:44:18.131Z ::ffff:172.21.0.5: Ping +2026-04-20T13:44:23.589Z ::ffff:172.21.0.5: Ping +2026-04-20T13:44:28.136Z ::ffff:172.21.0.5: Ping +2026-04-20T13:44:33.591Z ::ffff:172.21.0.5: Ping +2026-04-20T13:44:38.583Z ::ffff:172.21.0.5: Ping +2026-04-20T13:44:43.590Z ::ffff:172.21.0.5: Ping +2026-04-20T13:44:47.581Z ::ffff:172.21.0.5: Ping +2026-04-20T13:44:48.584Z ::ffff:172.21.0.5: Ping +2026-04-20T13:44:53.593Z ::ffff:172.21.0.5: Ping +2026-04-20T13:44:57.184Z ::ffff:172.21.0.5: Ping +2026-04-20T13:44:58.591Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:02.113Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:03.585Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:07.620Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:08.609Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:12.587Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:13.589Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:17.572Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:18.580Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:22.584Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:23.583Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:27.578Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:28.587Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:32.588Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:37.576Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:42.577Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:47.582Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:47.583Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:52.586Z ::ffff:172.21.0.5: Ping +2026-04-20T13:45:57.582Z ::ffff:172.21.0.5: Ping +2026-04-20T13:46:02.579Z ::ffff:172.21.0.5: Ping +2026-04-20T13:46:47.582Z ::ffff:172.21.0.5: Ping +2026-04-20T13:46:47.583Z ::ffff:172.21.0.5: Ping +2026-04-20T13:47:11.752Z ::ffff:172.21.0.5: Ping +2026-04-20T13:47:13.127Z ::ffff:172.21.0.5: Ping +2026-04-20T13:47:18.580Z ::ffff:172.21.0.5: Ping +2026-04-20T13:47:23.585Z ::ffff:172.21.0.5: Ping +2026-04-20T13:47:28.579Z ::ffff:172.21.0.5: Ping +2026-04-20T13:47:33.579Z ::ffff:172.21.0.5: Ping +2026-04-20T13:47:38.585Z ::ffff:172.21.0.5: Ping +2026-04-20T13:47:43.581Z ::ffff:172.21.0.5: Ping +2026-04-20T13:47:47.592Z ::ffff:172.21.0.5: Ping +2026-04-20T13:47:48.588Z ::ffff:172.21.0.5: Ping +2026-04-20T13:47:53.573Z ::ffff:172.21.0.5: Ping +2026-04-20T13:47:58.572Z ::ffff:172.21.0.5: Ping +2026-04-20T13:48:03.596Z ::ffff:172.21.0.5: Ping +2026-04-20T13:48:08.592Z ::ffff:172.21.0.5: Ping +2026-04-20T13:48:47.580Z ::ffff:172.21.0.5: Ping +2026-04-20T13:48:47.580Z ::ffff:172.21.0.5: Ping +2026-04-20T13:48:53.306Z ::ffff:172.21.0.5: Ping +2026-04-20T13:48:58.583Z ::ffff:172.21.0.5: Ping +2026-04-20T13:49:03.581Z ::ffff:172.21.0.5: Ping +2026-04-20T13:49:08.586Z ::ffff:172.21.0.5: Ping +2026-04-20T13:49:13.577Z ::ffff:172.21.0.5: Ping +2026-04-20T13:49:18.574Z ::ffff:172.21.0.5: Ping +2026-04-20T13:49:23.579Z ::ffff:172.21.0.5: Ping +2026-04-20T13:49:28.585Z ::ffff:172.21.0.5: Ping +2026-04-20T13:49:33.587Z ::ffff:172.21.0.5: Ping +2026-04-20T13:49:38.571Z ::ffff:172.21.0.5: Ping +2026-04-20T13:49:43.586Z ::ffff:172.21.0.5: Ping +2026-04-20T13:49:47.577Z ::ffff:172.21.0.5: Ping +2026-04-20T13:49:48.582Z ::ffff:172.21.0.5: Ping +2026-04-20T13:49:53.576Z ::ffff:172.21.0.5: Ping +2026-04-20T13:50:47.584Z ::ffff:172.21.0.5: Ping +2026-04-20T13:50:47.585Z ::ffff:172.21.0.5: Ping +2026-04-20T13:51:47.575Z ::ffff:172.21.0.5: Ping +2026-04-20T13:51:47.576Z ::ffff:172.21.0.5: Ping +2026-04-20T13:52:47.581Z ::ffff:172.21.0.5: Ping +2026-04-20T13:52:47.582Z ::ffff:172.21.0.5: Ping +2026-04-20T13:53:47.572Z ::ffff:172.21.0.5: Ping +2026-04-20T13:53:47.573Z ::ffff:172.21.0.5: Ping +2026-04-20T13:54:47.575Z ::ffff:172.21.0.5: Ping +2026-04-20T13:54:47.587Z ::ffff:172.21.0.5: Ping +2026-04-20T13:55:47.577Z ::ffff:172.21.0.5: Ping +2026-04-20T13:55:47.578Z ::ffff:172.21.0.5: Ping +2026-04-20T13:56:47.575Z ::ffff:172.21.0.5: Ping +2026-04-20T13:56:47.576Z ::ffff:172.21.0.5: Ping +2026-04-20T13:57:47.575Z ::ffff:172.21.0.5: Ping +2026-04-20T13:57:47.575Z ::ffff:172.21.0.5: Ping +2026-04-20T13:58:47.576Z ::ffff:172.21.0.5: Ping +2026-04-20T13:58:47.577Z ::ffff:172.21.0.5: Ping +2026-04-20T13:59:43.698Z ::ffff:172.21.0.5: Ping +2026-04-20T13:59:47.585Z ::ffff:172.21.0.5: Ping +2026-04-20T13:59:48.584Z ::ffff:172.21.0.5: Ping +2026-04-20T13:59:53.577Z ::ffff:172.21.0.5: Ping +2026-04-20T13:59:58.581Z ::ffff:172.21.0.5: Ping +2026-04-20T14:00:03.578Z ::ffff:172.21.0.5: Ping +2026-04-20T14:00:08.585Z ::ffff:172.21.0.5: Ping +2026-04-20T14:00:13.585Z ::ffff:172.21.0.5: Ping +2026-04-20T14:00:18.583Z ::ffff:172.21.0.5: Ping +2026-04-20T14:00:23.578Z ::ffff:172.21.0.5: Ping +2026-04-20T14:00:28.572Z ::ffff:172.21.0.5: Ping +2026-04-20T14:00:33.585Z ::ffff:172.21.0.5: Ping +2026-04-20T14:00:38.580Z ::ffff:172.21.0.5: Ping +2026-04-20T14:00:43.579Z ::ffff:172.21.0.5: Ping +2026-04-20T14:00:47.579Z ::ffff:172.21.0.5: Ping +2026-04-20T14:01:47.579Z ::ffff:172.21.0.5: Ping +2026-04-20T14:01:47.580Z ::ffff:172.21.0.5: Ping +2026-04-20T14:02:47.575Z ::ffff:172.21.0.5: Ping +2026-04-20T14:02:47.577Z ::ffff:172.21.0.5: Ping +2026-04-20T14:03:44.276Z ::ffff:172.21.0.5: Ping +2026-04-20T14:03:47.582Z ::ffff:172.21.0.5: Ping +2026-04-20T14:03:48.582Z ::ffff:172.21.0.5: Ping +2026-04-20T14:03:58.589Z ::ffff:172.21.0.5: Ping +2026-04-20T14:04:03.150Z ::ffff:172.21.0.5: Ping +2026-04-20T14:04:32.576Z ::ffff:172.21.0.5: Ping +2026-04-20T14:04:37.574Z ::ffff:172.21.0.5: Ping +2026-04-20T14:04:42.572Z ::ffff:172.21.0.5: Ping +2026-04-20T14:04:47.577Z ::ffff:172.21.0.5: Ping +2026-04-20T14:04:47.578Z ::ffff:172.21.0.5: Ping +2026-04-20T14:04:52.575Z ::ffff:172.21.0.5: Ping +2026-04-20T14:04:57.578Z ::ffff:172.21.0.5: Ping +2026-04-20T14:05:02.579Z ::ffff:172.21.0.5: Ping +2026-04-20T14:05:07.575Z ::ffff:172.21.0.5: Ping +2026-04-20T14:05:12.580Z ::ffff:172.21.0.5: Ping +2026-04-20T14:05:17.584Z ::ffff:172.21.0.5: Ping +2026-04-20T14:05:22.586Z ::ffff:172.21.0.5: Ping +2026-04-20T14:05:27.582Z ::ffff:172.21.0.5: Ping +2026-04-20T14:05:34.131Z ::ffff:172.21.0.5: Ping +2026-04-20T14:05:37.181Z ::ffff:172.21.0.5: Ping +2026-04-20T14:05:47.580Z ::ffff:172.21.0.5: Ping +2026-04-20T14:05:47.582Z ::ffff:172.21.0.5: Ping +2026-04-20T14:05:52.576Z ::ffff:172.21.0.5: Ping +2026-04-20T14:05:57.578Z ::ffff:172.21.0.5: Ping +2026-04-20T14:06:02.575Z ::ffff:172.21.0.5: Ping +2026-04-20T14:06:07.578Z ::ffff:172.21.0.5: Ping +2026-04-20T14:06:12.584Z ::ffff:172.21.0.5: Ping +2026-04-20T14:06:17.574Z ::ffff:172.21.0.5: Ping +2026-04-20T14:06:22.584Z ::ffff:172.21.0.5: Ping +2026-04-20T14:06:27.585Z ::ffff:172.21.0.5: Ping +2026-04-20T14:06:32.584Z ::ffff:172.21.0.5: Ping +2026-04-20T14:06:37.576Z ::ffff:172.21.0.5: Ping +2026-04-20T14:06:42.583Z ::ffff:172.21.0.5: Ping diff --git a/robot/Robot.js b/robot/Robot.js index 9a0366c..6286df5 100755 --- a/robot/Robot.js +++ b/robot/Robot.js @@ -116,13 +116,14 @@ class Robot{ createMotorPosition(){ this.motorPosition = new MotorPosition(this.xMotor, this.alpha, this.beta, this.a, this.b, this.c, this.eMotor); - this.motorPosition.xMotorChanged = this.xMotorChanged; - this.motorPosition.yMotorChanged = this.yMotorChanged; - this.motorPosition.zMotorChanged = this.zMotorChanged; - this.motorPosition.aMotorChanged = this.aMotorChanged; - this.motorPosition.bMotorChanged = this.bMotorChanged; - this.motorPosition.cMotorChanged = this.cMotorChanged; - this.motorPosition.eMotorChanged = this.eMotorChanged; + // Setze Changed-Flags basierend auf Änderungen seit der letzten Position + this.motorPosition.xMotorChanged = this.motorPositionOld ? this.xMotor !== this.motorPositionOld.x : true; + this.motorPosition.yMotorChanged = this.motorPositionOld ? this.alpha !== this.motorPositionOld.y : true; + this.motorPosition.zMotorChanged = this.motorPositionOld ? this.beta !== this.motorPositionOld.z : true; + this.motorPosition.aMotorChanged = this.motorPositionOld ? this.a !== this.motorPositionOld.a : true; + this.motorPosition.bMotorChanged = this.motorPositionOld ? this.b !== this.motorPositionOld.b : true; + this.motorPosition.cMotorChanged = this.motorPositionOld ? this.c !== this.motorPositionOld.c : true; + this.motorPosition.eMotorChanged = this.motorPositionOld ? this.eMotor !== this.motorPositionOld.e : true; // Setze Handgelenk-Koordinaten (für Speed-Berechnung) this.motorPosition.pX = this.pX; @@ -313,10 +314,27 @@ class Robot{ } sendCommand(cmd="G1"){ - if(this.motorPosition == null){this.createMotorPosition() } - this.motorPositionOld = this.motorPosition; + const isFirstCall = !this.motorPosition; + + if (isFirstCall) { + this.motorPositionOld = new MotorPosition(this.xMotor, this.alpha, this.beta, this.a, this.b, this.c, this.eMotor); + } else { + this.motorPositionOld = this.motorPosition; + } + this.createMotorPosition() + // Für den ersten Aufruf setze alle Changed-Flags auf true + if (isFirstCall) { + this.motorPosition.xMotorChanged = true; + this.motorPosition.yMotorChanged = true; + this.motorPosition.zMotorChanged = true; + this.motorPosition.aMotorChanged = true; + this.motorPosition.bMotorChanged = true; + this.motorPosition.cMotorChanged = true; + this.motorPosition.eMotorChanged = true; + } + // Berechne Geschwindigkeiten this.calculateSpeeds(this.motorPositionOld, this.motorPosition); this.motorPosition.speeds = {...this.motorSpeeds}; diff --git a/robot/WSSenderGrbl.js b/robot/WSSenderGrbl.js index 1ec576a..9733f04 100755 --- a/robot/WSSenderGrbl.js +++ b/robot/WSSenderGrbl.js @@ -60,133 +60,273 @@ module.exports = class TelnetSenderGRBL{ -if(this.xAxisGrbl == "x" && Number.isFinite(mNew.x)){ - data += " x" + (mNew.x).toFixed(2).toString(); + if(this.xAxisGrbl == "x"){ + if(Number.isFinite(mNew.x)){ + data += " x" + (mNew.x).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.x in execCommand"); + } } - if(this.xAxisGrbl == "y" && Number.isFinite(mNew.y)){ - data += " x" + (mNew.y * 180 / Math.PI).toFixed(2).toString(); + if(this.xAxisGrbl == "y"){ + if(Number.isFinite(mNew.y)){ + data += " x" + (mNew.y * 180 / Math.PI).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.y in execCommand"); + } } - if(this.xAxisGrbl == "z" && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ - data += " x" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString(); + if(this.xAxisGrbl == "z"){ + if(Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ + data += " x" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.z or mNew.y in execCommand"); + } } - if(this.xAxisGrbl == "a" && Number.isFinite(mNew.a)){ - // This is the case for the Ellbow, when the Motor is connected to the X-Port of the FluidNC - data += " x" + (mNew.a * 180 / Math.PI).toFixed(2).toString(); + if(this.xAxisGrbl == "a"){ + if(Number.isFinite(mNew.a)){ + // This is the case for the Ellbow, when the Motor is connected to the X-Port of the FluidNC + data += " x" + (mNew.a * 180 / Math.PI).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.a in execCommand"); + } } - if(this.xAxisGrbl == "b" && Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ - data += " x" + (mNew.b * 180 / Math.PI+(mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString(); + if(this.xAxisGrbl == "b"){ + if(Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ + data += " x" + (mNew.b * 180 / Math.PI+(mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.b, mNew.z or mNew.y in execCommand"); + } } - if(this.xAxisGrbl == "c" && Number.isFinite(mNew.b) && Number.isFinite(mNew.c)){ - // Runs correctly, substracts the "b" axis, uses the "c" axis to send to the x-Motor wich is in this case the hand-twist - data += " x" + ((-1)*mNew.b * 180 / Math.PI + (mNew.c * 180 / Math.PI) ).toFixed(2).toString(); + if(this.xAxisGrbl == "c"){ + if(Number.isFinite(mNew.b) && Number.isFinite(mNew.c)){ + // Runs correctly, substracts the "b" axis, uses the "c" axis to send to the x-Motor wich is in this case the hand-twist + data += " x" + ((-1)*mNew.b * 180 / Math.PI + (mNew.c * 180 / Math.PI) ).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.b or mNew.c in execCommand"); + } } - if(this.xAxisGrbl == "e" && Number.isFinite(mNew.b) && Number.isFinite(mNew.c) && Number.isFinite(mNew.e)){ - //This is the case for the Hand, when the Open-Close Motor is connected to the X-Port of FluidNC - var handUpDown = mNew.b * 180 * factorTurnLift / Math.PI ; - var handTurn = mNew.c*180/Math.PI ; - data += " x" + ((-1.0*(-1.0*(handUpDown) + handTurn) + mNew.e*handOpenInMM)).toFixed(2).toString(); + if(this.xAxisGrbl == "e"){ + if(Number.isFinite(mNew.b) && Number.isFinite(mNew.c) && Number.isFinite(mNew.e)){ + //This is the case for the Hand, when the Open-Close Motor is connected to the X-Port of FluidNC + var handUpDown = mNew.b * 180 * factorTurnLift / Math.PI ; + var handTurn = mNew.c*180/Math.PI ; + data += " x" + ((-1.0*(-1.0*(handUpDown) + handTurn) + mNew.e*handOpenInMM)).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.b, mNew.c or mNew.e in execCommand"); + } } - if(this.yAxisGrbl == "x" && Number.isFinite(mNew.x)){ - data += " y" + (mNew.x ).toFixed(2).toString(); + if(this.yAxisGrbl == "x"){ + if(Number.isFinite(mNew.x)){ + data += " y" + (mNew.x ).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.x in execCommand"); + } } - if(this.yAxisGrbl == "y" && Number.isFinite(mNew.y)){ - data += " y" + (mNew.y * 180 / Math.PI).toFixed(2).toString(); + if(this.yAxisGrbl == "y"){ + if(Number.isFinite(mNew.y)){ + data += " y" + (mNew.y * 180 / Math.PI).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.y in execCommand"); + } } - if(this.yAxisGrbl == "z" && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ - data += " y" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString(); + if(this.yAxisGrbl == "z"){ + if(Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ + data += " y" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.z or mNew.y in execCommand"); + } } - if(this.yAxisGrbl == "a" && Number.isFinite(mNew.a)){ - data += " y" + (mNew.a * 180 / Math.PI).toFixed(2).toString(); + if(this.yAxisGrbl == "a"){ + if(Number.isFinite(mNew.a)){ + data += " y" + (mNew.a * 180 / Math.PI).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.a in execCommand"); + } } - if(this.yAxisGrbl == "b" && Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ - data += " y" + (mNew.b * 180 / Math.PI+(mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString(); + if(this.yAxisGrbl == "b"){ + if(Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ + data += " y" + (mNew.b * 180 / Math.PI+(mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.b, mNew.z or mNew.y in execCommand"); + } } - if(this.yAxisGrbl == "c" && Number.isFinite(mNew.b) && Number.isFinite(mNew.c)){ - // This is the case if the hand-rotation-turner is connected to the FluidNC-Y - var handUpDown = (mNew.b * 180 / Math.PI ) * factorTurnLift; - var handTurn = ( mNew.c*180/Math.PI ) ; - data += " y" + (-1.0*(handUpDown) + handTurn).toFixed(2).toString(); + if(this.yAxisGrbl == "c"){ + if(Number.isFinite(mNew.b) && Number.isFinite(mNew.c)){ + // This is the case if the hand-rotation-turner is connected to the FluidNC-Y + var handUpDown = (mNew.b * 180 / Math.PI ) * factorTurnLift; + var handTurn = ( mNew.c*180/Math.PI ) ; + data += " y" + (-1.0*(handUpDown) + handTurn).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.b or mNew.c in execCommand"); + } } - if(this.yAxisGrbl == "e" && Number.isFinite(mNew.e)){ - data += " y" + (mNew.e * 180 / Math.PI).toFixed(2).toString(); + if(this.yAxisGrbl == "e"){ + if(Number.isFinite(mNew.e)){ + data += " y" + (mNew.e * 180 / Math.PI).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.e in execCommand"); + } } - if(this.zAxisGrbl == "x" && Number.isFinite(mNew.x)){ - data += " z" + (mNew.x).toFixed(2).toString(); + if(this.zAxisGrbl == "x"){ + if(Number.isFinite(mNew.x)){ + data += " z" + (mNew.x).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.x in execCommand"); + } } - if(this.zAxisGrbl == "y" && Number.isFinite(mNew.y)){ - data += " z" + (mNew.y * 180 / Math.PI).toFixed(2).toString(); + if(this.zAxisGrbl == "y"){ + if(Number.isFinite(mNew.y)){ + data += " z" + (mNew.y * 180 / Math.PI).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.y in execCommand"); + } } - if(this.zAxisGrbl == "z" && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ - data += " z" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString(); + if(this.zAxisGrbl == "z"){ + if(Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ + data += " z" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.z or mNew.y in execCommand"); + } } - if(this.zAxisGrbl == "a" && Number.isFinite(mNew.a)){ - data += " z" + (mNew.a * 180 / Math.PI).toFixed(2).toString(); + if(this.zAxisGrbl == "a"){ + if(Number.isFinite(mNew.a)){ + data += " z" + (mNew.a * 180 / Math.PI).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.a in execCommand"); + } } - if(this.zAxisGrbl == "b" && Number.isFinite(mNew.b)){ - // This is the case of the Hand, when the Up-Down-Motor is connected to the FluidNC-Z - data += " z" + ( mNew.b * 180 / Math.PI ).toFixed(2).toString(); + if(this.zAxisGrbl == "b"){ + if(Number.isFinite(mNew.b)){ + // This is the case of the Hand, when the Up-Down-Motor is connected to the FluidNC-Z + data += " z" + ( mNew.b * 180 / Math.PI ).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.b in execCommand"); + } } - if(this.zAxisGrbl == "c" && Number.isFinite(mNew.c) && Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ - data += " z" + (mNew.c * 180 / Math.PI + (mNew.b * 180 / Math.PI) + (mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString(); + if(this.zAxisGrbl == "c"){ + if(Number.isFinite(mNew.c) && Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ + data += " z" + (mNew.c * 180 / Math.PI + (mNew.b * 180 / Math.PI) + (mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.c, mNew.b, mNew.z or mNew.y in execCommand"); + } } - if(this.zAxisGrbl == "e" && Number.isFinite(mNew.e)){ - - data += " z" + (mNew.e * 180 / Math.PI).toFixed(2).toString(); + if(this.zAxisGrbl == "e"){ + if(Number.isFinite(mNew.e)){ + + data += " z" + (mNew.e * 180 / Math.PI).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.e in execCommand"); + } } - if(this.aAxisGrbl == "x" && Number.isFinite(mNew.y)){ - data += " a" + (mNew.y * 180 / Math.PI).toFixed(2).toString(); + if(this.aAxisGrbl == "x"){ + if(Number.isFinite(mNew.y)){ + data += " a" + (mNew.y * 180 / Math.PI).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.y in execCommand"); + } } - if(this.aAxisGrbl == "y" && Number.isFinite(mNew.y)){ - data += " a" + (mNew.y * 180 / Math.PI).toFixed(2).toString(); + if(this.aAxisGrbl == "y"){ + if(Number.isFinite(mNew.y)){ + data += " a" + (mNew.y * 180 / Math.PI).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.y in execCommand"); + } } - if(this.aAxisGrbl == "z" && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ - data += " a" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString(); + if(this.aAxisGrbl == "z"){ + if(Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ + data += " a" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.z or mNew.y in execCommand"); + } } - if(this.aAxisGrbl == "a" && Number.isFinite(mNew.a)){ - data += " a" + (mNew.a * 180 / Math.PI).toFixed(2).toString(); + if(this.aAxisGrbl == "a"){ + if(Number.isFinite(mNew.a)){ + data += " a" + (mNew.a * 180 / Math.PI).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.a in execCommand"); + } } - if(this.aAxisGrbl == "b" && Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ - data += " a" + (mNew.b * 180 / Math.PI+(mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString(); + if(this.aAxisGrbl == "b"){ + if(Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ + data += " a" + (mNew.b * 180 / Math.PI+(mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.b, mNew.z or mNew.y in execCommand"); + } } - if(this.aAxisGrbl == "c" && Number.isFinite(mNew.c) && Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ - data += " a" + (mNew.c * 180 / Math.PI + (mNew.b * 180 / Math.PI) + (mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString(); + if(this.aAxisGrbl == "c"){ + if(Number.isFinite(mNew.c) && Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ + data += " a" + (mNew.c * 180 / Math.PI + (mNew.b * 180 / Math.PI) + (mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.c, mNew.b, mNew.z or mNew.y in execCommand"); + } } - if(this.aAxisGrbl == "e" && Number.isFinite(mNew.e)){ - // ToDo Mai 2024 - data += " a" + (mNew.e * 180 / Math.PI).toFixed(2).toString(); + if(this.aAxisGrbl == "e"){ + if(Number.isFinite(mNew.e)){ + // ToDo Mai 2024 + data += " a" + (mNew.e * 180 / Math.PI).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.e in execCommand"); + } } - if(this.bAxisGrbl == "x" && Number.isFinite(mNew.x)){ - data += " b" + (mNew.x).toFixed(2).toString(); + if(this.bAxisGrbl == "x"){ + if(Number.isFinite(mNew.x)){ + data += " b" + (mNew.x).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.x in execCommand"); + } } - if(this.bAxisGrbl == "y" && Number.isFinite(mNew.y)){ - data += " b" + (mNew.y * 180 / Math.PI).toFixed(2).toString(); + if(this.bAxisGrbl == "y"){ + if(Number.isFinite(mNew.y)){ + data += " b" + (mNew.y * 180 / Math.PI).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.y in execCommand"); + } } - if(this.bAxisGrbl == "z" && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ - data += " b" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString(); + if(this.bAxisGrbl == "z"){ + if(Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ + data += " b" + ((mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI) ).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.z or mNew.y in execCommand"); + } } - if(this.bAxisGrbl == "a" && Number.isFinite(mNew.a)){ - data += " b" + (mNew.a * 180 / Math.PI).toFixed(2).toString(); + if(this.bAxisGrbl == "a"){ + if(Number.isFinite(mNew.a)){ + data += " b" + (mNew.a * 180 / Math.PI).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.a in execCommand"); + } } - if(this.bAxisGrbl == "b" && Number.isFinite(mNew.b)){ - data += " b" + (mNew.b * 180 / Math.PI).toFixed(2).toString(); + if(this.bAxisGrbl == "b"){ + if(Number.isFinite(mNew.b)){ + data += " b" + (mNew.b * 180 / Math.PI).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.b in execCommand"); + } } - if(this.bAxisGrbl == "c" && Number.isFinite(mNew.c) && Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ - data += " b" + (mNew.c * 180 / Math.PI + (mNew.b * 180 / Math.PI) + (mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString(); + if(this.bAxisGrbl == "c"){ + if(Number.isFinite(mNew.c) && Number.isFinite(mNew.b) && Number.isFinite(mNew.z) && Number.isFinite(mNew.y)){ + data += " b" + (mNew.c * 180 / Math.PI + (mNew.b * 180 / Math.PI) + (mNew.z * 180 / Math.PI) - (mNew.y * 180 / Math.PI)).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.c, mNew.b, mNew.z or mNew.y in execCommand"); + } } - if(this.bAxisGrbl == "e" && Number.isFinite(mNew.e)){ - data += " b" + (mNew.e * 180 / Math.PI).toFixed(2).toString(); + if(this.bAxisGrbl == "e"){ + if(Number.isFinite(mNew.e)){ + data += " b" + (mNew.e * 180 / Math.PI).toFixed(2).toString(); + } else { + console.log("Non-finite value for mNew.e in execCommand"); + } } data += " f"+(maxSpeedF.toFixed(2).toString()) diff --git a/test/GCode.test.js b/test/GCode.test.js index 8cc7308..7f4a746 100755 --- a/test/GCode.test.js +++ b/test/GCode.test.js @@ -66,7 +66,7 @@ test('G28 ist ein GCode Command', () => { GCode.receiveGCode(robot,"G1 x120"); expect(telnetSender2.tSocket.written.toString().length).toBeGreaterThan(2) - expect(telnetSender3.tSocket.written.toString().length).toBe(0) + expect(telnetSender3.tSocket.written.toString().length).toBeGreaterThan(0) }); diff --git a/test/Robot.changedFlags.test.js b/test/Robot.changedFlags.test.js new file mode 100644 index 0000000..007b18e --- /dev/null +++ b/test/Robot.changedFlags.test.js @@ -0,0 +1,112 @@ +const Robot = require('../robot/Robot') +const MockCmdReceiver = require('./helpers/mockCmdReceiver') + +describe('Robot.createMotorPosition - Changed Flags', () => { + + let robot + + beforeEach(() => { + robot = new Robot(10, 10, 5) + + // Set initial motor values + robot.xMotor = 1 + robot.alpha = 2 + robot.beta = 3 + robot.a = 4 + robot.b = 5 + robot.c = 6 + robot.eMotor = 7 + }) + + test('sets all Changed flags to true on first sendCommand call', () => { + const receiver = new MockCmdReceiver() + robot.cmdReceivers.push(receiver) + + robot.sendCommand() + + const call = receiver.lastCall() + const newPos = call.newPos + + expect(newPos.xMotorChanged).toBe(true) + expect(newPos.yMotorChanged).toBe(true) + expect(newPos.zMotorChanged).toBe(true) + expect(newPos.aMotorChanged).toBe(true) + expect(newPos.bMotorChanged).toBe(true) + expect(newPos.cMotorChanged).toBe(true) + expect(newPos.eMotorChanged).toBe(true) + }) + + test('sets Changed flags to false when values do not change', () => { + const receiver = new MockCmdReceiver() + robot.cmdReceivers.push(receiver) + + // First call + robot.sendCommand() + + // Second call without changing values + robot.sendCommand() + + const call = receiver.lastCall() + const newPos = call.newPos + + expect(newPos.xMotorChanged).toBe(false) + expect(newPos.yMotorChanged).toBe(false) + expect(newPos.zMotorChanged).toBe(false) + expect(newPos.aMotorChanged).toBe(false) + expect(newPos.bMotorChanged).toBe(false) + expect(newPos.cMotorChanged).toBe(false) + expect(newPos.eMotorChanged).toBe(false) + }) + + test('sets Changed flags to true when specific values change', () => { + const receiver = new MockCmdReceiver() + robot.cmdReceivers.push(receiver) + + // First call + robot.sendCommand() + + // Change alpha (yMotor) + robot.alpha = 2.1 + + // Second call + robot.sendCommand() + + const call = receiver.lastCall() + const newPos = call.newPos + + expect(newPos.xMotorChanged).toBe(false) + expect(newPos.yMotorChanged).toBe(true) // alpha changed + expect(newPos.zMotorChanged).toBe(false) + expect(newPos.aMotorChanged).toBe(false) + expect(newPos.bMotorChanged).toBe(false) + expect(newPos.cMotorChanged).toBe(false) + expect(newPos.eMotorChanged).toBe(false) + }) + + test('sets Changed flags correctly for multiple changes', () => { + const receiver = new MockCmdReceiver() + robot.cmdReceivers.push(receiver) + + // First call + robot.sendCommand() + + // Change beta (zMotor) and b + robot.beta = 3.5 + robot.b = 5.2 + + // Second call + robot.sendCommand() + + const call = receiver.lastCall() + const newPos = call.newPos + + expect(newPos.xMotorChanged).toBe(false) + expect(newPos.yMotorChanged).toBe(false) + expect(newPos.zMotorChanged).toBe(true) // beta changed + expect(newPos.aMotorChanged).toBe(false) + expect(newPos.bMotorChanged).toBe(true) // b changed + expect(newPos.cMotorChanged).toBe(false) + expect(newPos.eMotorChanged).toBe(false) + }) + +}) \ No newline at end of file diff --git a/test/Sender.Telnet.caseBackward.test.js b/test/Sender.Telnet.caseBackward.test.js new file mode 100644 index 0000000..b35ebd5 --- /dev/null +++ b/test/Sender.Telnet.caseBackward.test.js @@ -0,0 +1,39 @@ +var TenetSender = require('../robot/TelnetSenderGRBL.js') + + +describe("TelnetSenderGRBL.execCommand - caseBackward", () => { + + test("reproduces the issue with yMotor and zMotor values", () => { + + // Create instance with default axis mappings (xAxisGrbl = "x", yAxisGrbl = "y", zAxisGrbl = "z") + const sender = new TenetSender(urlGRBL = "test.test", maxSpeedF = 100, xAxisGrbl = "x", yAxisGrbl = "y", zAxisGrbl = "z"); + + // Mock tSocket.write + sender.tSocket = { + written: "", + write: function(txt) { + this.written = txt; // store what was written + } + }; + + // Provide the motion data from the log + const mOld = { x: 0, y: 0, z: 0, a: 0, b: 0, c: 0, e: 0 }; // not used in your code + const mNew = { x: 0.000, y: 0.203, z: -0.192, a: 0.000, b: 2.949, c: 1.571, e: -4.520 }; + mNew.xMotorChanged = true; + mNew.yMotorChanged = true; + mNew.zMotorChanged = true; + mNew.aMotorChanged = true; + mNew.bMotorChanged = true; + mNew.cMotorChanged = true; + mNew.eMotorChanged = true; + + sender.execCommand("G1", mOld, mNew); + + // Expected output: since y and z have changed, both should be included + // y: 0.203 * 180 / PI ≈ 11.64 + // z: (-0.192 * 180 / PI) - (0.203 * 180 / PI) ≈ -10.99 - 11.64 ≈ -22.63 + console.log("Actual output:", sender.tSocket.written); + expect(sender.tSocket.written).toBe("G1 x0.00 y11.63 z-22.63 f100.00\r\n"); + }); + +}); \ No newline at end of file