From 40a53a68824d14e82d74ed35298cff2ec84ffaaa Mon Sep 17 00:00:00 2001 From: Razanne Date: Thu, 23 Mar 2023 15:12:26 +0100 Subject: [PATCH] #262. WIP --- Connector.py | 49 ++++++++++++++++++++++++++++++++++--------- configs/razanne.toml | 6 +++--- floorplans/square.txt | 7 +++++++ 3 files changed, 49 insertions(+), 13 deletions(-) create mode 100644 floorplans/square.txt diff --git a/Connector.py b/Connector.py index d33e1ff..b92a4dd 100644 --- a/Connector.py +++ b/Connector.py @@ -26,6 +26,8 @@ def __init__(self): ) for i in range(1, len(self.getActiveRealDotbots())+1) ]) + self.maxLength = 7 + def getActiveRealDotbots(self): # Set the base URL for the API base_url = "http://localhost:8000" @@ -38,11 +40,31 @@ def getActiveRealDotbots(self): return response.json() def computeRealCoordinates(self, virtualX, virtualY): - return ((virtualX)/self.scale, (virtualY)/self.scale) + + # compute realX + if virtualX <= 1: + realX = 0 + elif virtualX >= (self.maxLength-1): + realX = 1 + else: + realX = virtualX/(self.maxLength-1) + + # compute realY + if virtualY <= 1: + realY = 0 + elif virtualY >= (self.maxLength-1): + realY = 1 + else: + realY = virtualY/(self.maxLength-1) + + print('virtual coordinates', virtualX, virtualY, '-> real coordinates', realX, realY) + return (realX, realY) def computeVirtualCoordinates(self, realX, realY): - print('real coordinates',realX, realY) - return (realX*self.scale, realY*self.scale) + + (virtualX, virtualY) = (realX*(self.maxLength-1), realY*(self.maxLength-1)) + print('real coordinates', realX, realY, '-> virtual coordinates', virtualX, virtualY) + return (virtualX, virtualY) def getRealPositions(self): dotBots = self.getActiveRealDotbots() @@ -59,11 +81,16 @@ def moveRawRealDotbot(self, address, x, y): endpoint = '/controller/dotbots/{address}/0/waypoints'.format(address = address) # Set the data for the new user - data = [{ - "x": x, - "y": y, - "z": 0, - }] + data = { + "threshold": 40, + "waypoints": [ + { + "x": x, + "y": y, + "z": 0 + } + ] + } try: # Make the POST request to the endpoint @@ -75,6 +102,7 @@ def moveRawRealDotbot(self, address, x, y): print(response.json()) else: print("An error occurred:", response.status_code) + print('***') except: pass @@ -116,8 +144,9 @@ def setNextRealDotBotMovement(self, dotBotId): self.moveRawRealDotbot(self.realDotBotsView[dotBotId]['address'], scaledNextX, scaledNextY) (realX, realY) = self.getRealPositions()[dotBotId-1] print(realX, realY, nextX, nextY) - print('here') - if (nextX-0.2 <= realX<= nextX+0.2) and (nextY-0.2 <= realY <= nextY+0.2): + break + + if (nextX-0.1 <= realX<= nextX+0.1) and (nextY-0.1 <= realY <= nextY+0.1): print('DotBot arrived') break diff --git a/configs/razanne.toml b/configs/razanne.toml index 0b6bd5b..02daa81 100644 --- a/configs/razanne.toml +++ b/configs/razanne.toml @@ -1,11 +1,11 @@ [atlas] - numRobots = 10 - floorplan = "office_small" # filename in floorplans + numRobots = 1 + floorplan = "square" # filename in floorplans navigationAlgorithm = "Atlas" # options: Atlas, Ballistic relayAlgorithm = "Recovery" # options: Recovery, SelfHealing, NoRelays lowerPdrThreshold = 0.8 # (for Recovery) trigger relay placement if below upperPdrThreshold = 0.9 # (for Recovery) to determine relay position propagationModel = "PisterHack" # options: LOS, Friis, Radius, PisterHack numberOfRuns = 1 # number of simulations runs with same simSetting - connector = 'off' # on if connector to real DotBots in watnted, else off + connector = 'on' # on if connector to real DotBots in watnted, else off diff --git a/floorplans/square.txt b/floorplans/square.txt new file mode 100644 index 0000000..80cff89 --- /dev/null +++ b/floorplans/square.txt @@ -0,0 +1,7 @@ +####### +#.....# +#..s..# +#.....# +#.....# +#.....# +####### \ No newline at end of file