Skip to content

Commit

Permalink
262. bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Raa37 committed Jan 20, 2023
1 parent 400c928 commit e328358
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
30 changes: 13 additions & 17 deletions Connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@ def __init__(self):
# physical address
"address": self.getActiveRealDotbots()[i-1]['address'],
# current position of DotBot
'x': self.getActiveRealDotbots()[i-1]['lh2_position']['x'],
'y': self.getActiveRealDotbots()[i-1]['lh2_position']['y'],
# current heading and speed
'leftWheelSpeed': 0,
'rightWheelSpeed': 0,
'x': self.getActiveRealDotbots()[i-1]['position_history'][-1]['x'],
'y': self.getActiveRealDotbots()[i-1]['position_history'][-1]['y'],
# next bump coordinates
'nextBumpX': None,
'nextBumpY': None,
Expand All @@ -38,8 +35,6 @@ def getActiveRealDotbots(self):

response = requests.get(base_url + endpoint)

print(response.json())

return response.json()

def getRealCoordinates(self, virtualX, virtualY):
Expand All @@ -51,7 +46,7 @@ def getVirtualCoordinates(self, realX, realY):
def getRealInitialPositions(self):
dotBots = self.getActiveRealDotbots()
print(dotBots)
return [self.getVirtualCoordinates(dotBot['lh2_position']['x'], dotBot['lh2_position']['y']) for dotBot in dotBots]
return [self.getVirtualCoordinates(dotBot['position_history'][-1]['x'], dotBot['position_history'][-1]['y']) for dotBot in dotBots]


def moveRawRealDotbot(self, address, x, y):
Expand Down Expand Up @@ -94,20 +89,21 @@ def updateTargetCoordinates(self, dotBotId, targetCell):

def setNextRealDotBotMovement(self, dotBotId):

if not self.realDotBotsView[dotBotId]['targetX']:
return

# get real DotBot position
(currentX, currentY) = (self.realDotBotsView[dotBotId]['x'], self.realDotBotsView[dotBotId]['y'] )

# compute distance between current position and target position
dotBotToTargetDistance = u.distance((currentX, currentY),(self.realDotBotsView[dotBotId]['targetX'], self.realDotBotsView[dotBotId]['targetY']))
(nextX, nextY) = (self.realDotBotsView[dotBotId]['targetX'], self.realDotBotsView[dotBotId]['targetY'])
if self.realDotBotsView[dotBotId]['nextBumpX']:

# compute distance between current position and target position
dotBotToTargetDistance = u.distance((currentX, currentY), (
self.realDotBotsView[dotBotId]['targetX'], self.realDotBotsView[dotBotId]['targetY']))

# compute distance between current position and next bump position
dotBotToBumpDistance = u.distance((currentX, currentY),(self.realDotBotsView[dotBotId]['nextBumpX'], self.realDotBotsView[dotBotId]['nextBumpY']))
# compute distance between current position and next bump position
dotBotToBumpDistance = u.distance((currentX, currentY),(self.realDotBotsView[dotBotId]['nextBumpX'], self.realDotBotsView[dotBotId]['nextBumpY']))

# compute which point is closer
(nextX, nextY) = min([dotBotToTargetDistance, dotBotToBumpDistance])
if dotBotToBumpDistance < dotBotToTargetDistance:
(nextX, nextY) = (self.realDotBotsView[dotBotId]['nextBumpX'], self.realDotBotsView[dotBotId]['nextBumpY'])

# scale positions
(scaledX, scaledY) = self.getRealCoordinates(nextX, nextY)
Expand Down
4 changes: 3 additions & 1 deletion Orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,9 @@ def __init__(self, numRobots, orchX, orchY, initialPositions, relayAlgorithm="Re
self.dotBotsView[dotBotId]['heading'] = 360*random.random()
self.dotBotsView[dotBotId]['speed'] = 1
self.dotBotsView[dotBotId]['movementTimeout'] = 0.5

(nextX, nextY) = u.computeCurrentPosition(self.initialPositions[0][0], self.dotBotsView[dotBotId]['heading'],self.initialPositions[0][1], 1, 0.5)
if self.connector:
self.connector.updateTargetCoordinates(dotBotId, (nextX, nextY))
#======================== public ==========================================

#=== admin
Expand Down

0 comments on commit e328358

Please sign in to comment.