Beispiel #1
0
class TestStatus(unittest.TestCase):

    def setUp(self):
        rospy.init_node('test_status')
        self.robot = Robot('robot_0', 1, 0.5, 1, 1, pi/2)
        self.robot1 = Robot('robot_1', 1, 0.5, 5, 5, pi/2)

        # Execute robots a few times to allow statuses to become existant.
        for i in range(0, 10):
            self.robot.execute()
            self.robot1.execute()
            time.sleep(0.1)

    def test_init(self):
        """Checks if status exists after initialising."""
        self.assertIsNotNone(self.robot.curr_robot_messages)
        self.assertIsNotNone(self.robot.curr_robot_messages[1])
        self.assertIsNotNone(self.robot.curr_robot_messages[1].robot_id)

    def test_robot_id(self):
        """Tests that the robots are publishing the correct id"""
        self.assertEquals(self.robot.curr_robot_messages[1].robot_id, 'robot_1')

    def test_position(self):
        """Tests whether the robots are publishing the correct position"""
        self.assertAlmostEqual(self.robot.curr_robot_messages[1].x, 5.0, places=2)

    def to_string(self):
        return "test movement"
Beispiel #2
0
class TestStatus(unittest.TestCase):
    def setUp(self):
        rospy.init_node('test_status')
        self.robot = Robot('robot_0', 1, 0.5, 1, 1, pi / 2)
        self.robot1 = Robot('robot_1', 1, 0.5, 5, 5, pi / 2)

        # Execute robots a few times to allow statuses to become existant.
        for i in range(0, 10):
            self.robot.execute()
            self.robot1.execute()
            time.sleep(0.1)

    def test_init(self):
        """Checks if status exists after initialising."""
        self.assertIsNotNone(self.robot.curr_robot_messages)
        self.assertIsNotNone(self.robot.curr_robot_messages[1])
        self.assertIsNotNone(self.robot.curr_robot_messages[1].robot_id)

    def test_robot_id(self):
        """Tests that the robots are publishing the correct id"""
        self.assertEquals(self.robot.curr_robot_messages[1].robot_id,
                          'robot_1')

    def test_position(self):
        """Tests whether the robots are publishing the correct position"""
        self.assertAlmostEqual(self.robot.curr_robot_messages[1].x,
                               5.0,
                               places=2)

    def to_string(self):
        return "test movement"
Beispiel #3
0
 def __init__(self, robot_id, top_speed, angular_top_speed, x_offset,
              y_offset, theta_offset):
     Robot.__init__(self, robot_id, top_speed, angular_top_speed, x_offset,
                    y_offset, theta_offset)
     self.type = type(self).__name__
     self.command = None
     rospy.Subscriber("move_command", String, self.cmd_handler)
Beispiel #4
0
 def create_fleet(self):
     robot1 = Robot("Bumblebee")
     robot2 = Robot("Optimus Prime")
     robot3 = Robot("Grimlock")
     self.robots.append(robot1)
     self.robots.append(robot2)
     self.robots.append(robot3)
Beispiel #5
0
    def __init__(self, robot_id, top_speed, angular_top_speed, x_offset, y_offset, theta_offset):
        Robot.__init__(self, robot_id, top_speed, angular_top_speed, x_offset, y_offset, theta_offset)

        #define max/min coordinates for orchard space
        boundaries = locations.get_orchard_boundaries()
        self.maxX = boundaries["max_x"]
        self.maxY = boundaries["max_y"]
        self.minX = boundaries["min_x"]
        self.minY = boundaries["min_y"]
        self.has_bin = False
        self.type = type(self).__name__

        # Unique variables for picker robots
        # self.picker_dict = dict()
        self.current_bin_x = 0
        self.current_bin_y = 0

        self.fruit_count = 0

        self.has_finished = False

        empty_response_pub = rospy.Publisher('empty_response_topic', empty_response, queue_size=10)

        def callback(data):
            """Execute method in response to "bin_status" message."""
            if data.is_empty:
                # Data used to calculate if it's the closest to the bin
                rospy.loginfo("Bin call: " + data.bin_id + " %.1f       %.1f" % (data.x, data.y))
                self.current_bin_x = data.x
                self.current_bin_y = data.y
            
                # rospy.loginfo(len(self.picker_dict))
                if self.is_closest() and not self.has_bin:  # and not self.slave and not data.is_carried:
                    self.has_finished = False
                    current_bin = robot_storage.getRobotWithId(data.bin_id)
                    if current_bin.designated_picker == None:
                        self.has_bin = True
                        self.add_action(NavigateAction(self.current_bin_x, self.current_bin_y))
                        rospy.loginfo("P Robot: " + self.robot_id + "    " + "Bin closest: " + data.bin_id)
                        msg = empty_response()
                        msg.robot_id = self.robot_id
                        msg.bin_id = data.bin_id
                        rospy.loginfo(self.robot_id + msg.robot_id + msg.bin_id + data.bin_id)
                        empty_response_pub.publish(msg)
                        rospy.loginfo("??????????????????////???????????????????")

        def initiate_picking(data):
            if data.robot_id == self.robot_id:
                pickerx = robot_storage.getRobotWithId(data.robot_id)
                self.x_start = self.position['x']
                self.y_start = self.position['y']
                self.add_action(NavigatePickAction(pickerx.position["x"], self.maxY + 5))

        rospy.Subscriber("bin_status_topic", bin_status, callback)

        # rospy.Subscriber("statuses", robot_status, picker_locations)

        rospy.Subscriber("latched_to_picker", empty_response, initiate_picking)
