示例#1
0
class ControllerTests(unittest.TestCase):
    """Controller unit tests."""
    def setUp(self):
        """Set up controller tests."""
        model = MagicMock()
        self.model = model
        self.controller = Controller(model)

    def test_makeStep(self):
        """Test make step."""
        def makeStep():
            self.model.isStepMade = True

        self.model.isStepMade = False
        self.model.makeStep = makeStep
        self.controller.makeStep()
        self.assertTrue(self.model.isStepMade)

    def test_getLifeMap(self):
        """Test life map."""
        checkValue = 132132
        self.model.getLifeMap = MagicMock(return_value=checkValue)
        lifeMap = self.controller.getMap()
        self.assertEqual(lifeMap, checkValue)

    def test_getLifeMapSize(self):
        """Test life map size."""
        checkValue = 132132
        lifeMap = MagicMock()
        lifeMap.getSize = MagicMock(return_value=checkValue)
        self.model.getLifeMap = MagicMock(return_value=lifeMap)
        lifeMap = self.controller.getLifemapSize()
        self.assertEqual(lifeMap, checkValue)
示例#2
0
def request_img():
    camera = Camera()
    controller = Controller()
    D1 = DD(27)
    D2 = DD(4)
    print("request_img")
    while (1):
        if (camera.test() > 0.2 and D2 == False and D1 == True):
            controller.Forward()
示例#3
0
def detect_distance():
    controller = Controller()
    D1 = DD(27)
    D2 = DD(4)
    print("detect_distance")
    while (1):
        if (D1.status() == False):
            controller.Stop()
        elif (D2.status() == True):
            controller.Stop()
示例#4
0
def start_planner():
    rospy.init_node("planner", anonymous=True, disable_signals=True)

    model_path = rospy.get_param("~mppic/model_path", None)
    use_nn_model = rospy.get_param("~mppic/use_nn_model", True)

    if (use_nn_model):
        model = nnio.ONNXModel(model_path)
    else:
        model = RosbotKinematic()

    control_generator = MPPICGenerator(model)
    optimizer = MPPICOptimizer(control_generator, triangle_cost,
                               calc_softmax_seq)
    odom = Odom()
    controller = Controller()
    goal_handler = GoalHandler()
    path_handler = PathHandler()
    metric_handler = MetricHandler(mean_dist_metric)

    mppic = LocalPlanner(optimizer, odom, controller, goal_handler,
                         path_handler, metric_handler)

    mppic.start()
    rospy.spin()
示例#5
0
def configure_controller(app):
    controller = Controller()
    controller.init_app(app)

    scalectrl = ScaleFactory()
    scalectrl.init_app(app)
示例#6
0
# The core algorithm writing here
from modules.camera import Camera
from modules.controller import Controller
from modules.DD import DD
import time

if __name__ == '__main__':
    controller = Controller()
    D1 = DD(27)  #Front DD , obstacle detection
    D2 = DD(4)  ##Back DD , person detection
    while (True):
        if (D1.status() == False):
            # Obstacle has been detected
            # stop
            controller.Stop()
        elif (D2.status() == True):
            # did not detect person
            # stop
            controller.Stop()
        else:
            # Fron got no obstacle and do detect the face and the person is in the range
            controller.Forward()
示例#7
0
 def on_start(self):
     self.controller = Controller(self)
示例#8
0
文件: trove.py 项目: purepitch/trove
parser.add_argument('--onecmd', nargs=1, help="run a single command")
parser.add_argument('--file', nargs=1, help="name of encrypted input file")

# Initialize Model
model = Model()
model.program_name = "trove"
model.version = "0.1"

# Inititalize View
view = View()

# Parse command line arguments
args = parser.parse_args()

# Initialize Controller
controller = Controller(model, view)

# Say hello
controller.print_hello_message()

# Run startup checks
controller.run_startup_checks()

if args.file is not None:
    controller.encrypted_file = args.file[0]

