Ejemplo n.º 1
0
    def launch_triggered(self):
        """
        Prepares the launching of nodes based on the robot items in the current launch list and docking station properties.
        Before launch: 
        1. Checks if the number of assigned robots does not exceed a docking stations capacity.
        2. Check if the launch list has any robots at all.
        If any issues are encountered, a MessageBox is displayed to the user informing them as such.
        Otherwise the created list of Robot class objects is launched by calling "launch_nodes()".
        """
        self.launch_list = []  # Empty launch list
        # Commision all docking stations (overwriting any previous docking cells)
        for ds in self.docking_station_dict.values():
            ds.commission()

        # Iterate over all existing (top level) items (a.k.a. robots) in the robotTree and add as robot class objects
        root = self.robotTree.invisibleRootItem()
        child_count = root.childCount()
        self.robot_navigation_dict = {}
        assignment_issue = False
        ds_issue = ""
        for i in range(child_count):
            item = root.child(i)
            robot = Robot(str(item.text(0)))
            succesful_assignment = robot.assign_cell(
                self.docking_station_dict[str(item.text(3))]
            )  # Assign docking station based on item.text(3) as key for docking station dictionairy which has all ds class objects. (ds01, ds02, ds03)
            self.robot_navigation_dict[str(item.text(0))] = str(item.text(1))
            self.launch_list.append(robot)
            if not succesful_assignment:
                assignment_issue = True
                ds_issue = str(item.text(3))
                break

        if not self.launch_list:
            # launch_list is empty, throw error.
            QtGui.QMessageBox.warning(
                self, "Launch list is empty!",
                "You must have at least 1 robot in the 'Launch list' before you can launch."
            )
        elif assignment_issue:
            # Docking station over max capacity, throw error.
            QtGui.QMessageBox.warning(
                self, "Maximum capacity exceeded!",
                "Docking station " + ds_issue +
                " maxiumum capacity is being exceeded, unable to launch the current setup."
            )
        else:
            global launch_status
            launch_status = launchStatus.LAUNCHED
            print("Launching!")
            self.labelStatusText.setText("Launching...")
            print(self.launch_list)
            self.launch_nodes()
            print(launch_status)
            self.set_launched_gui()
Ejemplo n.º 2
0
def main():
    rob = Robot()
    if rob.distance_sensor.get_right_inches(
    ) < rob.distance_sensor.get_left_inches():
        follow_right(rob)
    else:
        follow_right(rob)
Ejemplo n.º 3
0
def make_data(N,
              num_landmarks,
              world_size,
              measurement_range,
              motion_noise,
              measurement_noise,
              distance,
              is_debug=False):
    # check if data has been made
    complete = False

    while not complete:
        data = []

        # make robot and landmarks
        robot = Robot(world_size, measurement_range, motion_noise,
                      measurement_noise)
        if is_debug:
            robot.make_debug_landmarks(num_landmarks)
        else:
            robot.make_landmarks(num_landmarks)
        seen = [False for row in range(num_landmarks)]

        # guess an initial motion
        orientation = random.random() * 2.0 * np.pi
        dx = np.cos(orientation) * distance
        dy = np.sin(orientation) * distance

        for k in range(0, N - 1):
            #print('Run: ', k)
            # collect sensor measurements in a list, Z
            Z = robot.sense()

            # check off all landmarks that were observed
            for i in range(0, len(Z)):
                seen[Z[i][0]] = True

            # move
            while not robot.move(dx, dy):
                # if we'd be leaving the robot world, pick instead a new direction
                orientation = random.random() * 2.0 * np.pi
                dx = np.cos(orientation) * distance
                dy = np.sin(orientation) * distance

            # collect/memorize all sensor and motion data
            data.append([Z, [dx, dy]])

        # we are done when all landmarks were observed; otherwise re-run
        complete = (sum(seen) == num_landmarks)

    print(' ')
    print('Landmarks: ', robot.landmarks)
    print(robot)

    return data