Beispiel #6
0
def test_name_does_not_change_when_rebooted():
    robot = Robot()
    robot.start()
    name1 = robot.name()

    robot.stop()
    robot.start()
    name2 = robot.name()
    assert name1 == name2
Beispiel #7
0
    def __init__(self, robot_id, top_speed, angular_top_speed, x_offset, y_offset, theta_offset):
        Robot.__init__(self, robot_id, top_speed, angular_top_speed, x_offset, y_offset, theta_offset)
        self.counter = 0

        boundaries = locations.get_wall_boundaries()
        self.min_x = int(boundaries["min_x"])
        self.max_x = int(boundaries["max_x"])
        self.min_y = int(boundaries["min_y"])
        self.max_y = int(boundaries["max_y"])
Beispiel #8
0
    def __init__(self, robot_id, top_speed, angular_top_speed, x_offset, y_offset, theta_offset):
        Robot.__init__(self, robot_id, top_speed, angular_top_speed, x_offset, y_offset, theta_offset)
        self.type = type(self).__name__

        # Unique booleans for Bin instance
        self.slow_down_counter = 0
        self.is_publishing = True
        self.is_empty = True
        self.is_carried = False
        self.designated_picker = None
        self.designated_carrier = None
        self.master = None
        self.should_face = None
        self.empty_response_msg = empty_response()
        self.bin_latch = rospy.Publisher('latched_to_picker', empty_response, queue_size=1)
        # self.bin_full_latch = rospy.Publisher('latched_to_carrier', full_response, queue_size=1)

        def id_response(data):
            """Execute method in response to an empty_response message."""
            # rospy.loginfo("SDAFDFDSFDSAFDSAFDSAFDSAFDSAFSADFADSFSADF")
            if data.bin_id == self.robot_id:

                self.is_publishing = False
                
                robot = robot_storage.getRobotWithId(data.robot_id)
                if robot.type == "PickerRobot":
                    self.designated_picker = data.robot_id
                elif robot.type == "CarrierRobot":
                    self.designated_carrier = data.robot_id
                # rospy.loginfo(self.robot_id + "    " + data.robot_id)
            # self.is_carried = True

        def mimic_now(data):              
            """Execute method in response to a robot_status message"""
            if not self.should_face and data.robot_id == self.designated_picker and not self.master:
                if (data.x - 0.4) <= self.position['x'] <= (data.x + 0.4):
                    if (data.y - 0.4) <= self.position['y'] <= (data.y + 0.4):
                        picker = robot_storage.getRobotWithId(data.robot_id)
                        # rospy.loginfo(data.robot_id)
                        self.latch(picker)
                        self.empty_response_msg.robot_id = data.robot_id
                        self.empty_response_msg.bin_id = self.robot_id


            if not self.should_face and data.robot_id == self.designated_carrier and not self.master:
                if (data.x - 0.4) <= self.position['x'] <= (data.x + 0.4):
                    if (data.y - 0.4) <= self.position['y'] <= (data.y + 0.4):
                        carrier = robot_storage.getRobotWithId(data.robot_id)
                        # rospy.loginfo(data.robot_id)
                        self.latch(carrier)
                        self.empty_response_msg.robot_id = data.robot_id
                        self.empty_response_msg.bin_id = self.robot_id

        # Suscribe to topic to recieve response from pickers.
        rospy.Subscriber("empty_response_topic", empty_response, id_response)
        rospy.Subscriber("statuses", robot_status, mimic_now)
Beispiel #9
0
    def setUp(self):
        rospy.init_node('test_status')
        self.robot = Robot('robot_0', 1, 0.5, 1, 1, pi/2)
        self.robot1 = Robot('robot_1', 1, 0.5, 5, 5, pi/2)

        # Execute robots a few times to allow statuses to become existant.
        for i in range(0, 10):
            self.robot.execute()
            self.robot1.execute()
            time.sleep(0.1)
Beispiel #10
0
    def setUp(self):
        rospy.init_node('test_status')
        self.robot = Robot('robot_0', 1, 0.5, 1, 1, pi / 2)
        self.robot1 = Robot('robot_1', 1, 0.5, 5, 5, pi / 2)

        # Execute robots a few times to allow statuses to become existant.
        for i in range(0, 10):
            self.robot.execute()
            self.robot1.execute()
            time.sleep(0.1)
