updated roese utils

main
alex 2023-10-09 20:22:42 +02:00
parent e4f9eee319
commit 6340cfc391
9 changed files with 66 additions and 14 deletions

2
go.mod
View File

@ -3,7 +3,7 @@ module jannex/admin-dashboard-backend
go 1.21.0 go 1.21.0
require ( 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/fiber/v2 v2.49.2
github.com/gofiber/websocket/v2 v2.1.6 github.com/gofiber/websocket/v2 v2.1.6
github.com/google/uuid v1.3.1 github.com/google/uuid v1.3.1

4
go.sum
View File

@ -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.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 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.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 h1:8uQZIdzKmjc/iuPu7O2ioW48L81FgatrcpfFmiq/cCs=
github.com/andybalholm/brotli v1.0.5/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHGRSepvi9Eig= 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= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=

View File

@ -5,7 +5,7 @@
"tasks": [ "tasks": [
{ {
"name": "Bild zu Label konvertieren", "name": "Bild zu Label konvertieren",
"onFinish": "pause", "onFinish": "next",
"undoPossible": false, "undoPossible": false,
"repeatPossible": true, "repeatPossible": true,
"scriptPath": "test.py", "scriptPath": "test.py",

View File

@ -6,6 +6,7 @@ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '../..')
from libs.robots import rex from libs.robots import rex
rexRobot = rex.Rex("rexRobot", "Drucker leeren") rexRobot = rex.Rex("B24", "Drucker leeren")
rexRobot.move(1, 2, 3) # rexRobot.moveToXYZ(1, 2, 3)
rexRobot.move_to_x(5)

View File

@ -1,4 +1,6 @@
import requests import requests
import uuid
class Rex: class Rex:
""" """
@ -6,27 +8,69 @@ class Rex:
""" """
def __init__(self, rexName, jobName): def __init__(self, rexName, jobName):
self.rexName = rexName self.rexName = rexName
self.jobId = uuid.uuid4().__str__()
self.jobName = jobName self.jobName = jobName
self.x = 0 self.x = 0
self.y = 0 self.y = 0
self.z = 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.x = x
self.y = y self.y = y
self.z = z 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(): 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 # TODO: request to the server to finish the robot and update the robot status to free

View File

@ -36,6 +36,8 @@ import (
"github.com/gofiber/fiber/v2/middleware/logger" "github.com/gofiber/fiber/v2/middleware/logger"
"github.com/gofiber/websocket/v2" "github.com/gofiber/websocket/v2"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"
adlogger "jannex/admin-dashboard-backend/modules/logger"
) )
func init() { func init() {
@ -155,6 +157,8 @@ func main() {
go grouptasks.StartUnlockLockedGroupTaskStepsTicker() go grouptasks.StartUnlockLockedGroupTaskStepsTicker()
adlogger.AddSystemLog("Server started")
app.Listen(config.Cfg.Host + ":" + config.Cfg.Port) app.Listen(config.Cfg.Host + ":" + config.Cfg.Port)
} }

View File

@ -2,20 +2,19 @@ package logger
import ( import (
"fmt" "fmt"
"jannex/admin-dashboard-backend/modules/config"
"git.ex.umbach.dev/Alex/roese-utils/rslogger" "git.ex.umbach.dev/Alex/roese-utils/rslogger"
"github.com/gofiber/fiber/v2" "github.com/gofiber/fiber/v2"
) )
func AddSystemLog(format string, v ...any) { 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", Type: "system",
Logs: []string{"I " + rslogger.GetTime() + fmt.Sprintf(format, v...)}}) Logs: []string{"I " + rslogger.GetTime() + fmt.Sprintf(format, v...)}})
} }
func AddGroupTasksLog(format string, v ...any) { 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", Type: "grouptasks",
Logs: []string{"I " + rslogger.GetTime() + fmt.Sprintf(format, v...)}}) Logs: []string{"I " + rslogger.GetTime() + fmt.Sprintf(format, v...)}})
} }

View File

@ -313,7 +313,7 @@ func RunHub() {
grouptasks.InstallGlobalPythonPackages(data.Conn.Locals("userId").(string)) grouptasks.InstallGlobalPythonPackages(data.Conn.Locals("userId").(string))
break break
case utils.ReceivedCmdSubscribeToTopic: 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)) cache.SubscribeSocketClientToTopic(data.Conn.Locals("sessionId").(string), receivedMessage.Body["topic"].(string))
break break