Ejemplo n.º 1
0
class Sketch(object):
    __metaclass__ = ABCMeta

    def __init__(self, sleep_duration=c.host.default_sleep_duration):
        self.sleep_duration = sleep_duration
        self.tamp = TAMProxy()
        self.stopped = False
        self.start_time = None

    @abstractmethod
    def setup(self):
        raise NotImplementedError

    @abstractmethod
    def loop(self):
        raise NotImplementedError

    def start(self):
        self.start_time = time()
        self.iterations = 0 # float cuz this can get big
        if not self.tamp.started: self.tamp.start()
        self.stopped = False

    def stop(self):
        self.stopped = True

    @property
    def elapsed(self):
        return time() - self.start_time

    @property
    def throughput(self):
        return self.tamp.pf.packets_received / self.elapsed

    @property
    def frequency(self):
        return self.iterations / self.elapsed

    def run(self):
        self.start()
        try:
            self.setup()
            print "Entered loop"
            while not self.stopped:
                self.loop()
                self.iterations += 1
                sleep(self.sleep_duration)
        except KeyboardInterrupt:
            self.stop() # as if the sketch had called it
        self.tamp.stop()
        print "Sketch finished running"
Ejemplo n.º 2
0
class Sketch(object):
    __metaclass__ = ABCMeta

    def __init__(self, sleep_duration=c.host.default_sleep_duration):
        self.sleep_duration = sleep_duration
        self.tamp = TAMProxy()
        self.stopped = False
        self.start_time = None

    @abstractmethod
    def setup(self):
        raise NotImplementedError

    @abstractmethod
    def loop(self):
        raise NotImplementedError

    def start(self):
        self.start_time = time()
        self.iterations = 0  # float cuz this can get big
        if not self.tamp.started: self.tamp.start()
        self.stopped = False

    def stop(self):
        self.stopped = True

    @property
    def elapsed(self):
        return time() - self.start_time

    @property
    def throughput(self):
        return self.tamp.pf.packets_received / self.elapsed

    @property
    def frequency(self):
        return self.iterations / self.elapsed

    def run(self):
        self.start()
        try:
            self.setup()
            print "Entered loop"
            while not self.stopped:
                self.loop()
                self.iterations += 1
                sleep(self.sleep_duration)
        except KeyboardInterrupt:
            self.stop()  # as if the sketch had called it
        self.tamp.stop()
        print "Sketch finished running"
Ejemplo n.º 3
0
 def __init__(self, sleep_duration=c.host.default_sleep_duration):
     self.sleep_duration = sleep_duration
     self.tamp = TAMProxy()
     self.stopped = False
     self.start_time = None
Ejemplo n.º 4
0
from sw.mapping import Mapper
from sw.mapping.arena import Arena
from sw.vision import Vision, CameraPanel, Camera
from sw.gui import window, ControlPanel
from sw.hal import *
from sw import constants
import pygame
import time

from tamproxy import TAMProxy

if __name__ == "__main__":
    cam = Camera(geom=constants.camera_geometry, id=1)
    v = Vision(cam)
    with TAMProxy() as tamproxy:
        r = Robot(tamproxy)
        m = Mapper(r.drive.odometer,
                   map=Arena.load('../sw/mapping/red_map.txt'))
        w = window.Window(
            500, [m, CameraPanel(v), ControlPanel(r)
                  ])  #[Mapper(drive.odometer), CameraPanel(500, v)])
        while True:
            v.update()
            m.update_cubes_from(v)
            time.sleep(0.05)
            pass
Ejemplo n.º 5
0
class Sketch(object):
    __metaclass__ = ABCMeta

    def __init__(self, sleep_duration=c.host.default_sleep_duration):
        self.sleep_duration = sleep_duration
        self.tamp = TAMProxy()
        self.stopped = False
        self.start_time = None

    @abstractmethod
    def setup(self):
        raise NotImplementedError

    @abstractmethod
    def loop(self):
        raise NotImplementedError

    def pre_setup(self):
        self.start_time = time()
        self.iterations = 0
        self.tamp.start()
        self.stopped = False

    def post_setup(self):
        self.tamp.pf.pc.set_continuous_enabled(True)
        print "Entering Loop"

    def pre_loop(self):
        pass

    def post_loop(self):
        self.iterations += 1
        sleep(self.sleep_duration)

    def on_exit(self):
        self.tamp.stop()
        print "Sketch finished running"

    def stop(self):
        self.stopped = True

    @property
    def elapsed(self):
        return time() - self.start_time

    @property
    def throughput(self):
        return self.tamp.pf.packets_received / self.elapsed

    @property
    def frequency(self):
        return self.iterations / self.elapsed

    def run(self):
        try:
            self.pre_setup()
            self.setup()
            self.post_setup()
            while not self.stopped:
                self.pre_loop()
                self.loop()
                self.post_loop()
        except KeyboardInterrupt:
            self.stop()  # as if the sketch had called it
        self.on_exit()
Ejemplo n.º 6
0
from sw import pins
from tamproxy.devices import Odometer
from tamproxy.devices import Gyro
from tamproxy.devices import Encoder
from tamproxy import TAMProxy

import time

if __name__ == "__main__":
    tamp = TAMProxy()
    gyro = Gyro(tamp, pins.gyro_cs, integrate=False)
    lEnc = Encoder(tamp, pins.l_encoder_a, pins.l_encoder_b, continuous = False)
    rEnc = Encoder(tamp, pins.r_encoder_a, pins.r_encoder_b, continuous = False)
    odo = Odometer(tamp, lEnc, rEnc, gyro, 0.0)
    
    while True:
        odo.update()
        lEnc.update()
        rEnc.update()
        print odo.val
        print lEnc.val
        print rEnc.val
        time.sleep(0.05)
Ejemplo n.º 7
0
 def __init__(self, sleep_duration=c.host.default_sleep_duration):
     self.sleep_duration = sleep_duration
     self.tamp = TAMProxy()
     self.stopped = False
     self.start_time = None
Ejemplo n.º 8
0
class Sketch(object):
    __metaclass__ = ABCMeta

    def __init__(self, sleep_duration=c.host.default_sleep_duration):
        self.sleep_duration = sleep_duration
        self.tamp = TAMProxy()
        self.stopped = False
        self.start_time = None

    @abstractmethod
    def setup(self):
        raise NotImplementedError

    @abstractmethod
    def loop(self):
        raise NotImplementedError

    def pre_setup(self):
        self.start_time = time()
        self.iterations = 0
        self.tamp.start()
        self.stopped = False

    def post_setup(self):
        self.tamp.pf.pc.set_continuous_enabled(True)
        print "Entering Loop"

    def pre_loop(self):
        pass

    def post_loop(self):
        self.iterations += 1
        sleep(self.sleep_duration)

    def on_exit(self):
        self.tamp.stop()
        print "Sketch finished running"

    def stop(self):
        self.stopped = True

    @property
    def elapsed(self):
        return time() - self.start_time

    @property
    def throughput(self):
        return self.tamp.pf.packets_received / self.elapsed

    @property
    def frequency(self):
        return self.iterations / self.elapsed

    def run(self):
        try:
            self.pre_setup()
            self.setup()
            self.post_setup()
            while not self.stopped:
                self.pre_loop()
                self.loop()
                self.post_loop()
        except KeyboardInterrupt:
            self.stop() # as if the sketch had called it
        self.on_exit()