def main():
    from robot_class import Robot
    rob = Robot()
    while (True):
        if rob.distance_sensor.get_right_inches(
        ) < rob.distance_sensor.get_left_inches():
            follow_right(False, rob)
        else:
            follow_left(False, rob)
Ejemplo n.º 5
0
def make_data(N, num_landmarks, world_size, measurement_range, motion_noise, measurement_noise, distance, visualize=False):
    complete = False
    robot_instance = None
    data = list()

    while not complete:
        data = []

        # make Robot and landmarks
        robot_instance = Robot(world_size, measurement_range, motion_noise, measurement_noise)
        print('Robot x: {}, y: {}'.format(robot_instance.x, robot_instance.y))
        robot_instance.make_landmarks(num_landmarks)
        seen = [False for row in range(num_landmarks)]

        # guess an initial motion
        orientation = random.random() * 2.0 * pi
        dx = cos(orientation) * distance
        dy = sin(orientation) * distance

        for k in range(N - 1):

            # collect sensor measurements in a list, Z
            Z = robot_instance.sense()

            # check off all landmarks that were observed 
            for i in range(len(Z)):
                seen[Z[i][0]] = True

            # move
            while not robot_instance.move(dx, dy):
                # if we'd be leaving the Robot world, pick instead a new direction
                orientation = random.random() * 2.0 * pi
                dx = cos(orientation) * distance
                dy = sin(orientation) * distance

            if visualize:
                display_world(int(world_size), [robot_instance.x, robot_instance.y], robot_instance.landmarks)
                plt.arrow(robot_instance.x, robot_instance.y, dx, dy, color='k', head_width=1)
            # collect/memorize all sensor and motion data
            data.append([Z, [dx, dy]])

        # we are done when all landmarks were observed; otherwise re-run
        complete = (sum(seen) == num_landmarks)

    print(' ')
    print('Landmarks: ', robot_instance.landmarks)
    print(robot_instance)

    return data
Ejemplo n.º 6
0
def main(demonstrating):
    rob = Robot()

    desired_distance = 5
    # Proportional gain
    Kp = 1.5

    user_input = input(
        "Place robot in front of wall and press enter to continue.")

    if demonstrating:
        while True:
            distance = rob.distance_sensor.get_front_inches()
            proportional_control = saturation_function(
                Kp * (desired_distance - distance),
                rob.encoder.get_max_forward_speed(),
                rob.encoder.get_max_backward_speed())
            rob.encoder.setSpeedsIPS(proportional_control,
                                     proportional_control)
            time.sleep(0.01)
    else:
        start_time = time.monotonic()
        distance_list = []
        x_axis = []
        while time.monotonic() <= (start_time + 30):
            distance = rob.distance_sensor.get_front_inches()
            proportional_control = saturation_function(
                Kp * (desired_distance - distance),
                rob.encoder.get_max_forward_speed(),
                rob.encoder.get_max_backward_speed())
            rob.encoder.setSpeedsIPS(proportional_control,
                                     proportional_control)
            distance_list.append(distance)
            time.sleep(0.01)
            x_axis.append(time.monotonic() - start_time)

        plt.plot(x_axis, distance_list)
        plt.suptitle("Distance from wall over 30s with Kp ={0}".format(Kp))
        plt.ylabel("Distance (inches)")
        plt.xlabel("Time (seconds)")
        plt.show()
from dinosaur_class import Dinosaur
from robot_class import Robot
from fleet_class import Fleet
from herd_class import Herd
from weapon_class import Weapon
from battlefield_class import Battlefield

