Ejemplo n.º 1
0
 def __init__(self) -> None:
     self.movement_publisher = messenger.Publisher('/movement', messenger.Messages.motion)
     self.kicker_publisher = messenger.Publisher('/kicker_speed', messenger.Messages.integer)
     self.x = 0
     self.y = 0
     self.w = 0
     self.rpm = 0
Ejemplo n.º 2
0
    def __init__(self, mock=False, run=True) -> None:
        super().__init__('injector_node')

        self.command_publisher = messenger.Publisher('/command',
                                                     messenger.Messages.string)

        self.strategy_listener = messenger.Listener('/strategy',
                                                    messenger.Messages.string)
        self.canbus_listener = messenger.Listener('/canbus_message',
                                                  messenger.Messages.string)
        self.settings_listener = messenger.Listener(
            '/settings_changed',
            messenger.Messages.string,
            callback=self.refresh_settings)
        self.recognition_listener = messenger.Listener(
            '/recognition', messenger.Messages.string)

        self.config = ConfigManager.get_value('game')
        self.mock = mock

        self.initial_devices = set(
            (dev.hwid or dev.device) for dev in find_serial('CP2102').values())
        self.logger.info("existing devices %s", list(self.initial_devices))
        self.injector: Optional[serial.Serial] = None

        if run:
            self.loop(3)
Ejemplo n.º 3
0
    def __init__(self, mock=False, run=True, **kwargs) -> None:
        super().__init__('gameplay', existing_loggers=['gameplay'], **kwargs)

        self.mock = mock
        # ConfigManager.set_value('game|global|gameplay status', 'disabled')
        self.config = ConfigManager.get_value('game')
        self.gameplay = Gameplay(self.config, Controller(), self.logger)

        self.strategy_publisher = messenger.Publisher('/strategy', messenger.Messages.string)

        self.settings_listener = messenger.Listener(
            '/settings_changed', messenger.Messages.string, callback=self.refresh_settings)
        self.recognition_listener = messenger.Listener(
            '/recognition', messenger.Messages.string, callback=self.callback)
        self.command_listener = messenger.Listener(
            '/command', messenger.Messages.string, callback=self.command_callback)
        self.kicker_listener = messenger.Listener(
            '/canbus_message', messenger.Messages.string, callback=self.kicker_callback)

        self.realsense_distance_listener = messenger.Listener(
            '/distance/realsense', messenger.Messages.float, callback=self.realsense_distance_callback)

        self.tfmini_distance_listener = messenger.Listener(
            '/distance/tfmini', messenger.Messages.float, callback=self.tfmini_distance_callback)

        self.realsense_active = time()

        self.logger.info("Start gameplay")
        if run:
            self.spin()
Ejemplo n.º 4
0
def nuke_usb():
    node = messenger.Node('nuke_node')
    controller = messenger.Publisher('/controller', messenger.Messages.string)
    sleep(0.1)
    controller.publish('restart()')
    sleep(0.1)
    print("SEEEENDING##!#!##!#!#!#!")
Ejemplo n.º 5
0
    def __init__(self, mock=False, run=True, silent=True) -> None:
        super().__init__('realsense')
        self.publisher = messenger.Publisher('/distance/realsense',
                                             messenger.Messages.float)

        self.silent = silent
        self.mock = mock

        if not mock:
            self.sensor = CaptureDistance()
            self.iter = iter(self.sensor)

        if run:
            print("realsense looper")
            self.loop(35)
Ejemplo n.º 6
0
    def __init__(self, run=True, mock=False) -> None:
        super().__init__('tfmini')
        self.publisher = messenger.Publisher('/distance/tfmini',
                                             messenger.Messages.float)

        result = self.get_serial()
        self.device = next(iter(result.keys()), None)
        print(repr(self.device), ": starting TF-mini")
        self.ser: Optional[serial.Serial] = None

        self.fps = self.distance = 0

        self.average = StreamingMovingAverage(3)
        self.average_fps = StreamingMovingAverage(20)

        while not self.open():
            sleep(2)

        if run:
            self.run()
Ejemplo n.º 7
0
        for t in manager.threads:
            try:
                t.stop()
            except:
                print("BLOOP!?")
    print("KILL DONE")
    exit(0)


listener_wrapper = messenger.CallbackListenerWrapper()

node = messenger.Node('octocamera', on_shutdown=kill)
settings_change = messenger.Listener('/settings_changed',
                                     messenger.Messages.string,
                                     callback=listener_wrapper.update)
recognition_publisher = messenger.Publisher('/recognition',
                                            messenger.Messages.string)

logger = node.logger

# Build pipeline
config = ConfigManager.get_value('camera')
grabber = PanoramaGrabber(config)
image_recognizer = ImageRecognizer(grabber,
                                   config_manager=ConfigManager,
                                   publisher=recognition_publisher)

# settings listeners
listener_wrapper.listeners.append(image_recognizer.refresh_config)

manager = None  # type: ThreadManager
Ejemplo n.º 8
0
# ROS setup before gevent
import messenger
from config_manager import ConfigManager
from websocket_log_handler import WebsocketLogHandler

movement_publisher = messenger.Publisher('/movement', messenger.Messages.motion)
kicker_publisher = messenger.Publisher('/kicker_speed', messenger.Messages.integer)
command_publisher = messenger.Publisher('/command', messenger.Messages.string)
strategy_state = messenger.Listener('/strategy', messenger.Messages.string)
canbus_state = messenger.Listener('/canbus_message', messenger.Messages.string)
websocket_log_handler = WebsocketLogHandler()
logging_state = messenger.Listener('/rosout_agg', messenger.Messages.logging, callback=websocket_log_handler.emit)
node = messenger.Node('io_server', disable_signals=True)

# thread fixes
import gevent
from gevent import monkey

monkey.patch_all(thread=False)

# imports
import json
from time import time

from flask import Flask, render_template, request, redirect
from flask_sockets import Sockets


logger = node.logger

app = Flask(__name__)