<commit_before>import warnings
import time
import math
import copy

from time import perf_counter

from ctrl import block
from ctrl.block import clock

import rcpy
import rcpy.mpu9250 as mpu9250

# Uses <NAME>'s Borg for making MPU9250 a singleton

class MPU9250(clock.Clock):

    _shared_state = {}

    def __init__(self, **kwargs):

        # Makes sure clock is a singleton
        self.__dict__ = self._shared_state

        # Do not initialize if already initialized
        if not self.__dict__ == {}:
            warnings.warn('> Clock is already initialized. Skipping call to __init')
            return

        # get defaults
        defaults = mpu9250.get()

        # accel_fsr
        self.accel_fsr = kwargs.pop('accel_fsr', defaults['accel_fsr'])

        # gyro_fsr
        self.gyro_fsr = kwargs.pop('gyro_fsr', defaults['gyro_fsr'])

        # accel_dlpf
        self.accel_dlpf = kwargs.pop('accel_dlpf', defaults['accel_dlpf'])

        # gyro_dlpf
        self.gyro_dlpf = kwargs.pop('gyro_dlpf', defaults['gyro_dlpf'])

        # enable_magnetometer 
        self.enable_magnetometer = kwargs.pop('enable_magnetometer',
                                              defaults['enable_magnetometer'])

        # orientation
        self.orientation = kwargs.pop('orientation', defaults['orientation'])

        # compass_time_constant
        self.compass_time_constant = kwargs.pop('compass_time_constant',
                                                defaults['compass_time_constant'])

        # dmp_interrupt_priority
        self.dmp_interrupt_priority = kwargs.pop('dmp_interrupt_priority',
                                                 defaults['dmp_interrupt_priority'])

        # dmp_sample_rate
        self.period = kwargs.pop('period',
                                 1/defaults['dmp_sample_rate'])

        # show_warnings
        self.show_warnings = kwargs.pop('show_warnings',
                                        defaults['show_warnings'])

        # enable_dmp 
        self.enable_dmp = kwargs.pop('enable_dmp',
                                     defaults['enable_dmp'])
        
        # enable_fusion 
        self.enable_fusion = kwargs.pop('enable_fusion',
                                        defaults['enable_fusion'])

        # call super
        super().__init__(**kwargs)

        # initialize mpu9250
        mpu9250.initialize(accel_fsr = self.accel_fsr,
                           gyro_fsr = self.gyro_fsr,
                           accel_dlpf = self.accel_dlpf,
                           gyro_dlpf = self.gyro_dlpf,
                           orientation = self.orientation,
                           compass_time_constant = self.compass_time_constant,
                           dmp_interrupt_priority = self.dmp_interrupt_priority,
                           dmp_sample_rate = int(1/self.period),
                           enable_magnetometer = self.enable_magnetometer,
                           enable_dmp = self.enable_dmp,
                           show_warnings = self.show_warnings,
                           enable_fusion = self.enable_fusion)
                                 
        self.data = {}
                                          
    def get(self, *keys, exclude = ()):

        # call super excluding time and last
        return super().get(*keys, exclude = exclude + ('data',
                                                       '_shared_state'))
    
    def set(self, exclude = (), **kwargs):
        
        # will need to initialize
        initialize = set('accel_fsr', 'gyro_fsr',
                         'accel_dlpf', 'gyro_dlpf',
                         'enable_magnetometer', 'orientation',
                         'compass_time_constant',
                         'dmp_interrupt_priority','dmp_sample_rate',
                         'show_warnings','enable_dmp',
                         'enable_fusion').intersection(kwargs.keys())
       
        # call super
        super().set(exclude + ('data',
                               '_shared_state'), **kwargs)

        if initialize:
            # initialize mpu9250<commit_msg>Improved initialization in mup9250.set<commit_after>import warnings
import time
import math
import copy

from time import perf_counter

from ctrl import block
from ctrl.block import clock

