class Car: def __init__(self, m1_forward, m1_backward, m2_forward, m2_backward, m3_forward, m3_backward, m4_forward, m4_backward, resolution_x, resolution_y, rotation): self._camera = Camera(resolution_x, resolution_y, rotation) self._motor1 = Motor(m1_forward, m1_backward) self._motor2 = Motor(m2_forward, m2_backward) self._motor3 = Motor(m3_forward, m3_backward) self._motor4 = Motor(m4_forward, m4_backward) def move_forward(self): print('Moving the car forward...') self._motor1.move_forward() self._motor2.move_forward() self._motor3.move_forward() self._motor4.move_forward() def move_backward(self): print('Moving the car backward...') self._motor1.move_backward() self._motor2.move_backward() self._motor3.move_backward() self._motor4.move_backward() def stop(self): print('Stopping the car...') self._motor1.stop() self._motor2.stop() self._motor3.stop() self._motor4.stop() def take_picture(self, image_filename): self._camera.take_picture(image_filename)
def __init__(self, m1_forward, m1_backward, m2_forward, m2_backward, m3_forward, m3_backward, m4_forward, m4_backward, resolution_x, resolution_y, rotation, status=CarStatus.STOPPED): self._camera = Camera(resolution_x, resolution_y, rotation) self._motor1 = Motor(m1_forward, m1_backward) self._motor2 = Motor(m2_forward, m2_backward) self._motor3 = Motor(m3_forward, m3_backward) self._motor4 = Motor(m4_forward, m4_backward) self._status = status
class Car: """ This car represents the Raspberry-Py car """ def __init__(self, m1_forward, m1_backward, m2_forward, m2_backward, m3_forward, m3_backward, m4_forward, m4_backward, resolution_x, resolution_y, rotation, status=CarStatus.STOPPED): self._camera = Camera(resolution_x, resolution_y, rotation) self._motor1 = Motor(m1_forward, m1_backward) self._motor2 = Motor(m2_forward, m2_backward) self._motor3 = Motor(m3_forward, m3_backward) self._motor4 = Motor(m4_forward, m4_backward) self.status = status def move_forward(self): print('Moving the car forward...') self.status = CarStatus.RUNNING self._motor1.move_forward() self._motor2.move_forward() self._motor3.move_forward() self._motor4.move_forward() def move_backward(self): print('Moving the car backward...') self.status = CarStatus.RUNNING self._motor1.move_backward() self._motor2.move_backward() self._motor3.move_backward() self._motor4.move_backward() def stop(self): print('Stopping the car...') self.status = CarStatus.STOPPED self._motor1.stop() self._motor2.stop() self._motor3.stop() self._motor4.stop() def take_picture(self, image_filename): self._camera.take_picture(image_filename)
class Car: """ This car represents the Raspberry Pi car """ def __init__(self, m1_forward, m1_backward, m2_forward, m2_backward, m3_forward, m3_backward, m4_forward, m4_backward, resolution_x, resolution_y, rotation, status=CarStatus.STOPPED): self._camera = Camera(resolution_x, resolution_y, rotation) self._motor1 = Motor(m1_forward, m1_backward) self._motor2 = Motor(m2_forward, m2_backward) self._motor3 = Motor(m3_forward, m3_backward) self._motor4 = Motor(m4_forward, m4_backward) self._status = status def move_forward(self) -> None: self._status = CarStatus.MOVING_FORWARD self._motor1.move_forward() self._motor2.move_forward() self._motor3.move_forward() self._motor4.move_forward() def move_backward(self) -> None: self._status = CarStatus.MOVING_BACKWARD self._motor1.move_backward() self._motor2.move_backward() self._motor3.move_backward() self._motor4.move_backward() def stop(self) -> None: self._status = CarStatus.STOPPED self._motor1.stop() self._motor2.stop() self._motor3.stop() self._motor4.stop() def take_picture(self, image_filename) -> None: self._status = CarStatus.TAKING_IMAGE self._camera.take_picture(image_filename) self._status = CarStatus.IMAGE_TAKEN def update_status(self, status: CarStatus) -> None: self._status = status @property def status(self) -> CarStatus: return self._status @status.setter def status(self, status): self._status = status
def onkey(self, key): if key == "B": self.driveon = not self.driveon print("Drive:", self.driveon) elif key=="Y": filename = Camera.capture() print("Capture: ", filename) elif key=="A": filename = Camera.record(self.vid_duration) print("Record: ", filename) elif key=="X": # catch ball frame = Camera.capture_mem() x,y,r = identify_yellow_ball(frame) adir, dist = (Camera.convert_x_to_dir(x), Camera.convert_radius_to_dist(r)) print("Chase: ", adir, dist) #Drive.chase_obj(dir, dist) return True
def recording_setup(): global csv_file, image_counter, writer, recording_thread, recording_run_event, camera_stream image_counter = 0 camera_stream = Camera().start() print 'Warming up camera sensors. Wait 2 seconds..\n\n' time.sleep(2) csv_file = open('CNN/data/driving_log.csv', 'w') writer = csv.writer(csv_file) recording_run_event = threading.Event() recording_run_event.set() recording_thread = threading.Thread(target=recording_loop)