Beispiel #11
0
    def __init__(self, robot_id, top_speed, angular_top_speed, x_offset,
                 y_offset, theta_offset):
        Robot.__init__(self, robot_id, top_speed, angular_top_speed, x_offset,
                       y_offset, theta_offset)
        self.counter = 0

        boundaries = locations.get_wall_boundaries()
        self.min_x = int(boundaries["min_x"])
        self.max_x = int(boundaries["max_x"])
        self.min_y = int(boundaries["min_y"])
        self.max_y = int(boundaries["max_y"])
Beispiel #12
0
    def __init__(self, robot_id, top_speed, angular_top_speed, x_offset, y_offset, theta_offset):
        Robot.__init__(self, robot_id, top_speed, angular_top_speed, x_offset, y_offset, theta_offset)
        self.type = type(self).__name__

        # Unique variables for carrier robots
        self.carrier_dict = dict()
        self.current_bin_x = 0
        self.current_bin_y = 0
        self.has_bin = False
        self.counter = 0
        self.going_towards = None

        empty_response_pub = rospy.Publisher('empty_response_topic', empty_response, queue_size=10)

        def callback(data):
            if not data.is_empty:
                self.current_bin_x = data.x
                self.current_bin_y = data.y

                current_bin = robot_storage.getRobotWithId(data.bin_id)

                if self.is_closest() and not self.has_bin and not current_bin.designated_carrier:
                    self.going_towards = data.bin_id
                    current_bin.designated_carrier = self.robot_id
                    rospy.loginfo("Carrier bot coming towards bin " + data.bin_id + " at " + str(self.current_bin_x) + ", " + str(self.current_bin_y))
                    self.has_bin = True
                    self.add_action(NavigateAction(self.current_bin_x, self.current_bin_y))
                    rospy.loginfo("P Robot: " + self.robot_id + "    " + "Bin closest: " + data.bin_id)
                    msg = empty_response()
                    msg.robot_id = self.robot_id
                    msg.bin_id = data.bin_id
                    empty_response_pub.publish(msg)

        def bin_carrying(data):
            if data.robot_id == self.robot_id:
                rospy.loginfo("carrier " + self.robot_id + " going up to driveway")
                carrierx = robot_storage.getRobotWithId(data.robot_id)
                for i in range(0,3):
                    if not bin_locations[i]['occupied']:
                        bin_locations[i]['occupied'] = True
                        self.add_action(NavigateAction(bin_locations[i]['x'], bin_locations[i]['y']))
                        self.add_action(UnlatchAction(self.slave))
                        break
                    if i is 3:
                        # Locations should never be all full, but who knows?
                        bin_locations[i]['occupied'] = True
                        self.add_action(NavigateAction(bin_locations[i]['x'], bin_locations[i]['y']))

        rospy.Subscriber("latched_to_picker", empty_response, bin_carrying)        

        rospy.Subscriber("bin_status_topic", bin_status, callback)
Beispiel #13
0
    def __init__(self, robot_id, top_speed, angular_top_speed, x_offset, y_offset, theta_offset):
        Robot.__init__(self, robot_id, top_speed, angular_top_speed, x_offset, y_offset, theta_offset)

        # Set boundaries
        boundaries = locations.get_wall_boundaries()
        self.min_x = boundaries["min_x"]
        self.max_x = boundaries["max_x"]
        self.min_y = boundaries["min_y"]
        self.max_y = boundaries["max_y"]

        # Instance variables
        self.was_blocked = False
        self.old_queue = []

        self.d = 7
class RobotTests(unittest.TestCase):
    def setUp(self):
        self.mega_man = Robot("Mega Man", battery=50)

    def test_charge(self):
        # make new robot each time
        # mega_man = Robot("Mega Man", battery=50)	# Use setUp to make robot once
        self.mega_man.charge()
        self.assertEqual(self.mega_man.battery, 100)

    def test_say_name(self):
        # make new robot each time
        # mega_man = Robot("Mega Man", battery=50)	# Use setUp to make robot once
        self.assertEqual(self.mega_man.say_name(),
                         "BEEP BOOP BEEP BOOP. I AM MEGA MAN")
        self.assertEqual(self.mega_man.battery, 49)
Beispiel #15
0
    def __init__(self, robot_id, top_speed, angular_top_speed, x_offset, y_offset, theta_offset):
        Robot.__init__(self, robot_id, top_speed, angular_top_speed, x_offset, y_offset, theta_offset)
        
        # Instance variables
        self.type = type(self).__name__
        self.robot_dict = dict()
        self.currently_targeting = False
        self.dict_index = -1
        self.counter = 0
        self.retreat = False

        def robot_locations(data):
            """Stores picker and carrier data from the statuses topic"""
            if data.robot_type == "PickerRobot" or data.robot_type == "CarrierRobot":
                self.robot_dict[data.robot_id] = data
        rospy.Subscriber("statuses", robot_status, robot_locations)
