<commit_before>from __future__ import division
import os, sys
if int(os.environ.get('DISABLE_PANELS','0')):
    simple_panels = None
else:
    import simple_panels.simple_panels as simple_panels # try DISABLE_PANELS=1
import time, warnings
import numpy as np
import Queue
import enthought.traits.api as traits
from enthought.traits.ui.api import View, Item, Group, Handler, HGroup, \
     VGroup, RangeEditor

import remote_traits
import strokelitude.plugin

R2D = 180.0/np.pi

class StripePluginInfo(strokelitude.plugin.PluginBase):
    def get_name(self):
        return 'Closed Loop Stripe Fixation'
    def get_hastraits_class(self):
        return StripeClass, StripeClassWorker

class StripeClass(remote_traits.MaybeRemoteHasTraits):
    gain = traits.Float(-1.0)
    offset = traits.Float(0.0)

    traits_view = View( Group( ( Item('gain'),
                                 Item('offset') )),
                        )

class StripeClassWorker(StripeClass):
    def __init__(self):
        self.panel_height=4
        self.panel_width=11
        self.compute_width=12
        self.stripe_pos_radians = 0.0
        self.last_time = time.time()
        self.gain = -1.0 # in (radians per second) / radians
        self.offset = 0.0 # in radians per second
        self.arr = np.zeros( (self.panel_height*8, self.panel_width*8),
                              dtype=np.uint8)
        self.vel = 0.0
        self.last_diff_radians = 0.0
        self.incoming_data_queue = Queue.Queue()

    def set_incoming_queue(self,data_queue):
        self.incoming_data_queue = data_queue

    def do_work( self ):
        """This gets called frequently (e.g. 100 Hz)"""

        ## # Get any available incoming data. Ignore all but most recent.
        last_data = None
        while 1:
            try:
                last_data = self.incoming_data_queue.get_nowait()
            except Queue.Empty, err:
                break

        # Update stripe velocity if new data arrived.
        if last_data is not None:
            (cam_id,timestamp,framenumber,results,
             trigger_timestamp) = last_data
            left_angle_radians, right_angle_radians = results
            #L = left_angle_radians*R2D
            #R = right_angle_radians*R2D
            diff_radians = left_angle_radians + right_angle_radians # (opposite signs already from angle measurement)
            self.last_diff_radians = diff_radians

        # update self.vel every frame so that changes in gain and offset noticed
        self.vel = self.last_diff_radians*self.gain + self.offset

        # Compute stripe position.
        now = time.time()
        dt = now-self.last_time
        self.last_time = now

        self.stripe_pos_radians += self.vel*dt

        # Draw stripe
        self.draw_stripe()

    def draw_stripe(self):
        self.arr.fill( 255 ) # turn all pixels white

        # compute columns of stripe
        self.stripe_pos_radians = self.stripe_pos_radians % (2*np.pi)<commit_msg>fview_strokelitude: improvements and bugfixes in wing edge detection<commit_after>from __future__ import division
import os, sys
if int(os.environ.get('DISABLE_PANELS','0')):
    simple_panels = None
else:
    import simple_panels.simple_panels as simple_panels # try DISABLE_PANELS=1
import time, warnings
import numpy as np
import Queue
import enthought.traits.api as traits
from enthought.traits.ui.api import View, Item, Group, Handler, HGroup, \
     VGroup, RangeEditor

import remote_traits
import strokelitude.plugin

R2D = 180.0/np.pi

class StripePluginInfo(strokelitude.plugin.PluginBase):
    def get_name(self):
        return 'Closed Loop Stripe Fixation'
    def get_hastraits_class(self):
        return StripeClass, StripeClassWorker

class StripeClass(remote_traits.MaybeRemoteHasTraits):
    gain = traits.Float(-1.0)
    offset = traits.Float(0.0)

    traits_view = View( Group( ( Item('gain'),
                                 Item('offset') )),
                        )

class StripeClassWorker(StripeClass):
    def __init__(self):
        self.panel_height=4
        self.panel_width=11
        self.compute_width=12
        self.stripe_pos_radians = 0.0
        self.last_time = time.time()
        self.gain = -1.0 # in (radians per second) / radians
        self.offset = 0.0 # in radians per second
        self.arr = np.zeros( (self.panel_height*8, self.panel_width*8),
                              dtype=np.uint8)
        self.vel = 0.0
        self.last_diff_radians = 0.0
        self.incoming_data_queue = Queue.Queue()

    def set_incoming_queue(self,data_queue):
        self.incoming_data_queue = data_queue

    def do_work( self ):
        """This gets called frequently (e.g. 100 Hz)"""

        ## # Get any available incoming data. Ignore all but most recent.
        last_data = None
        while 1:
            try:
                last_data = self.incoming_data_queue.get_nowait()
            except Queue.Empty, err:
                break

        # Update stripe velocity if new data arrived.
        if last_data is not None:
            (cam_id,timestamp,framenumber,results,
             trigger_timestamp) = last_data
            left_angle_radians, right_angle_radians = results
            if not (left_angle_radians is None or right_angle_radians is None):
                #L = left_angle_radians*R2D
                #R = right_angle_radians*R2D
                diff_radians = left_angle_radians + right_angle_radians # (opposite signs already from angle measurement)
                self.last_diff_radians = diff_radians

        # update self.vel every frame so that changes in gain and offset noticed
        self.vel = self.last_diff_radians*self.gain + self.offset

        # Compute stripe position.
        now = time.time()
        dt = now-self.last_time
        self.last_time = now

        self.stripe_pos_radians += self.vel*dt

        # Draw stripe
        self.draw_stripe()

    def draw_stripe(self):
        self.arr.fill( 255 ) # turn all pixels white

        # compute columns of stripe
        self.stripe_pos_radians = self.stripe_pos_radians % (2*np.pi)
{'fraction_non_alphanumeric': 0.08201274301584709, 'fraction_numerical': 0.01274301584708381, 'mean_word_length': 2.3545205479452056, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4085755', 'n_tokens_mistral': 1948, 'n_tokens_neox': 1847, 'n_words': 453}