#if not controller.config_file_has_encrypted_file():
#    controller.add_bcrypt_section()
#    controller.init_passwd_file()
if controller.config_file_has_encrypted_file():
    controller.read_encrypted_file()
示例#9
0
import threading
from flask import Flask, render_template
from flask_socketio import SocketIO, emit
from modules.controller import Controller
from modules.rover_coms import Rover
"""
TODO: 
- Add swal when connected to rover/etc
- Have a connected status icon in the corner of dash
"""

app = Flask(__name__,
            template_folder='../templates',
            static_folder='../static')
socketio = SocketIO(app)
controller = Controller()
rover = Rover(socketio, controller)


@app.route('/')
def entry():
    """
    Default page to render
    """
    return render_template('index.html')


@socketio.on('message')
def handle_message(payload):
    """
    Log to terminal the message received from the dashboard
示例#10
0
def initController(model):
    """Init controller instance."""
    return Controller(model)
示例#11
0
import sys

import RPi.GPIO as gpio
from modules.controller import Controller

MOTOR_PINS = [13, 19, 26, 21, 20, 16]
SERVO_PIN = 18
SONAR_PINS = [23, 24]
controller = Controller(MOTOR_PINS, SERVO_PIN, SONAR_PINS) # motor pins (a list)

#parameters
CLOSE_DIST = 3  #distance of when to lock the door

#def for slipper cars
def slipper_1_out():
  controller.slipper_move(0, "forward")
  controller.stop()

def slipper_2_out():
  controller.slipper_move(1, "forward")
  controller.stop()

def slipper_3_out():
  controller.slipper_move(2, "forward")
  controller.stop()

def slipper_1_in():
  controller.slipper_move(0, "backward")
  controller.stop()

def slipper_2_in():
示例#12
0
from PIL import Image, ImageDraw, ImageFont
import adafruit_ssd1306
import time
import RPi.GPIO as GPIO

from modules.controller import Controller

GPIO.setmode(GPIO.BCM)

font = ImageFont.truetype(
    "/usr/share/fonts/truetype/quicksand/Quicksand-Bold.ttf", 10)

oled_reset = digitalio.DigitalInOut(board.D4)

WIDTH = 128
HEIGHT = 64
BORDER = 5

spi = board.SPI()
oled_cs = digitalio.DigitalInOut(board.D5)
oled_dc = digitalio.DigitalInOut(board.D6)
oled = adafruit_ssd1306.SSD1306_SPI(WIDTH, HEIGHT, spi, oled_dc, oled_reset,
                                    oled_cs)

oled.fill(0)
oled.show()

controller = Controller(font, oled)
#oled.image(image)
#oled.show()
示例#13
0
 def setUp(self):
     """Set up controller tests."""
     model = MagicMock()
     self.model = model
     self.controller = Controller(model)
示例#14
0
 def __init__(self, verbose=False):
     self._objectName = "INTERFACE"
     self._objectLevel = 0
     self._verbose = verbose
     self.controller = Controller()
示例#15
0
class Interface:
    def __init__(self, verbose=False):
        self._objectName = "INTERFACE"
        self._objectLevel = 0
        self._verbose = verbose
        self.controller = Controller()

    # WELCOME! ###############################################################################

    def welcomeMessage(self):
        print("## WELCOME TO GUTENBERG")
        print("## A batch watermark applicator tool")
        print(
            "## ----------------------------------------------------------------"
        )
        print("## Made with love by Alessio Vaccaro")
        print("## www.alessiovaccaro.com")
        print(
            "## ----------------------------------------------------------------"
        )
        print(
            "## Gutenberg is part of the Blue Journey Astrophotography project\n"
        )

    def endingMessage(self):
        input("\n## Please press ENTER to exit...")
        print("## Bye!")
        time.sleep(1)

    # QUESTIONS ##############################################################################

    def askForSomething(self, message):
        log = self._loggerReturn(message)
        userInput = input(log)
        return (userInput)

    def askForWatermarkBrightness(self):
        watermarkBrightness = int(
            self.askForSomething(
                "Please insert watermark brightness [0-100%]: ")) * 0.01
        self.controller.setWatermarkDestinationBrightness(watermarkBrightness)

    def askForWatermarkOffsetPercentage(self):
        watermarkOffsetPercentage = int(
            self.askForSomething(
                "Please insert watermark offset [0-100%]: ")) * 0.01
        self.controller.setWatermarkDestinationOffsetPercentage(
            watermarkOffsetPercentage)

    def askForWatermarkSizePercentage(self):
        watermarkSizePercentage = int(
            self.askForSomething(
                "Please insert watermark size [0-100%]: ")) * 0.01
        self.controller.setWatermarkDestinationSizePercentage(
            watermarkSizePercentage)

    def askForOutputFolder(self):
        self._logger("Selecting output folder...")
        self.controller.setOutputFolder()
        self._logger("Output folder selected")

    def askForOutputPrefix(self):
        outputPrefix = self.askForSomething(
            "Please output prefix [ex. 'prefix' for 'prefix-myimage.jpg']: ")
        self.controller.setOutputPrefix(outputPrefix)

    def askForOutputSuffix(self):
        outputSuffix = self.askForSomething(
            "Please output suffix [ex. 'suffix' for 'myimage-suffix.jpg']: ")
        self.controller.setOutputSuffix(outputSuffix)

    def askForImages(self):
        selected = False
        tries = 1
        self._logger("Please select images...")
        while (not selected) and (tries < 3):
            if self.controller.fillBucket():
                self._logger("Images selected...")
                selected = True
            else:
                self._logger("Please select images...")
                tries += 1

    def askForWatermark(self):
        selected = False
        tries = 1
        self._logger("Please select watermark...")
        while (not selected) and (tries < 3):
            if self.controller.loadWatermark():
                self._logger("Watermark selected")
                selected = True
            else:
                self._logger("Please select watermark...")
                tries += 1

    def startTheProcess(self):
        self._logger("Starting...")
        self.controller.process()
        self._logger("Done!")

    # LOOP ##################################################################################

    def loop(self):
        # WELCOME
        self.welcomeMessage()
        # Prepare Bucket and Loading Watermark
        self.askForImages()
        if self.controller.bucketIsReady():
            self.askForWatermark()
            if self.controller.watermarkIsReady():
                # Option setting
                self.askForWatermarkBrightness()
                self.askForWatermarkOffsetPercentage()
                self.askForWatermarkSizePercentage()
                self.askForOutputPrefix()
                self.askForOutputSuffix()
                self.askForOutputFolder()
                # START
                self.startTheProcess()
        # END
        self.endingMessage()

    # LOGGER ################################################################################

    def _logger(self, message):
        if self._verbose == True:
            now = time.strftime("%H:%M:%S", time.localtime())
            message = "%s [%s]: %s" % (now, self._objectName, message)
            print(message)

    def _loggerReturn(self, message):
        now = time.strftime("%H:%M:%S", time.localtime())
        message = "%s [%s]: %s" % (now, self._objectName, message)
        return (message)
示例#16
0
    exit(-1)

import RPi.GPIO as gpio
from flask import Flask
from flask import jsonify
from modules.camera import Camera
from modules.controller import Controller
from rfid_thread import rfid_thread

mode = sys.argv[1]
SUBSCRIPTION_KEY = 'PUT SUBSCRIPTION KEY HERE'
if mode == 'text':
    camera = Camera(SUBSCRIPTION_KEY)

app = Flask(__name__)
controller = Controller(23, 18)  # motor_pin, servo_pin


@app.route('/')
def root():
    return 'woooow'


@app.route('/forward')
def forward():
    controller.forward()
    return jsonify(success=True)


"""
TODO: 
示例#17
0
from modules.controller import Controller

if __name__ == "__main__":
    controller = Controller()
    controller.run()
示例#18
0
文件: stop.py 项目: tony2037/api_car
from modules.controller import Controller

control = Controller(23, 18)
control.stop()
control.cleanup()