def __init__(self, *args, **kwargs): super(CommandThread, self).__init__(*args, **kwargs) self._stop_event = threading.Event() self.command = Command() self.last_cmd_time = None self.config_handler = ConfigHandler.get_instance() # Flag noting whether this is the vehicle or if it's a test server self.is_vehicle = self.config_handler.get_config_value_or( 'is_vehicle', True) # Pull in the trim from the config file self.trim = Trim() self.trim.from_json(self.config_handler.get_config_value_or( 'trim', {})) if self.is_vehicle: # initialize throttle and steering values self.throttle = Throttle(self.trimmed_throttle()) self.steering = Steering(self.trimmed_steering()) self.lock = threading.Lock() self.loop_delay = 0.01 logging.debug( "Main thread for vehicle controller started. Awaiting first command..." )
def __init__(self): config_handler = ConfigHandler.get_instance() # preferred_pin_factory = config_handler.get_config_value_or('preferred_pin_factory', '') # if preferred_pin_factory == 'pigpio': # Device.pin_factory = PiGPIOFactory() # logging.info(f"Starting vehicle manager thread using pin factory: {Device.pin_factory}") # else: # logging.info("Starting vehicle manager thread using default pin factory") # The mode can be set from a thread different from the one in which it was created, so this lock prevents # unnecessary funny business when setting the mode self._lock = Lock() # Create the vehicle controller and start it self._cmd_ctl = CmdCtl() self._cmd_ctl.start() # Create the sensor manager and start it self._peripheral_mgr = PeripheralMgr() self._peripheral_mgr.start_peripherals() # Create the image streamer and start it sensor_list = config_handler.get_config_value_or('peripheral_list', []) self._image_streamer = None if sensor_list.__contains__('main_camera'): self._image_streamer = ImageStreamer() self._image_streamer.start()
def __init__(self, *args, **kwargs): super(ImageStreamerThread, self).__init__(*args, **kwargs) self._running = False self._streaming = False self._config_handler = ConfigHandler.get_instance() self._data_dir = self._config_handler.get_config_value_or( 'data_dir', '/data') # Default resolution gives us a 4:3 aspect ratio. Width must be a multiple of 32, height must be a multiple # of 16 self._res_width = self._config_handler.get_config_value_or( 'res_width', 192) self._res_height = self._config_handler.get_config_value_or( 'res_height', 144) self._pi_camera = None try: self._pi_camera = picamera.PiCamera() self._pi_camera.resolution = (self._res_width, self._res_height) except picamera.exc.PiCameraError as e: logging.error( "Unable to open streaming camera, video stream will be disabled" ) self._lock = threading.Lock() self._last_image_filename = None self._video_stream_client = None
def game_controller_calibrated_from_window(self, calibration_data): self._game_controller_config_window.close() config_handler = ConfigHandler.get_instance() config_handler.set_config_value('game_controller_calibration', calibration_data.to_json()) self.game_controller_calibrated(calibration_data)
def __init__(self) -> None: super().__init__() self._running = False self._streaming = False self._connected = False self._lock = threading.Lock() self._port = ConfigHandler.get_instance().get_config_value_or('stream_port', 4000) self._timeout = 0.25 self._last_image = None
def __init__(self, init_value=0.0): self.steering = init_value self.config_handler = ConfigHandler.get_instance() # Get the config value, then re-write it to the config. We do this so in the case that there is no config file # yet, it will create one with the default value steering_pin = self.config_handler.get_config_value_or( 'steering_pin', Constants.GPIO_PIN_STEERING_SERVO) self.config_handler.set_config_value('steering_pin', steering_pin) self.servo = Servo(steering_pin) logging.debug(f"Setting initial steering to {self.steering}")
def __init__(self, init_value=0.0): self.throttle = init_value self.config_handler = ConfigHandler.get_instance() # Get the config value, then re-write it to the config. We do this so in the case that there is no config file # yet, it will create one with the default value speed_control_pin = self.config_handler.get_config_value_or( 'speed_control_pin', Constants.GPIO_PIN_ELECTRONIC_SPEED_CONTROLLER) self.config_handler.set_config_value('speed_control_pin', speed_control_pin) self.servo = Servo(speed_control_pin) logging.debug(f"Setting initial throttle to {self.throttle}")
def __init__(self): super().__init__() self._distance = 0 self._config_handler = ConfigHandler.get_instance() self._trigger_pin = self._config_handler.get_config_value_or( 'trigger_pin', 23) self._echo_pin = self._config_handler.get_config_value_or( 'echo_pin', 24) self._lock = threading.Lock() self._loop_delay = 0.05 self._timeout = 0.5 self._hardware = gpiozero.DistanceSensor(echo=self._echo_pin, trigger=self._trigger_pin, max_distance=3)
def __init__(self): self.config_handler = ConfigHandler.get_instance() # Populate our peripheral list from the config self.peripherals = {} peripheral_list = self.config_handler.get_config_value_or( 'peripheral_list', []) for peripheral in peripheral_list: if peripheral == 'distance_sensor': self.peripherals['distance_sensor'] = DistanceSensor() if peripheral == 'segmented_display': self.peripherals['segmented_display'] = SegmentedDisplay() if peripheral == 'cpu_fan': self.peripherals['cpu_fan'] = CpuFan() if peripheral == 'stereo_camera': self.peripherals['stereo_camera'] = StereoCamera() self.mode = Mode()
from common.config_handler import ConfigHandler import os """ This function is used to generate a systemd service unit file. To install as a service, follow the following steps: 1. Add the following values to your config file: - 'vehicle_src_dir' - the path to the 'src' directory on the pi - 'vehicle_cfg_dir' - the path to the directory where you are storing your vehicle-side config file 2. Run this script to generate the rotor.service file 3. Copy all files over to the pi src directory using 'send_to_vehicle.py' 4. Copy the rotor.service file into /lib/systemd/system 5. Reload systemd with 'sudo systemctl daemon-reload' 6. Start the rotor service with 'sudo systemctl restart rotor.service' 7. Enable the rotor service to start automatically on boot with 'sudo systemctl enable rotor.service' """ if __name__ == '__main__': config_handler = ConfigHandler.get_instance() vehicle_src_dir = config_handler.get_config_value_or( 'vehicle_src_dir', '/home/pi/rotor/src') vehicle_cfg_dir = config_handler.get_config_value_or( 'vehicle_cfg_dir', '/etc/rotor') pwd = os.path.dirname(os.path.realpath(__file__)) file_str = f"[Unit]\n" \ f"Description=Rotor Vehicle Service\n" \ f"After=multi-user.target\n\n" \ f"[Service]\n" \ f"Type=idle\n" \ f"Environment=ROTOR_DIR={vehicle_cfg_dir}\n" \ f"ExecStart=/usr/bin/python3 -u {vehicle_src_dir}/vehicle_main.py\n\n" \ f"[Install]\n" \ f"WantedBy=multi-user.target"
def __init__(self): super(CpuFan, self).__init__() self._fan = gpiozero.LED(ConfigHandler.get_instance().get_config_value_or('cpu_fan_pin', 21)) self._fan.off() self._fan_state = False
from common.config_handler import ConfigHandler import os import subprocess import platform """ To use this script, you should define at least three fields in your config file: vehicle_ip : The destination ip address to send the source files to vehicle_src_dir : The source directory on the vehicle the source files should be placed vehicle_user : The username for the vehicle This script forces the use of ipv4, which I've found to help connection issues with ssh, so I put it here too. Not sure if it's totally necessary """ if __name__ == '__main__': config_handler = ConfigHandler() ip = config_handler.get_config_value_or('vehicle_ip', '127.0.0.1') vehicle_src_dir = config_handler.get_config_value_or( 'vehicle_src_dir', '/home/pi/rotor/src') user = config_handler.get_config_value_or('vehicle_user', 'pi') pwd = os.path.dirname(os.path.realpath(__file__)) command = '' if platform.uname().system == 'Windows': command = f"scp -r {pwd} scp://{user}@{ip}/{vehicle_src_dir}" else: command = f"rsync -rv {pwd}/* {user}@{ip}:{vehicle_src_dir}" print(command) subprocess.run(command, shell=True)
def __init__(self, auto_agent : AutoAgent): super().__init__() self._reqest_handler = RequestHandler(ConfigHandler.get_instance()) self._auto_agent = auto_agent self._stereo_proc = StereoProcessor()
from client.auto_agent import AutoAgent from client.image_stream_server import ImageStreamServer from client.telemetry_processor import TelemetryProcessor if __name__ == "__main__": # Set the log level logger = logging.getLogger() logger.setLevel(logging.INFO) # Setup the image server to receive images from the vehicle. Needs to happen before creating the image_stream_server = ImageStreamServer() image_stream_server.start() # Setup the primary vehicle control class and start it vehicle_ctl = VehicleCtl(ConfigHandler.get_instance()) vehicle_ctl.start() # Automatically start up the image stream vehicle_ctl.request_stream_start() # Create the auto agent auto_agent = AutoAgent(vehicle_ctl) auto_agent.start() # Create the telemetry processor telemetry_proc = TelemetryProcessor(auto_agent) telemetry_proc.start() # Create the Qt application and launch app = QtWidgets.QApplication(sys.argv) mainWin = MainWindow(vehicle_ctl, image_stream_server)
from common.config_handler import ConfigHandler import subprocess if __name__ == '__main__': config_handler = ConfigHandler() ip = config_handler.get_config_value_or('vehicle_ip', '127.0.0.1') user = config_handler.get_config_value_or('vehicle_user', 'pi') command = f"rsync -v {user}@{ip}:/data/* ../data" print(command) subprocess.run(command, shell=True)