if __name__ == '__main__':

    # battlefield = Battlefield
    # battlefield.run_game()

    # instantiate 3 robots
    dex = Robot()
    robo_jojo = Robot()
    chappie = Robot()

    # instantiate 3 dinosaurs
    dino = Dinosaur()
    gino = Dinosaur()
    nino_brown = Dinosaur()

    # assign robot names
    dex.name = "dex"
    robo_jojo.name = "robo jojo"
    chappie.name = "chappie"

    # show robot stats
    print(dex.robot_stats())
    print(robo_jojo.robot_stats())
    print(chappie.robot_stats())
Ejemplo n.º 8
0
# Stops the robot

from robot_class import Robot

rob = Robot(True)
rob.stop()
Ejemplo n.º 9
0
def main1():
    print("started")
    print("-------")
    world_size = 10.0  # size of world (square)
    measurement_range = 5.0  # range at which we can sense landmarks
    motion_noise = 0.2  # noise in robot motion
    measurement_noise = 0.2  # noise in the measurements

    # instantiate a robot, r
    r = Robot(world_size, measurement_range, motion_noise, measurement_noise)

    # print out the location of r
    print(r)

    # define figure size
    plt.rcParams["figure.figsize"] = (5, 5)

    # call display_world and display the robot in it's grid world
    print(r)
    display_world(int(world_size), [r.x, r.y])

    # choose values of dx and dy (negative works, too)
    dx = 1
    dy = 2
    r.move(dx, dy)

    # print out the exact location
    print(r)

    # display the world after movement, not that this is the same call as before
    # the robot tracks its own movement
    display_world(int(world_size), [r.x, r.y])

    # create any number of landmarks
    num_landmarks = 3
    r.make_landmarks(num_landmarks)

    # print out our robot's exact location
    print(r)

    # display the world including these landmarks
    display_world(int(world_size), [r.x, r.y], r.landmarks)

    # print the locations of the landmarks
    print('Landmark locations [x,y]: ', r.landmarks)
    # try to sense any surrounding landmarks
    measurements = r.sense()

    # this will print out an empty list if `sense` has not been implemented
    print(measurements)

    data = []

    # after a robot first senses, then moves (one time step)
    # that data is appended like so:
    data.append([measurements, [dx, dy]])

    # for our example movement and measurement
    print(data)
    # in this example, we have only created one time step (0)
    time_step = 0

    # so you can access robot measurements:
    print('Measurements: ', data[time_step][0])

    # and its motion for a given time step:
    print('Motion: ', data[time_step][1])
Ejemplo n.º 10
0
                num_f += 1
            # time.sleep(0.01)
        if num_f > num_t:
            available_directions.append('f')

        if len(available_directions) > 0:
            direction = available_directions[random.randint(
                0,
                len(available_directions) - 1)]
        else:
            direction = 'b'

        if direction == 'r':
            print("Turning right")
            rob.rotate('r')
        if direction == 'l':
            print("Turning left")
            rob.rotate('l')
        if direction == 'b':
            print("U-turn")
            rob.rotate('r')
            rob.rotate('r')

        print("Moving forward")
        rob.forward()


## Main program
if __name__ == "__main__":
    rob = Robot()
    navigate(rob)
Ejemplo n.º 11
0
# Stops the robot

from robot_class import Robot

rob = Robot()
rob.stop()
Ejemplo n.º 12
0
from robot_class import Robot
import time

rob = Robot()
rob.rotate('l')
while True:
    print("front" + str(rob.distance_sensor.get_front_inches()))
    print("left" + str(rob.distance_sensor.get_left_inches()))
    print("right" + str(rob.distance_sensor.get_right_inches()))
    print()
    time.sleep(0.5)
Ejemplo n.º 13
0
from robot_class import Robot
import time

rob = Robot()
while True:
    rob.center_rotate(rob.distance_sensor.get_left_inches)
    time.sleep(1)
Ejemplo n.º 14
0
"""Getting map"""
pool_kernel = 20
init_map = rospy.wait_for_message("/map", OccupancyGrid)
print(init_map.info.height, init_map.info.width, init_map.info.resolution)
map_res = init_map.info.resolution
map = np.reshape(init_map.data, (init_map.info.height, init_map.info.width)).T
map = skimage.measure.block_reduce(map, (pool_kernel, pool_kernel), np.max)
print(map.shape)
"""Reading initial positions and goals of robots"""

