Swarm Project: End Result

As it turns out, our final project ran into a few issues in terms of putting all the code together and running final testing with serial communication. As a result, we did not manage to get the swarm running, but we do have the main code, as well as the specific functions for flipping camera axis. 

As stated, here was our original plan:

  1. Object is detected within boundary
  2. Robot with the shortest distance to the object will move first to “attack” it
  3. The robot will navigate to the object and attempt to push it out the boundary
  4. If the robot is unable to do so (most likely if the object is too heavy), the rest of the bots will navigate to the object as well, forming a chain sequence behind the first bot to help push the object out
  5. Once the object is pushed out, the bots will resume original reset positionsOf course, we did manage to code every step we intended to run, including an extra step of solving the camera axis inversion.  Here are some problems we managed to solve during the process:

calculating the position of bot, as well as the angle it is facing (performed by recognizing the four corners of the bot’s QR code)

def calcBotData(data): #data has the four corners #calcBotData returns the x,y of the center of the bot and the angle it is facing, can also be used for the enemy bot
id = data[0]
corner1 = data[1]#corner1data Should be at the location of the head
corner2 = data[2]#corner2data Should be at the location of the tail
#these corners are across from each other

#calculating center of the bot
x = (headx + tailx)/2
y = (heady + taily)/2

headx = corner1[0]
heady = corner1[1]
dy = heady - y
dx = headx - x

angle = math.atan2(dy, dx)
if angle < 0:
angle = 2*math.pi - angle

#THIS ANGLE IS IN RADIANS
return [id,x,y,angle]

sending ‘reinforcement bots’ in the case where one bot cannot push out the object

def initiateCall(availablebots, enemy, dest):

reinforcementBot = availablebots[0] #store first bot in list into variable
availablebots = availablebots[1:]

distance = math.hypot(reinforcementBot[0][0] - enemy[0], reinforcementBot[0][1] - enemy[1])

timeA = 6.38 * orient(reinforcementBot, dest)
timeD = 60 * distance

command = str(reinforcementBot[0])+ ",0,"+ str(timeA)
#SEND TO SERIAL
sleep(timeA + 2)
command = str(reinforcementBot[0])+ ",1,"+ str(timeD)
#SEND TO SERIAL

timeA = 6.38 * orient(reinforcementBot, dest)
command = str(reinforcementBot[0])+ ",0,"+ str(timeA)
#SEND TO SERIAL

command = str(reinforcementBot[0])+ ",1,0"
#SEND TO SERIAL

return availablebots

resetting the bot position 

def reset(robots):
received = robots
for i in range(3): #for each bot
move[i][0] = bot[i][0]
for j in range(1,3): #calculate vector, j = 1 for x, j = 2 for y
move[i][j] = start[i][j] - received[i][j]

if move[i][1] != 0: #exclude x = 0
tanAngle[i] = move[i][2] / move[i][1] #calculate tan, y/x
if move[i][2] > 0: # y > 0
angle[i] = math.atan(tanAngle) #angle = 0 ~ pi
elif move[i][2] < 0:
angle[i] = math.atan(tanAngle) + math.pi #angle = pi ~ 2pi
elif move[i][2] == 0: # angle = 0 or pi
if move[i][1] > 0: #x > 0
angle[i] = 0;
else: #x < 0
angle[i] = math.pi
else: # x = 0
if move[i][2] > 0: # y > 0
angle = math.pi / 2
elif move[i][2] < 0:
angle = math.pi / 2 * 3
else:
angle = 0

However, due to time constraints, as well as the ambitious nature of our project, we had to implement the training time during the end of the week, which resulted in some setbacks. Namely, we didn’t expect to have so much trouble sending signals to the bot using serial, and after several attempted test runs, we had to leave the project as is to work on the final. 

With that being said, because the main issue was that the serial wasn’t working, we actually have no idea if the code runs properly or not. Our hope is that for future improvements, we would tackle the serial issue, and then test out the full swarm code if possible.

Leave a Reply