Beispiel #16
0
def test_robot_initial_position():
    ''' test all strings for bearings will work '''

    bearings = ['north', 'south', 'east', 'west']

    for b in bearings:
        robot = Robot(1, 2, b)
        assert robot.x == 1 and robot.y == 2 and robot.bearing == b
Beispiel #17
0
    def __init__(self, robot_id, top_speed, angular_top_speed, x_offset,
                 y_offset, theta_offset):
        Robot.__init__(self, robot_id, top_speed, angular_top_speed, x_offset,
                       y_offset, theta_offset)

        # Set boundaries
        boundaries = locations.get_wall_boundaries()
        self.min_x = boundaries["min_x"]
        self.max_x = boundaries["max_x"]
        self.min_y = boundaries["min_y"]
        self.max_y = boundaries["max_y"]

        # Instance variables
        self.was_blocked = False
        self.old_queue = []

        self.d = 7
Beispiel #18
0
 def iniData(self, points, connections, first_point, robots):
     if not robots:
         robots = 1
     self.first_point = first_point
     self.points = points
     self.points = [(x.x(), x.y()) for x in self.points]
     self.connections = connections
     self.robots = [Robot((first_point.x(), first_point.y())) for x in range(int(robots))]
 def robo_turn(self):
     self.show_robo_opponent_options()
     input("Select opponent to attack: <1> , <2> , <3>.")
     if input == 1:
         Robot.attack(dinosaur=d1)
     elif input == 2:
         Robot.attack(dinosaur=d2)
     elif input == 3:
         Robot.attack(dinosaur=d3)
     else:
         input("Please select <1> , <2> or <3>.")
Beispiel #20
0
 def setUp(self):
     rospy.init_node('test_robot')
     self.robot = Robot('robot_0', 1, 0.5, 1, 1, pi / 2)
     for i in range(0, 20):
         self.robot.execute()
Beispiel #21
0
class TestRobot(unittest.TestCase):

    def setUp(self):
        rospy.init_node('test_robot')
        self.robot = Robot('robot_0', 1, 0.5, 1, 1, pi / 2)
        for i in range(0, 20):
            self.robot.execute()

    def test_init(self):
        """Checks if subscribed information has been received."""
        self.assertIsNot(self.robot.odometry, None)
        self.assertIsNot(self.robot.leftLaser, None)
        self.assertIsNot(self.robot.rightLaser, None)

    def test_forward(self):
        """Checks if forward sets the velocity to its top speed."""
        self.robot.forward()
        self.assertEqual(self.robot.velocity.linear.x, 1)

    def test_stop(self):
        """Checks if stop sets the linear and angular velocity to 0."""
        self.robot.forward()
        self.robot.start_rotate()
        self.robot.stop()

        self.assertEqual(self.robot.velocity.linear.x, 0)
        self.assertEqual(self.robot.velocity.angular.z, 0)

    def test_set_angular_velocity(self):
        """Checks if angular velocity is set to the specified value."""
        self.robot.set_angular_velocity(0.2)
        self.assertEqual(self.robot.velocity.angular.z, 0.2)

    def test_set_linear_velocity(self):
        """Checks if linear velocity is set to the specified value."""
        self.robot.set_linear_velocity(0.7)
        self.assertEqual(self.robot.velocity.linear.x, 0.7)

    def test_start_rotate(self):
        """Checks if angular velocity is set to angular_top_speed
        and rotation_executing is set to true."""
        self.robot.start_rotate()

        self.assertEqual(self.robot.velocity.angular.z, 0.5)
        self.assertTrue(self.robot.rotation_executing)

    def test_start_rotate_opposite(self):
        """Checks if angular velocity is set to angular_top_speed in the
        negative direction and rotation_executing is set to true."""
        self.robot.start_rotate_opposite()

        self.assertEqual(self.robot.velocity.angular.z, -0.5)
        self.assertTrue(self.robot.rotation_executing)

    def test_stop_rotate(self):
        """Checks to see if angular velocity is set to 0 and
        rotation_executing is set to false."""
        self.robot.stop_rotate()

        self.assertEqual(self.robot.velocity.angular.z, 0)
        self.assertFalse(self.robot.rotation_executing)
from robots import Robot

r1 = Robot(4, 10, 'est', 'Robert', 'Humanoide', 'En service')
print('r1 =', r1)
r2 = Robot(15, 7, 'sud', 'Juliette', 'Mobile', 'En service')
print('r2 =', r2)

r1.nom = "D2R2"  # on a ajouté un nom à r1 mais r2 n'a pas de nom


def tourner_gauche(robot):
    robot.direction = (robot.direction + 3) % 4

    Robot.pivoter_gauche = tourner_gauche

    r2.pivoter_gauche()  # direction devient 'est'
    print('r2 =', r2)
