コード例 #1
0
    def __init__(self):
        """Initialize agent instance, create subscribers and publishers."""
        # Create a publisher for commands
        self.pub = rospy.Publisher('cmd_vel', Twist, queue_size=1)

        # Initialize class variables
        self.agent = Boid()

        # Create subscribers
        subs = [
            mf.Subscriber("nearest", OdometryArray),
            mf.Subscriber("avoid", PoseArray)
        ]
        self.ts = mf.TimeSynchronizer(subs, 10)
        self.ts.registerCallback(self.callback)

        rospy.Subscriber('/param_update',
                         Empty,
                         self.param_callback,
                         queue_size=1)

        # Main while loop.
        rate = rospy.Rate(10)
        while not rospy.is_shutdown():
            rate.sleep()
コード例 #2
0
    def __init__(self):
        """Initialize agent instance, create subscribers and publishers."""
        # Initialize class variables.
        init_vel_x = rospy.get_param("~init_vel_x", 0)
        init_vel_y = rospy.get_param("~init_vel_y", 0)
        frequency = rospy.get_param("/ctrl_loop_freq")
        wait_count = int(rospy.get_param("/wait_time") * frequency)
        start_count = int(rospy.get_param("/start_time") * frequency)
        self.run_type = rospy.get_param("/run_type")
        self.agent = Boid(init_vel_x, init_vel_y, wait_count, start_count, frequency)
        self.markers = MarkerSet()
        self.params_set = False

        # Create a publisher for commands.
        self.cmd_vel_pub = rospy.Publisher('cmd_vel', Twist, queue_size=frequency)
        self.markers_pub = rospy.Publisher('markers', MarkerArray, queue_size=frequency)

        # Create subscribers.
        rospy.Subscriber('/dyn_reconf2/parameter_updates', Config, self.param_callback, queue_size=1)
        rospy.Subscriber('/virtual_robot2/odom', Odometry, self.virtual_robot_callback, queue_size=10)

        subs = [mf.Subscriber("nearest", OdometryArray), mf.Subscriber("avoid", PoseArray)]
        self.ts = mf.TimeSynchronizer(subs, 10)
        self.ts.registerCallback(self.callback)

        # Keep program from exiting
        rospy.spin()
コード例 #3
0
def setup():
    size(600, 600)
    noStroke()
    global boid
    boid = Boid(width / 2, height / 2, 10, 1)
コード例 #4
0
from p5 import *
import numpy as np
from boids import Boid

width = 500
height = 500
flock = [Boid(*np.random.rand(2) * width, width, height) for _ in range(50)]


def setup():
    #this happens just once
    size(width, height)  #instead of create_canvas


def draw():
    #this happens every time
    background(30, 30, 47)
    for boid in flock:
        boid.show()
        boid.apply_behaviour(flock)
        boid.update()


run()
コード例 #5
0
ファイル: flock.py プロジェクト: ajpkim/boids
 def __init__(self, n, width, height):
     self.boids = [Boid(np.array([random.random()*width, random.random()*height]),
                        width, height) for i in range(n)]
     self.width = width
     self.height = height
コード例 #6
0
rule1W = 100
rule2W = 100
rule3W = 100
desired_seperation = 20
#desired_position = np.array([100,600]) #You can give static desired positions like this
desired_position = np.zeros(2, dtype=np.int32)
step_size = 10

# Create flocks
N = 40  #Total number of boids
flock = [None for _ in range(N)]
for i in range(N):
    initial_position = np.zeros(2, dtype=np.int32)
    initial_position[0] = np.random.randint(0, width - 10)  # x coordinate
    initial_position[1] = np.random.randint(0, height - 10)  # y coordinate
    flock[i] = Boid(width,height,initial_position,horizon,max_speed,rule1W,rule2W,rule3W, \
                    desired_seperation)


def setup():
    global bg
    size(width, height)  #Background image is width x height
    bg = load_image("images/UW_background.png")


def draw():  #This is the main loop for p5 library
    global flock
    background(bg)

    for boid in flock:
        boid.tend_to_place(desired_position, step_size)
        boid.main_boid(flock)