import rcpy
import rcpy.mpu9250 as mpu9250

# Uses <NAME>'s Borg for making MPU9250 a singleton

class MPU9250(clock.Clock):

    _shared_state = {}

    def __init__(self, **kwargs):

        # Makes sure clock is a singleton
        self.__dict__ = self._shared_state

        # Do not initialize if already initialized
        if not self.__dict__ == {}:
            warnings.warn('> Clock is already initialized. Skipping call to __init')
            return

        # get defaults
        defaults = mpu9250.get()

        # accel_fsr
        self.accel_fsr = kwargs.pop('accel_fsr', defaults['accel_fsr'])

        # gyro_fsr
        self.gyro_fsr = kwargs.pop('gyro_fsr', defaults['gyro_fsr'])

        # accel_dlpf
        self.accel_dlpf = kwargs.pop('accel_dlpf', defaults['accel_dlpf'])

        # gyro_dlpf
        self.gyro_dlpf = kwargs.pop('gyro_dlpf', defaults['gyro_dlpf'])

        # enable_magnetometer 
        self.enable_magnetometer = kwargs.pop('enable_magnetometer',
                                              defaults['enable_magnetometer'])

        # orientation
        self.orientation = kwargs.pop('orientation', defaults['orientation'])

        # compass_time_constant
        self.compass_time_constant = kwargs.pop('compass_time_constant',
                                                defaults['compass_time_constant'])

        # dmp_interrupt_priority
        self.dmp_interrupt_priority = kwargs.pop('dmp_interrupt_priority',
                                                 defaults['dmp_interrupt_priority'])

        # dmp_sample_rate
        self.period = kwargs.pop('period',
                                 1/defaults['dmp_sample_rate'])

        # show_warnings
        self.show_warnings = kwargs.pop('show_warnings',
                                        defaults['show_warnings'])

        # enable_dmp 
        self.enable_dmp = kwargs.pop('enable_dmp',
                                     defaults['enable_dmp'])
        
        # enable_fusion 
        self.enable_fusion = kwargs.pop('enable_fusion',
                                        defaults['enable_fusion'])

        # call super
        super().__init__(**kwargs)

        # initialize mpu9250
        mpu9250.initialize(accel_fsr = self.accel_fsr,
                           gyro_fsr = self.gyro_fsr,
                           accel_dlpf = self.accel_dlpf,
                           gyro_dlpf = self.gyro_dlpf,
                           orientation = self.orientation,
                           compass_time_constant = self.compass_time_constant,
                           dmp_interrupt_priority = self.dmp_interrupt_priority,
                           dmp_sample_rate = int(1/self.period),
                           enable_magnetometer = self.enable_magnetometer,
                           enable_dmp = self.enable_dmp,
                           show_warnings = self.show_warnings,
                           enable_fusion = self.enable_fusion)
                                 
        self.data = {}
                                          
    def get(self, *keys, exclude = ()):

        # call super excluding time and last
        return super().get(*keys, exclude = exclude + ('data',
                                                       '_shared_state'))
    
    def set(self, exclude = (), **kwargs):
        
        # will need to initialize
        initialize = set(('accel_fsr', 'gyro_fsr',
                          'accel_dlpf', 'gyro_dlpf',
                          'enable_magnetometer', 'orientation',
                          'compass_time_constant',
                          'dmp_interrupt_priority','dmp_sample_rate',
                          'show_warnings','enable_dmp',
                          'enable_fusion')).intersection(kwargs.keys())
       
        # call super
        super().set(exclude + ('data',
                               '_shared_state'), **kwargs)

        if initialize:
            # initialize mpu9250
{'fraction_non_alphanumeric': 0.085824030728604, 'fraction_numerical': 0.008642419877565718, 'mean_word_length': 1.5028537098227697, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 26, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2595859', 'n_tokens_mistral': 2236, 'n_tokens_neox': 2120, 'n_words': 390}