From 6340cfc3912b5e602eeb901fd5c641424b18d772 Mon Sep 17 00:00:00 2001 From: alex Date: Mon, 9 Oct 2023 20:22:42 +0200 Subject: [PATCH] updated roese utils --- go.mod | 2 +- go.sum | 4 ++ groupTasks/groups/rex-robots/index.json | 2 +- groupTasks/groups/rex-robots/test.py | 5 +- .../robots/__pycache__/rex.cpython-39.pyc | Bin 1179 -> 2554 bytes groupTasks/libs/robots/rex.py | 56 ++++++++++++++++-- main.go | 4 ++ modules/logger/logger.go | 5 +- socketserver/hub.go | 2 +- 9 files changed, 66 insertions(+), 14 deletions(-) diff --git a/go.mod b/go.mod index 26c3632..d07c823 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module jannex/admin-dashboard-backend go 1.21.0 require ( - git.ex.umbach.dev/Alex/roese-utils v1.0.8 + git.ex.umbach.dev/Alex/roese-utils v1.0.10 github.com/gofiber/fiber/v2 v2.49.2 github.com/gofiber/websocket/v2 v2.1.6 github.com/google/uuid v1.3.1 diff --git a/go.sum b/go.sum index 07bd2af..7b7a94f 100644 --- a/go.sum +++ b/go.sum @@ -4,6 +4,10 @@ git.ex.umbach.dev/Alex/roese-utils v1.0.7 h1:eLw6u1ibPeG6zd702Q3Ge8VebABiz0KQJkz git.ex.umbach.dev/Alex/roese-utils v1.0.7/go.mod h1:tjq6m6lNFo0TzAvq8jHhlK48IGxi+SrlrQwf9WYg408= git.ex.umbach.dev/Alex/roese-utils v1.0.8 h1:ph18N52R9UsJ0AsJW95W6afa9qKlMDMh60xE4wlfFi8= git.ex.umbach.dev/Alex/roese-utils v1.0.8/go.mod h1:tjq6m6lNFo0TzAvq8jHhlK48IGxi+SrlrQwf9WYg408= +git.ex.umbach.dev/Alex/roese-utils v1.0.9 h1:MshCYgFc22t4h9KjfE4hvuHbUcrqkbzxC3J4nqGoyuk= +git.ex.umbach.dev/Alex/roese-utils v1.0.9/go.mod h1:tjq6m6lNFo0TzAvq8jHhlK48IGxi+SrlrQwf9WYg408= +git.ex.umbach.dev/Alex/roese-utils v1.0.10 h1:pAtvtWrDSuVKGyusKPG093+DsnNc2ek/6k/9Qgz7acE= +git.ex.umbach.dev/Alex/roese-utils v1.0.10/go.mod h1:tjq6m6lNFo0TzAvq8jHhlK48IGxi+SrlrQwf9WYg408= github.com/andybalholm/brotli v1.0.5 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs= github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= diff --git a/groupTasks/groups/rex-robots/index.json b/groupTasks/groups/rex-robots/index.json index e13b8dc..90d40e2 100644 --- a/groupTasks/groups/rex-robots/index.json +++ b/groupTasks/groups/rex-robots/index.json @@ -5,7 +5,7 @@ "tasks": [ { "name": "Bild zu Label konvertieren", - "onFinish": "pause", + "onFinish": "next", "undoPossible": false, "repeatPossible": true, "scriptPath": "test.py", diff --git a/groupTasks/groups/rex-robots/test.py b/groupTasks/groups/rex-robots/test.py index 0115a54..22f7052 100644 --- a/groupTasks/groups/rex-robots/test.py +++ b/groupTasks/groups/rex-robots/test.py @@ -6,6 +6,7 @@ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..') from libs.robots import rex -rexRobot = rex.Rex("rexRobot", "Drucker leeren") +rexRobot = rex.Rex("B24", "Drucker leeren") -rexRobot.move(1, 2, 3) \ No newline at end of file +# rexRobot.moveToXYZ(1, 2, 3) +rexRobot.move_to_x(5) \ No newline at end of file diff --git a/groupTasks/libs/robots/__pycache__/rex.cpython-39.pyc b/groupTasks/libs/robots/__pycache__/rex.cpython-39.pyc index 419f63556363fca9f72cd93f406e959c5075f677..1d7427dc164dd9db62cfc70d766f42322d819391 100644 GIT binary patch literal 2554 zcmb_dL2uhO6ecCvmYq0hx^@}XbrUvpn6M^pfn@`NVk=N=!w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GL cN?cXUu3{B3{#P30_O#UJ6Z0IOM(jee-%5mkjQ{`u diff --git a/groupTasks/libs/robots/rex.py b/groupTasks/libs/robots/rex.py index 4fa8ffe..5f43bbd 100644 --- a/groupTasks/libs/robots/rex.py +++ b/groupTasks/libs/robots/rex.py @@ -1,4 +1,6 @@ import requests +import uuid + class Rex: """ @@ -6,27 +8,69 @@ class Rex: """ def __init__(self, rexName, jobName): self.rexName = rexName + self.jobId = uuid.uuid4().__str__() self.jobName = jobName self.x = 0 self.y = 0 self.z = 0 + self.connectedModule = 0 - def move(self, x, y, z): + def _request_data(self): + return {'robotName': self.rexName, 'jobid': self.jobId, 'jobName': self.jobName} + + def _post_request(self, json): + obj = {} + + obj = self._request_data() + obj['task'] = json + + res = requests.post('http://localhost:50055/v1/control/0', json=obj) + + def move_to_x(self, x): """ - Move the robot to a new position. + Move the robot to the new x position. + """ + self.x = x + + self._post_request({'x': self.x}) + + def move_to_y(self, y): + """ + Move the robot to the new y position. + """ + self.y = y + + def move_to_z(self, z): + """ + Move the robot to the new z position. + """ + self.z = z + + def move_to_xyz(self, x, y, z): + """ + Move the robot to the new position. """ self.x = x self.y = y self.z = z - print("Robot: " + self.rexName + " moved to (" + str(self.x) + ", " + str(self.y) + ")") + print('Robot: ' + self.rexName + ' moved to (' + str(self.x) + ', ' + str(self.y) + ')') - requests.post("http://localhost:50055/v1/control/move", json={"x": self.x, "y": self.y, "z": self.z}) + # requests.post('http://localhost:50055/v1/control/move', json={'x': self.x, 'y': self.y, 'z': self.z}) + + self._post_request({'x': self.x, 'y': self.y, 'z': self.z}) + + def change_connected_module(self, module): + """ + Change the connected module. + """ + print('Robot: ' + self.rexName + ' changed connected module to ' + str(module)) def finish(): """ - Finish the robot. + Finish the robot. + This will update the robot status to free. """ - print("Robot finished") + print('Robot finished') # TODO: request to the server to finish the robot and update the robot status to free \ No newline at end of file diff --git a/main.go b/main.go index 754cb5b..9fab868 100644 --- a/main.go +++ b/main.go @@ -36,6 +36,8 @@ import ( "github.com/gofiber/fiber/v2/middleware/logger" "github.com/gofiber/websocket/v2" "github.com/rs/zerolog/log" + + adlogger "jannex/admin-dashboard-backend/modules/logger" ) func init() { @@ -155,6 +157,8 @@ func main() { go grouptasks.StartUnlockLockedGroupTaskStepsTicker() + adlogger.AddSystemLog("Server started") + app.Listen(config.Cfg.Host + ":" + config.Cfg.Port) } diff --git a/modules/logger/logger.go b/modules/logger/logger.go index 9e36f42..05fde8e 100644 --- a/modules/logger/logger.go +++ b/modules/logger/logger.go @@ -2,20 +2,19 @@ package logger import ( "fmt" - "jannex/admin-dashboard-backend/modules/config" "git.ex.umbach.dev/Alex/roese-utils/rslogger" "github.com/gofiber/fiber/v2" ) func AddSystemLog(format string, v ...any) { - go rslogger.LogManagerRequestClient(fiber.MethodPost, config.Cfg.LogManagerServerUrl+"/v1/log", rslogger.LogManagerRequestBody{ + go rslogger.LogManagerRequestClient(fiber.MethodPost, rslogger.LogManagerRequestBody{ Type: "system", Logs: []string{"I " + rslogger.GetTime() + fmt.Sprintf(format, v...)}}) } func AddGroupTasksLog(format string, v ...any) { - go rslogger.LogManagerRequestClient(fiber.MethodPost, config.Cfg.LogManagerServerUrl+"/v1/log", rslogger.LogManagerRequestBody{ + go rslogger.LogManagerRequestClient(fiber.MethodPost, rslogger.LogManagerRequestBody{ Type: "grouptasks", Logs: []string{"I " + rslogger.GetTime() + fmt.Sprintf(format, v...)}}) } diff --git a/socketserver/hub.go b/socketserver/hub.go index 9c7b1b1..0ee4a4e 100644 --- a/socketserver/hub.go +++ b/socketserver/hub.go @@ -313,7 +313,7 @@ func RunHub() { grouptasks.InstallGlobalPythonPackages(data.Conn.Locals("userId").(string)) break case utils.ReceivedCmdSubscribeToTopic: - log.Info().Msgf("Received subscribe to topic: %v", receivedMessage.Body) + log.Debug().Msgf("Received subscribe to topic: %v", receivedMessage.Body) cache.SubscribeSocketClientToTopic(data.Conn.Locals("sessionId").(string), receivedMessage.Body["topic"].(string)) break