Beispiel #23
0
 def test_can_create_a_robot(self):
     orange = Robot()
            # convert this laser reading to polar coordinate
            distance=range_ 
            angle=origin + num*increment

            # get world coordinate of this laser reading
            x=math.cos(angle+pose_theta)*distance
            y=math.sin(angle+pose_theta)*distance
                
            # and transform it to matrix index
            i = int(self.position_in_map.x + x/self.granularity)
            j = int(self.position_in_map.y + y/self.granularity)

            # get path from robot position to each point on laser
            path = Bresenham((self.position_in_map.x, self.position_in_map.y),
                             (i, j)).path

            # set each point on path to free
            for p in path:
                self.map_cell_add_value(p[0], p[1], self._free)

            # set the position for this laser reading as occupied
            self.map_cell_add_value(i,j,self._occ)


if __name__ == '__main__':
    from robots import Robot

    robot = Robot()
    ogm = OccupancyGridMap()
    robot.start(ogm.update_map)
Beispiel #25
0
 def setUp(self):
     self.robot = Robot(COMPILER, SANDBOX)
     self.make_file(IO_TEST_1_IN, """1 2 3 4 5\n""")
     self.make_file(IO_TEST_1_OUT, """15 120\n""")
     self.make_file(IO_TEST_2_IN, """0 1 2 3 4\n""")
     self.make_file(IO_TEST_2_OUT, """10 0\n""")
Beispiel #26
0
    def __init__(self, robot_id, top_speed, angular_top_speed, x_offset,
                 y_offset, theta_offset):
        Robot.__init__(self, robot_id, top_speed, angular_top_speed, x_offset,
                       y_offset, theta_offset)

        #define max/min coordinates for orchard space
        boundaries = locations.get_orchard_boundaries()
        self.maxX = boundaries["max_x"]
        self.maxY = boundaries["max_y"]
        self.minX = boundaries["min_x"]
        self.minY = boundaries["min_y"]
        self.has_bin = False
        self.type = type(self).__name__

        # Unique variables for picker robots
        # self.picker_dict = dict()
        self.current_bin_x = 0
        self.current_bin_y = 0

        self.fruit_count = 0

        self.has_finished = False

        empty_response_pub = rospy.Publisher('empty_response_topic',
                                             empty_response,
                                             queue_size=10)

        def callback(data):
            """Execute method in response to "bin_status" message."""
            if data.is_empty:
                # Data used to calculate if it's the closest to the bin
                rospy.loginfo("Bin call: " + data.bin_id + " %.1f       %.1f" %
                              (data.x, data.y))
                self.current_bin_x = data.x
                self.current_bin_y = data.y

                # rospy.loginfo(len(self.picker_dict))
                if self.is_closest(
                ) and not self.has_bin:  # and not self.slave and not data.is_carried:
                    self.has_finished = False
                    current_bin = robot_storage.getRobotWithId(data.bin_id)
                    if current_bin.designated_picker == None:
                        self.has_bin = True
                        self.add_action(
                            NavigateAction(self.current_bin_x,
                                           self.current_bin_y))
                        rospy.loginfo("P Robot: " + self.robot_id + "    " +
                                      "Bin closest: " + data.bin_id)
                        msg = empty_response()
                        msg.robot_id = self.robot_id
                        msg.bin_id = data.bin_id
                        rospy.loginfo(self.robot_id + msg.robot_id +
                                      msg.bin_id + data.bin_id)
                        empty_response_pub.publish(msg)
                        rospy.loginfo(
                            "??????????????????////???????????????????")

        def initiate_picking(data):
            if data.robot_id == self.robot_id:
                pickerx = robot_storage.getRobotWithId(data.robot_id)
                self.x_start = self.position['x']
                self.y_start = self.position['y']
                self.add_action(
                    NavigatePickAction(pickerx.position["x"], self.maxY + 5))

        rospy.Subscriber("bin_status_topic", bin_status, callback)

        # rospy.Subscriber("statuses", robot_status, picker_locations)

        rospy.Subscriber("latched_to_picker", empty_response, initiate_picking)
 def setUp(self):
     self.mega_man = Robot("Mega Man", battery=50)
 def __init__(self, robot_id, top_speed, angular_top_speed, x_offset, y_offset, theta_offset):
     Robot.__init__(self, robot_id, top_speed, angular_top_speed, x_offset, y_offset, theta_offset)
     self.type = type(self).__name__
     self.command = None
     rospy.Subscriber("move_command", String, self.cmd_handler)
Beispiel #29
0
def test_Robot():
    r = Robot("Marvin", "Nürnberg")
    assert r.name == "Marvin"
    assert r.city == "Nürnberg"
Beispiel #30
0
 def test_robot_forward_should_change_robot_position_to_next_position(self):
     robot = Robot()
     robot.forward()
     self.assertEqual(2, robot.position)
Beispiel #31
0
 def test_robot_back_should_change_robot_position_to_after_position(self):
     robot = Robot()
     robot.position = 2
     robot.back()
     self.assertEqual(1, robot.position)
Beispiel #32
0
 def test_robot_can_starts_at_button_1(self):
     self.assertEqual(1, Robot().position)
