Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from marabunta import BaseRobot
from math import sin,cos,pi
class HeadingConsensusRobot(BaseRobot):
"""Robot model for heading consensus.
By iteratively calling the update() method,
this robot will communicate with the rest
of the swarm and align its heading to the
swarm's mean heading.
Obstacle avoidance (implemented in BaseRobot)
will take precence over consensus reaching.
"""
#def __init__(self, body, network):
# BaseRobot.__init__(self, body, network)
# return
def heading_target(self):
"""Get the other agent's state and
compute the mean heading. Note that
from marabunta import BaseRobot
from math import *
class MarchingRobot(BaseRobot):
"""Robot model for marching algorithm.
By iteratively calling the update() method,
this robot will communicate with the rest
of the swarm and move in a way that
simulatenouslty tries to
[Spread] stay away from the closest neighbor ,
[Heading] achieve heading consensus , and
[Group] stay close to the group of neighbors.
The importance of each of these three aspects can
be set with the variables S, H and G.
Typical values are given by default but the optimal
parameters can drastically change depending on the
properties of the agents and the desired outcome.
Takes a *threshold* parameter to determine when it
has reached a "good enough" state. Can be set to 0.
Obstacle avoidance (implemented in BaseRobot)
from marabunta import BaseRobot, ebotBody, XBeeNetwork, XBeeExpirationNetwork
from math import *
from time import time,sleep
import sys
from threading import Lock
from settings import s
class Leader(BaseRobot):
def update(self, deltat, v=None):
self.broadcast_state()
if self.obstacle_infront():
v = 0.0
self.move_forward(deltat, v)
return
dt=0.05
total_time = 50
speed=0.15
try:
num_friends = float(sys.argv[1])-1
except:
num_friends = 4-1
from marabunta import BaseRobot
from math import *
class PerimeterDefenseRobot(BaseRobot):
"""Robot model for perimeter defense.
By iteratively calling the update() method,
this robot will communicate with the rest
of the swarm and move away from the others
as far as possible. Takes a *threshold*
parameter to determine when it has gone
far enough and reached consensus. Can be
set to 0.
Obstacle avoidance (implemented in BaseRobot)
will take precence over consensus reaching.
"""
def __init__(self, body, network, threshold):
BaseRobot.__init__(self, body, network)
self.threshold = threshold
self.rendezvous_point = None
self.path = []
from marabunta import BaseRobot, MockBody, MockNetwork
import random
# for visualization
import numpy as np
import pylab as pl
class myRobot(BaseRobot):
def __init__(self, setting):
body = MockBody(setting.get("position") ,setting.get("heading"))
network = MockNetwork(setting.get("ID"))
BaseRobot.__init__(self,body, network)
return
def spread_target(self):
neis = self.get_agents().values()
pos = self.body.get_position()
# Get both neighbors and obstacles, in relative coordinates
obstacles = self.body.obstacle_coordinates()
points = [ [nei[0]-pos[0], nei[1]-pos[1]] for nei in neis] + obstacles
if points:
target = [0.,0.]
for p in points:
d2 = p[0]**2 + p[1]**2