def __init__(self): Car.__init__(self) self.getType() self.getEngineType() self.lidar = self.getDevice("lidar") self.lidar.enable(5000) self.lidar.enablePointCloud() print(self.lidar.isPointCloudEnabled()) self.keyboard.enable(10) self.speed = 0 print("^" * 10)
def test_park(self): parkingLotObj = Parking(2, 3) res1 = parkingLotObj.park(Car("White", 10)) res2 = parkingLotObj.park(Car("Red", 20)) res3 = parkingLotObj.park(Car("Yellow", 830)) # res4 = parkingLotObj.park(Car("Orange", 430)) # res5 = parkingLotObj.park(Car("Green", 130)) # res6 = parkingLotObj.park(Car("TEal", 302)) # res7 = parkingLotObj.park(Car("Turqois", 301)) self.assertEqual(res1, True) self.assertEqual(res2, True) self.assertEqual(res3, True)
class TestVehicle(unittest.TestCase): def setUp(self): self.c = Car(20, 5) self.t = Truck(20, 5) def vehicle_is_abstract_class(self): with self.assertRaises(TypeError) as exc: Vehicle(20, 5) def test_drive_car_enough_fuel(self): expected = self.c.fuel_quantity - 3 * (5 + 0.9) self.c.drive(3) self.assertEqual(self.c.fuel_quantity, expected) def test_drive_car_not_enough_fuel(self): expected = self.c.fuel_quantity self.c.drive(100) self.assertEqual(self.c.fuel_quantity, expected) def test_drive_car_0km_no_change(self): expected = 0 old_fuel_q = self.c.fuel_quantity self.c.drive(0) self.assertEqual(self.c.fuel_quantity - old_fuel_q, expected) def test_drive_truck_enough_fuel(self): expected = self.t.fuel_quantity - 3 * (5 + 1.6) self.t.drive(3) self.assertEqual(self.t.fuel_quantity, expected) def test_drive_truck_not_enough_fuel(self): expected = self.t.fuel_quantity self.t.drive(100) self.assertEqual(self.t.fuel_quantity, expected) def test_different_consumption_rate(self): self.c.drive(3) self.t.drive(3) self.assertNotEqual(self.c.fuel_quantity, self.t.fuel_quantity) def test_refuel_car(self): added_fuel = 20 expected = self.c.fuel_quantity + added_fuel self.c.refuel(added_fuel) self.assertEqual(self.c.fuel_quantity, expected) def test_refuel_truck(self): added_fuel = 20 expected = self.t.fuel_quantity + added_fuel * 0.95 self.t.refuel(added_fuel) self.assertEqual(self.t.fuel_quantity, expected)
def test_unpark(self): parkingLotObj = Parking(2, 3) res1 = parkingLotObj.un_park(Car("", 10)) # res2 = parkingLotObj.un_park(Car("", "10")) # res3 = parkingLotObj.un_park(Car("", "10")) self.assertEqual(res1, False)
def block(self, registration, colour): if self.is_parking_full(): print(Constants.PARKING_FULL) return # Find first empty slot empty_slot = self.parkings.index(0) self.parkings[empty_slot] = Parking(Car(registration, colour), empty_slot + 1) self.__slot_counter += 1 print(OUTPUT_MESSAGES[Constants.PARK].format(empty_slot + 1))
def main(): parking_lot = ParkingLot(111, 10, 100, 150) my_bike = Bike(11, "hero") my_bike1 = Bike(12, "atlas") my_car = Car(21, "lexus") my_car1 = Car(22, "mini-cooper") my_bus = Bus(31, "tata") parking_lot.park(my_bike) parking_lot.park(my_car) parking_lot.park(my_bus) parking_lot.park(my_car1) print("intial parking lot") parking_lot.print_vehicle_to_spot_mapping() parking_lot.remove(my_bike) print('parking lot after removing bike 11') parking_lot.print_vehicle_to_spot_mapping() parking_lot.park(my_bike1) print('parking lot after parking bike12') parking_lot.print_vehicle_to_spot_mapping()
class TestCar(unittest.TestCase): def setUp(self): self.fuel_quantity = 100 self.fuel_consumption = 3 self.car = Car(self.fuel_quantity, self.fuel_consumption) def test_carDrive_whenNotEnoughFuel(self): distance = 40 self.car.drive(distance) self.assertEqual(self.fuel_quantity, self.car.fuel_quantity) def test_carDrive_whenEnoughFuel(self): distance = 10 self.car.drive(distance) expected = self.fuel_quantity - (self.car.fuel_consumption + self.car. INCREASED_CONSUMPTION) * distance self.assertEqual(expected, self.car.fuel_quantity) def test_carRefuel_shouldIncreaseFuelQuantity(self): amount = 10 self.car.refuel(amount) self.assertEqual(self.fuel_quantity + amount, self.car.fuel_quantity)
def main(): # TODO: Lue kartan sijainti komentoriviparametrina # Karttatiedoston sisältävän kansion polku mapFolder = path.dirname(path.abspath(__file__)) # Karttatiedoston absoluuttinen polku kiintolevyllä mapFile = path.join(mapFolder, values.default_map) map = Map(mapFile) car = Car(1, 1) plane = Plane(3, 3) boat = Boat(7, 3) # Muuttuja, johon valittu ajoneuvo on tallennettu currentVehicle = car # Käyttäjän syöttämä komento, alustetaan tyhjäksi command = "" while command != "q": clear() # Tyhjennetään komentokehote jokaisen komennon jälkeen map.Draw(car, plane, boat) print("Liikutettava ajoneuvo:", currentVehicle.GetName()) command = input("Syötä komento > ").strip().lower() # Sallitut komennot: # - up: liikuttaa ajoneuvoa ylöspäin # - down: liikuttaa ajoneuvoa alaspäin # - left: liikuttaa ajoneuvoa vasemmalle # - right: liikuttaa ajoneuvoa oikealle # - c: käytä autoa # - p: käytä lentokonetta # - b: käytä venettä # - q: sulje sovellus if command == "up": currentVehicle.Move(values.Direction.UP, map) elif command == "down": currentVehicle.Move(values.Direction.DOWN, map) elif command == "left": currentVehicle.Move(values.Direction.LEFT, map) elif command == "right": currentVehicle.Move(values.Direction.RIGHT, map) elif command == "c": currentVehicle = car elif command == "b": currentVehicle = boat elif command == "p": currentVehicle = plane
def _get_vehicle_from_licence_plate(licence_plate: str) -> Vehicle: """Generates a Vehicle object based on a licence plate This Would most likely be replaced with an API call or simiar if this was an real life application See this as a placeholder, mockup. Args: licence_plate (str) Returns: Vehicle """ vehicle_mappings = {"abc123": Car(), "abc321": Motorbike()} return vehicle_mappings[licence_plate]
def main(): # TODO: Lue kartan sijainti komentoriviparametrina mapFolder = path.dirname( path.abspath(__file__)) # Karttatiedoston sisältävä kansio mapFile = path.join( mapFolder, values.default_map) # Karttatiedoston polku kiintolevystä try: map = Map(mapFile) except MapFileNotFoundError: print("Karttatiedostoa ei löytynyt!") return # Return tässä sulkee sovelluksen car = Car(1, 1) plane = Plane(3, 3) boat = Boat(7, 3) currentVehicle = car # Liikutetaan autoa oletuksena command = '' while command != 'q': clear() map.Draw(car, plane, boat) print("Valittu ajoneuvo", currentVehicle.GetName()) command = input("Syötä komento: > ").strip().lower() if command == "up": currentVehicle.Move(values.Direction.UP, map) elif command == "down": currentVehicle.Move(values.Direction.DOWN, map) elif command == "left": currentVehicle.Move(values.Direction.LEFT, map) elif command == "right": currentVehicle.Move(values.Direction.RIGHT, map) elif command == "p": currentVehicle = plane elif command == "c": currentVehicle = car elif command == "b": currentVehicle = boat
def processInputFile(inputFileName): """Read the input file, pull the data.""" print("processing", os.path.basename(inputFileName)) with open(inputFileName) as flines: inputData = [line.strip().split(" ") for line in flines] R, C, F, N, B, T = [int(x) for x in inputData[0]] # initialise the fleet fleet = [Car() for i in range(F)] rides = [] for ind, line in enumerate(inputData[1:]): start_row, start_column, finish_row, finish_column, earliest_start, latest_finish = line ryder = Ride(ride_id=ind, origin=(start_row, start_column), destination=(finish_row, finish_column), start_time=earliest_start, finish_time=latest_finish) rides.append(ryder) return fleet, rides, T, B
class VehicleTests(unittest.TestCase): def setUp(self) -> None: self.car = Car(2, 1) self.truck = Truck(2, 1) def test_car_init_method(self): self.assertEqual(self.car.fuel_quantity, 2) self.assertEqual(self.car.fuel_consumption, 1) def test_truck_init_method(self): self.assertEqual(self.truck.fuel_quantity, 2) self.assertEqual(self.truck.fuel_consumption, 1) def test_refuel_car(self): self.car.refuel(1) self.assertEqual(self.car.fuel_quantity, 3) def test_refuel_truck(self): self.truck.refuel(8) self.assertEqual(self.truck.fuel_quantity, 9.6) def test_car_drive_enough_fuel(self): self.car.fuel_quantity = 1.9 self.car.drive(1) self.assertEqual(self.car.fuel_quantity, 0) def test_car_drive_not_enough_fuel(self): self.car.drive(10) self.assertEqual(self.car.fuel_quantity, 2) def test_truck_drive_enough_fuel(self): self.truck.fuel_quantity = 2.6 self.truck.drive(1) self.assertEqual(self.truck.fuel_quantity, 0) def test_truck_drive_not_enough_fuel(self): self.truck.drive(10) self.assertEqual(self.truck.fuel_quantity, 2)
from vehicle import Car, change_km_to_mile if __name__=="__main__": my_car=Car() my_car.start() my_car.accelerate() speed_mile=change_km_to_mile(my_car.get_speed()) print('속도:',speed_mile,'mile') my_car.stop
# print( "---Level ", i ) # for j in i: # print( " Spots " , j ) # # Just for testing # def show_parking_lots(self): # all_vehicles = [] # for level in self.level: # all_vehicles.append(self.level.get_spots()) # return all_vehicles if __name__ == '__main__': print("Creating spots and adding to level ") spots_count, level_count = input("Spot Count, Level count ").split() spots_count = int( spots_count ) level_count = int( level_count ) pk = Parking( level_count , spots_count ) pk.park(Car("White", 10)) pk.park(Car("Yello", 20)) pk.park(Car("White", 22)) print("UNPARKING ------------------------------------------------------") pk.un_park(Car("",10)) pk.un_park(Car("", 20))
#!/usr/bin/env python3 """This script makes the decision for the cars movements""" from __future__ import division import time import sys from HRSR04 import DistanceSensor from vehicle import Car # create two distance sensor's LEFTSENSOR = DistanceSensor(23, 24) RIGHTSENSOR = DistanceSensor(18, 27) # add new car, left servo on channel 0 and right servo on channel 1 SMARTCAR = Car(0, 1) def main(): DELAY = 0.75 #""" print("--------------------") time.sleep(0.1) LEFT_DISTANCE = LEFTSENSOR.distance() RIGHT_DISTANCE = RIGHTSENSOR.distance() print("left: ", LEFT_DISTANCE) print("right: ", RIGHT_DISTANCE) #""" #""" if LEFT_DISTANCE < 10 and RIGHT_DISTANCE < 10:
# chapter_6.py from vehicle import Vehicle, Car, Truck my_car = Car("Ford", "Thunderbird") print(f"my_car is type {type(my_car)}") print(f"my_car uses {my_car.fuel}") print(f"my_car is a Car: {isinstance(my_car, Car)}") print(f"my_car is a Vehicle: {isinstance(my_car, Vehicle)}") print(f"Car is a subclass of Vehicle: {issubclass(Car, Vehicle)}") my_truck = Truck("Ford", "F350") print(f"my_truck is type {type(my_truck)}") print(f"my_truck uses {my_truck.fuel}") print(f"my_truck has {my_truck.number_of_wheels} wheels")
def setUp(self) -> None: self.car = Car(2, 1) self.truck = Truck(2, 1)
def __init__(self): Car.__init__(self) self.saveStep = 0 self.steeringAngle = 0.0 self.velocity = cfg.param.velocity self.controlTime = cfg.robot.time self.basicTime = self.getBasicTimeStep() print("#" * 40) print("This is auto-Vehicle!") print("Here are my Info: ") print("My Synchronization: ", self.getSynchronization()) print("My Basic Time Step: ", self.getBasicTimeStep()) print("My Control Time Step: ", self.controlTime) print("#" * 40) print("Here are my Device Info: ") print("#" * 40) print("Lidar Enabled: ", cfg.lidar.isEnable) if cfg.lidar.isEnable: self.lidar = self.getDevice("lidar") self.lidar.enable(cfg.lidar.samplingPeriod) self.lidar.enablePointCloud() self.lidar.setFrequency(cfg.lidar.frequency) print("Sampling Period: ", self.lidar.getSamplingPeriod()) print("Rotation Frequency: ", self.lidar.getFrequency()) print("#" * 40) print("GPS Enabled: ", cfg.gps.isEnable) if cfg.gps.isEnable: self.gps = self.getDevice("gps") self.gps.enable(cfg.gps.samplingPeriod) print("Sampling Period: ", self.gps.getSamplingPeriod()) print("#" * 40) print("Camera Enabled: ", cfg.camera.isEnable) if cfg.camera.isEnable: self.firstCall = True self.filterSize = 3 self.cameraChannel = 3 self.oldCameraValue = [0, 0, 0] self.camera = self.getDevice("camera") self.camera.enable(cfg.camera.samplingPeriod) self.cameraImgWidth = self.camera.getWidth() self.cameraImgHeight = self.camera.getHeight() self.cameraImgFov = self.camera.getFov() print("Sampling Period: ", self.camera.getSamplingPeriod()) print("Image Width: ", self.cameraImgWidth) print("Image Height: ", self.cameraImgHeight) print("#" * 40) print("Sick Enabled: ", cfg.sick.isEnable) if cfg.sick.isEnable: self.HALFAREA = 20 self.sick = self.getDevice("Sick LMS 291") self.sick.enable(cfg.sick.samplingPeriod) self.sickWidth = self.sick.getHorizontalResolution() self.sickRange = self.sick.getMaxRange() self.sickFov = self.sick.getFov() print("Sampling Period: ", self.sick.getSamplingPeriod()) print("Sick Width: ", self.sickWidth) print("Sick Range: ", self.sickRange) print("Sick Fov: ", self.sickFov) print("#" * 40) print("PID Enabled: ", cfg.pid.isEnable) if cfg.pid.isEnable: self.needResetPID = False self.oldPIDValue = 0.0 self.integral = 0.0 print("KP: ", cfg.pid.KP) print("KI: ", cfg.pid.KI) print("KD: ", cfg.pid.KD) print("#" * 40) self.setHazardFlashers(True) self.setDippedBeams(True) self.setAntifogLights(True) self.setWiperMode(False) self.setCruisingSpeed(self.velocity)
def setUp(self): self.fuel_quantity = 100 self.fuel_consumption = 3 self.car = Car(self.fuel_quantity, self.fuel_consumption)
l = l.flatten() if l[1] > l[3]: theta = np.pi - np.arctan2(l[1] - l[3], l[0] - l[2]) else: theta = np.pi - np.arctan2(l[3] - l[1], l[2] - l[0]) avg_theta += theta avg_center += (l[0] + l[2]) / 2 n += 1 avg_center /= n avg_theta /= n return float(avg_center - w / 2) / float(w / 2) if __name__ == '__main__': # Initialize our car and sensors car = Car() front_camera = car.getCamera("front_camera") front_camera.enable(50) car.setBrakeIntensity(0.75) car.setCruisingSpeed(35) # Do we want to stop at stop signs? detect_stop_sign = True stop = False brakes = [] brake_cmd = 1 brake_k = 0.95 # Controller tuning and inits max_speed = 39
def test_simple_car(self): car = Car(5, 1) car.move(3, 0) self.assertEqual(car.fuel, 2) self.assertEqual(car.pos_x, 3) self.assertEqual(car.pos_y, 0)
def setUp(self): self.c = Car(20, 5) self.t = Truck(20, 5)
from vehicle import Car, Vehicle my_car = Car("Shira", "nai") print(f"The car is of type: {type(my_car)}") print(f"The model is {my_car.model}") print(f"The make is {my_car.make}") print(my_car.__str__()) print(my_car.__repr__()) print(my_car.value_var, "is the value in instance variable") print(Car.value_var) Car.value_var = 100 print(Car.value_var) print(my_car.value_var, "is the value in instance variable")
def slow_down(self, n: int): if n < 0: raise ValueError('value must be positive') if n > self._speed: self._speed = 0 else: self._speed -= n def beep(self): print('Ding...') if __name__ == '__main__': my_car = Car("Priora", 100) test_drive(my_car) vehicle_interface_test(my_car) print('\n\n') my_boat = Boat("Meteor", 20) test_drive(my_boat) vehicle_interface_test(my_boat) print('\n\n') my_bi = Bicycle() test_drive(my_bi) vehicle_interface_test(my_bi) print('\n\n') my_sail = SailBoat()