with open(path + '/robot_start_positions.csv', mode='r') as csv_file:
    csv_reader = csv.reader(csv_file, delimiter=',')
    for i, row in enumerate(csv_reader):
        if (i == 0): continue
        goal = [int(row[3]), int(row[4])]
        new_robot = Robot(i - 1, map_res, pool_kernel, goal)
        robots.append(new_robot)
"""Writing data file with names"""

with open(path + '/robot_data.csv', mode='w') as robot_file:
    robot_writer = csv.writer(robot_file,
                              delimiter=',',
                              quotechar='"',
                              quoting=csv.QUOTE_MINIMAL)
    for robot in robots:

        print(int(robot.pose.x / (map_res * pool_kernel)),
              int(robot.pose.y / (map_res * pool_kernel)))
        robot_writer.writerow([
            robot.name, robot.start_pose[0], robot.start_pose[1],
            robot.goal_pose[0], robot.goal_pose[1]
Ejemplo n.º 15
0
from robot_class import Robot

robot = Robot()

robot.makeExcelFile()
Ejemplo n.º 16
0
from robot_class import Robot

rob = Robot()

rob.forward()
Ejemplo n.º 17
0
leftIR = 14
middleIR = 15
rightIR = 18

buttonPin = 26
buttonstate = 1
started = False
stop = False
kruisingCount = 0
route = 0
draaitijdcount = 0
start = 0

print(route)

robot = Robot()


def kruispunt(
    route
):  # In deze collectie van if statements wordt er gekeken welke route er is opgegeven.
    if (route == 1):  # 1 staat voor links.
        knipper_links()
        for x in range(0, 150):
            robot.linksaf()
        while (GPIO.input(middleIR)):
            robot.scherplinks()
    elif (route == 2):  # 2 staat voor rechtdoor.
        sleep(2)
        for x in range(0, 150):
            robot.rechtdoor()
Ejemplo n.º 18
0
import RPi.GPIO as GPIO
from time import sleep
from robot_class import Robot

GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)

robot = Robot()
buttonPin = 26
buttonstate = 1
started = False
run = True

GPIO.setup(21, GPIO.OUT)  #linker lichten
GPIO.setup(20, GPIO.OUT)  #worden de disco's
GPIO.setup(16, GPIO.OUT)  #rechter lichten

GPIO.setup(buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.add_event_detect(buttonPin, GPIO.RISING)

while run:
    buttonstate = GPIO.input(buttonPin)
    if (buttonstate == 0):
        print "start"
        started = True
        while started:
            for x in range(0, 1000):
                robot.scherprechts()  #links vooruit, rechts achteruit
                GPIO.output(16, True)  #rechts ook vooruit
                GPIO.output(21, False)
            for x in range(0, 1000):
Ejemplo n.º 19
0
Boundry = [[0, 0], [20, 20]]

start = [0, 0, 0, 0]
#x,y,F,g
goal = [20, 20, 0, 20]

isl = [[9, 15]]

obstacle = [[12, 12], [11, 13], [10, 14], [13, 11], [14, 10], [13,
                                                               13], [12, 14],
            [11, 15], [14, 12], [15, 11], [11, 11], [10, 13], [12, 10],
            [13, 9], [13, 12], [12, 13], [11, 12], [12, 11]]

#Riz Objects
Dsp = display_2d(Boundry)
Bot = Robot(Boundry, start)
Heur = EucliHeur(start, goal, obstacle, isl)


def isOpenEmpty():
    if (len(OPEN1) == 0 and len(OPEN2) == 0):
        return True
    else:
        return False


def isGoal(n):
    if (n[0] == goal[0] and n[1] == goal[1]):
        return True
    else:
        return False