<s> import logging <EOL> import os <EOL> import platform <EOL> from datetime import datetime <EOL> from localconfig import FishPiConfig <EOL> from model_data import POCVModelData <EOL> from control . navigation import NavigationUnit <EOL> from perception . world import PerceptionUnit <EOL> class FishPiKernel : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , config , debug = False ) : <EOL> self . config = config <EOL> self . debug = debug <EOL> self . _gps_sensor = config . gps_sensor <EOL> self . _compass_sensor = config . compass_sensor <EOL> self . _accelerometer_sensor = config . accelerometer_sensor <EOL> self . _gyro_sensor = config . gyro_sensor <EOL> self . _temperature_sensor = config . temperature_sensor <EOL> self . _vehicle_constants = config . vehicle_constants <EOL> self . _drive_controller = config . drive_controller <EOL> self . _camera_controller = config . camera_controller <EOL> self . data = POCVModelData ( ) <EOL> self . _perception_unit = PerceptionUnit ( self . _vehicle_constants , self . data ) <EOL> self . _navigation_unit = NavigationUnit ( self . _perception_unit , self . _drive_controller , self . _vehicle_constants ) <EOL> def update ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> self . read_time ( ) <EOL> except Exception as ex : <EOL> self . data . has_time = False <EOL> logging . exception ( "<STR_LIT>" % ex ) <EOL> try : <EOL> self . read_GPS ( ) <EOL> except Exception as ex : <EOL> self . data . has_GPS = False <EOL> logging . exception ( "<STR_LIT>" % ex ) <EOL> try : <EOL> self . read_compass ( ) <EOL> except Exception as ex : <EOL> self . data . has_compass = False <EOL> logging . exception ( "<STR_LIT>" % ex ) <EOL> try : <EOL> self . read_magnetometer ( ) <EOL> except Exception as ex : <EOL> self . data . has_magnetometer = False <EOL> logging . exception ( "<STR_LIT>" % ex ) <EOL> try : <EOL> self . read_accelerometer ( ) <EOL> except Exception as ex : <EOL> self . data . has_accelerometer = False <EOL> logging . exception ( "<STR_LIT>" % ex ) <EOL> try : <EOL> self . read_gyro ( ) <EOL> except Exception as ex : <EOL> self . data . has_gyro = False <EOL> logging . exception ( "<STR_LIT>" % ex ) <EOL> try : <EOL> self . read_temperature ( ) <EOL> except Exception as ex : <EOL> self . data . has_temperature = False <EOL> logging . exception ( "<STR_LIT>" % ex ) <EOL> try : <EOL> self . _perception_unit . update ( self . data ) <EOL> except Exception as ex : <EOL> logging . exception ( "<STR_LIT>" % ex ) <EOL> try : <EOL> self . _navigation_unit . update ( ) <EOL> except Exception as ex : <EOL> logging . exception ( "<STR_LIT>" % ex ) <EOL> def list_devices ( self ) : <EOL> logging . info ( "<STR_LIT>" ) <EOL> for device in self . config . devices : <EOL> logging . info ( device ) <EOL> def get_capture_img_enabled ( self ) : <EOL> return self . _camera_controller . enabled <EOL> def set_camera_mode ( self , camera_cmd ) : <EOL> if not isinstance ( camera_cmd , basestring ) : <EOL> logging . error ( "<STR_LIT>" ) <EOL> return <EOL> self . _camera_controller . set_mode ( camera_cmd ) <EOL> def read_time ( self ) : <EOL> dt = datetime . today ( ) <EOL> self . data . timestamp = dt . time ( ) <EOL> self . data . datestamp = dt . date ( ) <EOL> self . data . has_time = True <EOL> def read_GPS ( self ) : <EOL> if self . _gps_sensor : <EOL> ( fix , lat , lon , heading , speed , altitude , num_sat , timestamp , datestamp ) = self . _gps_sensor . read_sensor ( ) <EOL> self . data . fix = fix <EOL> self . data . lat = lat <EOL> self . data . lon = lon <EOL> self . data . gps_heading = heading <EOL> self . data . speed = speed <EOL> self . data . altitude = altitude <EOL> self . data . num_sat = num_sat <EOL> self . data . timestamp = timestamp <EOL> self . data . datestamp = datestamp <EOL> self . data . has_GPS = True <EOL> else : <EOL> self . data . has_GPS = False <EOL> def read_compass ( self ) : <EOL> if self . _compass_sensor : <EOL> ( heading , pitch , roll ) = self . _compass_sensor . read_sensor ( ) <EOL> self . data . compass_heading = heading <EOL> self . data . compass_pitch = pitch <EOL> self . data . compass_roll = roll <EOL> self . data . has_compass = True <EOL> else : <EOL> self . data . has_compass = False <EOL> def read_magnetometer ( self ) : <EOL> pass <EOL> def read_accelerometer ( self ) : <EOL> pass <EOL> def read_gyro ( self ) : <EOL> pass <EOL> def read_temperature ( self ) : <EOL> if self . _temperature_sensor : <EOL> temperature = self . _temperature_sensor . read_sensor ( ) <EOL> self . data . temperature = temperature <EOL> self . data . has_temperature = True <EOL> else : <EOL> self . data . has_temperature = False <EOL> def set_throttle ( self , throttle_level ) : <EOL> self . _drive_controller . set_throttle ( throttle_level ) <EOL> def set_steering ( self , angle ) : <EOL> self . _drive_controller . set_steering ( angle ) <EOL> def set_manual_mode ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _navigation_unit . stop ( ) <EOL> self . halt ( ) <EOL> def set_auto_pilot_mode ( self ) : <EOL> """<STR_LIT>""" <EOL> self . halt ( ) <EOL> self . _navigation_unit . start ( ) <EOL> @ property <EOL> def auto_mode_enabled ( self ) : <EOL> return self . _navigation_unit . auto_mode_enabled <EOL> def set_speed ( self , speed ) : <EOL> """<STR_LIT>""" <EOL> self . _navigation_unit . set_speed ( speed ) <EOL> def set_heading ( self , heading ) : <EOL> """<STR_LIT>""" <EOL> self . _navigation_unit . set_heading ( heading ) <EOL> def navigate_to ( self ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> def halt ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _navigation_unit . stop ( ) <EOL> self . _drive_controller . halt ( ) <EOL> def load_gpx ( self , filename ) : <EOL> gpx = self . _perception_unit . load_gpx ( filename ) <EOL> return gpx </s>