Beispiel #33
0
 def setUp(self):
     rospy.init_node('test_move_action')
     self.robot = Robot('robot_0', 1, 0.5, 1, 1, pi / 2)
     self.robot1 = Robot('robot_0', 1, 0.5, 0, 0, pi / 2)
Beispiel #34
0
from herd import Herd
from battlefield import Battlefield
from weapons import Weapons
import ctypes
import random

if __name__ == '__main__':

    #Battlefield
    battlefield = Battlefield()

    #Weapons
    weapons = Weapons()

    # Robots
    robot_wally = Robot("Wall-E")
    robot_wally.power_level = 100
    robot_wally.attack_power = 60
    # weapons.choose_weapon(robot_wally)

    robot_megaman = Robot("Megaman")
    robot_megaman.power_level = 110
    robot_megaman.attack_power = 100
    # weapons.choose_weapon(robot_megaman)

    robot_marvin = Robot("Marvin")
    robot_marvin.power_level = 120
    robot_marvin.attack_power = 70
    # weapons.choose_weapon(robot_marvin)

    #Dinos
Beispiel #35
0
#! /usr/bin/env python3

from robots import Robot


x = Robot("Marvin", "Nürnberg")
x.say_hi()

y = Robot("Hen", "Nürnberg")
y.say_hi()
try:
    y.name = "Henry"
except NameError as e:
    print(e)

try:
    z = Robot("Hans", "München")
except NameError as e:
    print(e)

w = x + y
w.say_hi()

print(w)
print(repr(w))
w2 = eval(repr(w))
w2.say_hi()

