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)
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()
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()
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()
def configure_controller(app): controller = Controller() controller.init_app(app) scalectrl = ScaleFactory() scalectrl.init_app(app)
# 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()
def on_start(self): self.controller = Controller(self)
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()
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
def initController(model): """Init controller instance.""" return Controller(model)
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():
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()
def setUp(self): """Set up controller tests.""" model = MagicMock() self.model = model self.controller = Controller(model)
def __init__(self, verbose=False): self._objectName = "INTERFACE" self._objectLevel = 0 self._verbose = verbose self.controller = Controller()
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)
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:
from modules.controller import Controller if __name__ == "__main__": controller = Controller() controller.run()
from modules.controller import Controller control = Controller(23, 18) control.stop() control.cleanup()