print(w == w2)
Beispiel #36
0
class RobotTest(unittest.TestCase):

    def __init__(self, *args, **kwargs):
        if not os.path.isdir(SANDBOX):
            os.mkdir(SANDBOX)
        super(RobotTest, self).__init__(*args, **kwargs)

    def setUp(self):
        self.robot = Robot(COMPILER, SANDBOX)
        self.make_file(IO_TEST_1_IN, """1 2 3 4 5\n""")
        self.make_file(IO_TEST_1_OUT, """15 120\n""")
        self.make_file(IO_TEST_2_IN, """0 1 2 3 4\n""")
        self.make_file(IO_TEST_2_OUT, """10 0\n""")

    def make_file(self, path, content):
        with open(path, 'w') as new:
            new.write(content)

    def test_compile_with_no_source(self):
        with open(DEVNULL, 'w') as devnull:
            self.assertRaises(ValueError, self.robot.compile, NO_SOURCE, EXECUTABLE, stdout=devnull, stderr=devnull)

    def test_compile_with_bad_executable(self):
        self.make_file(SOURCE, OK_SOURCE)
        with open(DEVNULL, 'w') as devnull:
            self.assertRaises(ValueError, self.robot.compile, SOURCE, BAD_EXECUTABLE, stdout=devnull, stderr=devnull)

    def test_evaluate_with_no_executable(self):
        self.make_file(SOURCE, CE_SOURCE)
        with open(DEVNULL, 'w') as devnull:
            self.robot.compile([SOURCE], EXECUTABLE, stdout=devnull, stderr=devnull)
            self.assertRaises(ValueError, self.robot.evaluate, EXECUTABLE, INPUT, OUTPUT, stdout=devnull, stderr=devnull)

    def test_evaluate_no_input(self):
        self.make_file(SOURCE, OK_SOURCE)
        with open(DEVNULL, 'w') as devnull, open(EXECUTABLE, 'w'):
            self.assertRaises(ValueError, self.robot.evaluate, EXECUTABLE, NO_INPUT, OUTPUT, stdout=devnull, stderr=devnull)

    def test_diff_with_equal_output(self):
        test_output = """3\n1 2 3\n"""
        user_output = """3 1 2 3\n"""
        self.make_file(TEST_OUTPUT, test_output)
        self.make_file(OUTPUT, user_output)
        self.assertFalse(self.robot.diff(TEST_OUTPUT, OUTPUT))

    def test_diff_with_non_equal_output(self):
        test_output = """4 1 2 3 4\n"""
        user_output = """3 1 2 3\n"""
        self.make_file(TEST_OUTPUT, test_output)
        self.make_file(OUTPUT, user_output)
        self.assertTrue(self.robot.diff(TEST_OUTPUT, OUTPUT))

    def test_diff_with_equal_float_output(self):
        test_output = """12.9999999 9.9999999\n"""
        user_output = """13 10\n"""
        self.make_file(TEST_OUTPUT, test_output)
        self.make_file(OUTPUT, user_output)
        self.assertFalse(self.robot.diff(TEST_OUTPUT, OUTPUT))

    def test_diff_with_non_equal_float_output(self):
        test_output = """12.99999 9.99999\n"""
        user_output = """13.0 10.1\n"""
        self.make_file(TEST_OUTPUT, test_output)
        self.make_file(OUTPUT, user_output)
        self.assertTrue(self.robot.diff(TEST_OUTPUT, OUTPUT))

    def test_run_with_ce_source(self):
        self.make_file(SOURCE, CE_SOURCE)
        test_cases = {1: dict(input=IO_TEST_1_IN, output=IO_TEST_1_OUT), 2: dict(input=IO_TEST_2_IN, output=IO_TEST_2_OUT)}
        status, memory, time, failed, log = self.robot.run([SOURCE], test_cases, IO_TEST_TIME_LIMIT, IO_TEST_MEMORY_LIMIT)
        self.assertEqual(status, Status.CE)
        self.assertEqual(memory, None)
        self.assertEqual(time, None)
        self.assertEqual(failed, None)
        self.assertNotEqual(log, None)

    def test_run_with_ok_source(self):
        self.make_file(SOURCE, OK_SOURCE)
        test_cases = {1: dict(input=IO_TEST_1_IN, output=IO_TEST_1_OUT), 2: dict(input=IO_TEST_2_IN, output=IO_TEST_2_OUT)}
        status, memory, time, failed, log = self.robot.run([SOURCE], test_cases, IO_TEST_TIME_LIMIT, IO_TEST_MEMORY_LIMIT)
        self.assertEqual(status, Status.OK)
        self.assertNotEqual(memory, None)
        self.assertNotEqual(time, None)
        self.assertEqual(failed, None)
        self.assertEqual(log, None)

    def test_run_with_fe_source(self):
        self.make_file(SOURCE, FE_SOURCE)
        test_cases = {1: dict(input=IO_TEST_1_IN, output=IO_TEST_1_OUT), 2: dict(input=IO_TEST_2_IN, output=IO_TEST_2_OUT)}
        status, memory, time, failed, log = self.robot.run([SOURCE], test_cases, IO_TEST_TIME_LIMIT, IO_TEST_MEMORY_LIMIT)
        self.assertEqual(status, Status.FE)
        self.assertNotEqual(memory, None)
        self.assertNotEqual(time, None)
        self.assertEqual(failed, 2)
        self.assertEqual(log, None)

    def test_run_with_tl_source(self):
        self.make_file(SOURCE, TL_SOURCE)
        test_cases = {1: dict(input=IO_TEST_1_IN, output=IO_TEST_1_OUT), 2: dict(input=IO_TEST_2_IN, output=IO_TEST_2_OUT)}
        status, memory, time, failed, log = self.robot.run([SOURCE], test_cases, IO_TEST_TIME_LIMIT, IO_TEST_MEMORY_LIMIT)
        self.assertEqual(status, Status.TL)
        self.assertEqual(memory, None)
        self.assertEqual(time, None)
        self.assertEqual(failed, 1)
        self.assertEqual(log, None)

    def test_run_with_sf_source(self):
        self.make_file(SOURCE, SF_SOURCE)
        test_cases = {1: dict(input=IO_TEST_1_IN, output=IO_TEST_1_OUT), 2: dict(input=IO_TEST_2_IN, output=IO_TEST_2_OUT)}
        status, memory, time, failed, log = self.robot.run([SOURCE], test_cases, IO_TEST_TIME_LIMIT, IO_TEST_MEMORY_LIMIT)
        self.assertEqual(status, Status.SF)
        self.assertNotEqual(memory, None)
        self.assertNotEqual(time, None)
        self.assertEqual(failed, 1)
        self.assertEqual(log, None)

    def test_run_with_wa_source(self):
        self.make_file(SOURCE, WA_SOURCE)
        test_cases = {1: dict(input=IO_TEST_1_IN, output=IO_TEST_1_OUT), 2: dict(input=IO_TEST_2_IN, output=IO_TEST_2_OUT)}
        status, memory, time, failed, log = self.robot.run([SOURCE], test_cases, IO_TEST_TIME_LIMIT, IO_TEST_MEMORY_LIMIT)
        self.assertEqual(status, Status.WA)
        self.assertNotEqual(memory, None)
        self.assertNotEqual(time, None)
        self.assertEqual(failed, 1)
        self.assertEqual(log, None)

    def test_run_with_re_source(self):
        self.make_file(SOURCE, RE_SOURCE)
        test_cases = {1: dict(input=IO_TEST_1_IN, output=IO_TEST_1_OUT), 2: dict(input=IO_TEST_2_IN, output=IO_TEST_2_OUT)}
        status, memory, time, failed, log = self.robot.run([SOURCE], test_cases, IO_TEST_TIME_LIMIT, IO_TEST_MEMORY_LIMIT)
        self.assertEqual(status, Status.RE)
        self.assertNotEqual(memory, None)
        self.assertNotEqual(time, None)
        self.assertEqual(failed, 1)
        self.assertEqual(log, None)
Beispiel #37
0
 def setUp(self):
     rospy.init_node('test_bin')
     self.bin = Bin('robot_0', 1, 0.5, 1, 1, pi / 2)
     self.robot = Robot('robot_1', 1, 0.5, 1, 1, pi / 2)
Beispiel #38
0
from robots import Robot
from dinosaurs import Dinosaur
from fleet import Fleet
from herd import Herd
from battlefield import Battlefield

r1 = Robot('WALL-E')
r2 = Robot('T-800')
r3 = Robot('Roomba')

d1 = Dinosaur('Trogdor', 55)
d2 = Dinosaur('Allosaurus', 42)
d3 = Dinosaur('Spinosaurus', 55)

Fleet(3)
Fleet.create_fleet(r1)
Fleet.create_fleet(r2)
Fleet.create_fleet(r3)
print(Fleet.robot_fleet)

Herd(3)
Herd.create_herd(d1)
Herd.create_herd(d2)
Herd.create_herd(d3)
print(Herd.dinosaur_herd)
Beispiel #39
0
 def setUp(self):
     rospy.init_node('test_navigate_action')
     self.robot = Robot('robot_0', 1, 0.5, 1, 1, pi/2)
def main():

    #initialize pygame
    pygame.init()
    screen = pygame.display.set_mode(SCREEN_SIZE)
    bounds = screen.get_rect()
    
    #initialize game
    player = Player(bounds.center, bounds) #sets starting position fir player
    robot = Robot((randrange(0,800),randrange(0,600)), bounds)
    player_grp = GroupSingle(player)
    #robot_grp = GroupSingle(robot)
    robot_grp = Group()
    robot_grp.add(Robot((randrange(0,800),randrange(0,600)), bounds))
    robot_grp.add(Robot((randrange(0,800),randrange(0,600)), bounds))
    robot_grp.add(Robot((randrange(0,800),randrange(0,600)), bounds))
    meteors = Group()
    impacts = Group()
    score = 0
    spawntime = 10
    spawnticker = 0
    font = pygame.font.Font(None,35)

    #game loop
    done = False
    clock = pygame.time.Clock()
    print "Loop Started"
    while not done:

        for event in pygame.event.get():
            if event.type == QUIT:
                done = True
            elif event.type == KEYDOWN and event.key == K_ESCAPE:
                done = True

            
            elif event.type == KEYDOWN and event.key == K_SPACE:
                if player.carrying:
                    player.drop()
                else:
                    for robot in groupcollide(robot_grp, player_grp, False, False):
                        player.grab(robot)
                        score += 5
                        print "robot picked up"
                        break
                
	


    #input

    #spawn meteors
	spawnticker += 1
	if spawnticker >= spawntime:
	    #print "spawned!"
	    meteors.add(Meteor((randrange(0,800),randrange(0,600)),bounds, 90, "rock"))
	    spawnticker = 0
	    
    #update
	meteors.update()
	ImpactGroup.impacts.update()
        player.update()

    #collisions
	coll = groupcollide(player_grp, ImpactGroup.impacts, False, False)
	for robot in coll:
	    robot.damage(coll[robot][0])
	
	coll = groupcollide(robot_grp, ImpactGroup.impacts, False, False)
	for robot in coll:
	    robot.damage(coll[robot][0])
    #draw
        screen.fill(BG_COLOR)
        
        robot_grp.draw(screen)
	
	ImpactGroup.impacts.draw(screen)
	meteors.draw(screen)
	player_grp.draw(screen)
	robot_grp.draw(screen)
        clock.tick(30)
        score_text = font.render("Score: %05d"%score, False, (255,255,255))
        screen.blit(score_text, (5,5))
        pygame.display.flip()
Beispiel #41
0
    def test_robot_move_to_should_move_robot_step_by_step(self):
        robot = Robot()
        for i in range(9):
            robot.move_to(10)

        self.assertEqual(10, robot.position)

#---------------
if __name__ == '__main__':

    params = Parameters(path="../config.yaml")
    mean_time = []
    std_time = []
    for lambda_ in np.linspace(0, 2, 21):
        times = []
        n_failures = 0
        for i in range(10):
            q = make_queues()
            env = Environment()
            gt = set(env.ground_truth)
            robot1 = Robot(1, q.robots, env)
            robot2 = Robot(2, q.robots, env)
            master = NaiveMaster(params, q.master, lambda_=lambda_)
            robot1.start()
            robot2.start()
            master.start()
            directive = {"type_directive": "request_run"}
            q.gui.gui2master.put(Container(directive))
            edges = {}
            start_time = time.time()
            while True:
                if not q.gui.master2gui.empty():
                    directive = q.gui.master2gui.get_nowait()
                    edges = set(directive.summary.edges)
                common = gt.intersection(edges)
                overlap = float(len(common)) / float(len(gt))
Beispiel #43
0
from robots import Robot, RC_BLACK, RC_WHITE
from intcomp import IntcodeController

f = open('input11.txt', 'r')
ls1 = f.read().split(',')
vm = IntcodeController([int(s) for s in ls1], buffer=[])
r = Robot(vm)
r.run()
print(len(r.panel))
vm.reset()
r = Robot(vm, panel={(0, 0): RC_WHITE})
r.run()
r.print_as_picture()