Esempio n. 1
0
import sys
import logging

from database_service import DatabaseService
from mqtt_service import MqttService
from flask_server import WebService


def config_default_logger():
    logger = logging.getLogger()
    logger.setLevel(logging.DEBUG)
    handler = logging.StreamHandler(sys.stdout)
    log_format = logging.Formatter(
        '%(asctime)s * %(name)s - %(levelname)s - %(message)s')
    handler.setFormatter(log_format)
    logger.addHandler(handler)
    return logger


if __name__ == '__main__':
    logger = config_default_logger()
    db_client = DatabaseService(logger)

    mqtt = MqttService(logger, db_client)
    web_server = WebService(logger, db_client)

    mqtt.start()
    web_server.start()
Esempio n. 2
0
import json
import time
import threading

import RPi.GPIO as GPIO

from mqtt_service import MqttService
from nrf24l01 import NRF24L01
from arm_controller import ArmController

from config import *

rf24 = NRF24L01()
mqtt = MqttService()
arm = ArmController()

robot = False

trashbin = False


def button_press():
    global trashbin
    trashbin = not trashbin
    if trashbin:
        for _ in range(3):
            rf24.write(b'11')
            rf24.write(b'21')
            rf24.write(b'31')
            time.sleep(0.1)
    else:
Esempio n. 3
0
class Simulator():
    def on(self):
        self.mqtt = MqttService()
        self.mqtt.on()

    def rc(self):
        print("init rc")
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/enable',
            1)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/direction',
            0)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/velocity',
            0)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/angle',
            0)
        time.sleep(2)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/direction',
            1)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/velocity',
            1)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/angle',
            1)
        time.sleep(6)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/velocity',
            0)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/angle',
            -1)
        time.sleep(6)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/velocity',
            1)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/angle',
            0)
        time.sleep(6)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/direction',
            0)
        time.sleep(6)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/direction',
            2)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/velocity',
            1)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/angle',
            0)
        time.sleep(6)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/direction',
            0)

    def run(self):
        print("init")
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/enable',
            1)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/direction',
            0)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/velocity',
            0)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/uil/rc/angle',
            0)

        print("pos")
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/latitude',
            47.031944)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/longitude',
            9.083533)
        time.sleep(2)
        print("pos")
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/latitude',
            47.031891)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/longitude',
            9.083556)
        time.sleep(2)
        print("pos")
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/latitude',
            47.031844)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/longitude',
            9.083570)
        time.sleep(2)
        print("pos")
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/latitude',
            47.031798)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/longitude',
            9.083597)
        time.sleep(2)
        print("pos")
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/latitude',
            47.031745)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/longitude',
            9.083629)
        time.sleep(2)
        print("pos")
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/latitude',
            47.031766)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/longitude',
            9.083707)
        time.sleep(2)
        print("pos")
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/latitude',
            47.031788)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/longitude',
            9.083771)
        time.sleep(2)
        print("pos")
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/latitude',
            47.031807)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/longitude',
            9.083816)
        time.sleep(2)
        print("pos")
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/latitude',
            47.031860)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/longitude',
            9.083771)
        time.sleep(2)
        print("pos")
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/latitude',
            47.031910)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/longitude',
            9.083729)
        time.sleep(2)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/latitude',
            47.031965)
        print("pos")
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/longitude',
            9.083692)
        time.sleep(2)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/latitude',
            47.031962)
        print("pos")
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/longitude',
            9.083610)
        time.sleep(2)
        print("pos")
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/latitude',
            47.031950)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/longitude',
            9.083551)
        time.sleep(2)
        print("pos")
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/latitude',
            47.031944)
        self.mqtt.publish(
            '/654baff5-cd72-472a-859a-925afe5056f3/transprotobot/sil/gps/longitude',
            9.083533)
        time.sleep(1)
        print("end")
Esempio n. 4
0
 def on(self):
     self.mqtt = MqttService()
     self.mqtt.on()
Esempio n. 5
0

def on_mqtt_message(client, userdata, message):
    global robot_status
    status = str(message.payload.decode("utf-8"))
    robot_status = status


if __name__ == '__main__':
    # Initialize frame rate calculation
    frame_rate_calc = 1
    freq = cv2.getTickFrequency()
    font = cv2.FONT_HERSHEY_SIMPLEX

    object_detector = ObjectDetect()
    mqtt = MqttService()
    lcd = PCD8544()

    # Initialize Picamera and grab reference to the raw capture
    camera = PiCamera()
    camera.resolution = (IM_WIDTH, IM_HEIGHT)
    camera.framerate = 1
    rawCapture = PiRGBArray(camera, size=(IM_WIDTH, IM_HEIGHT))
    rawCapture.truncate(0)

    for frame1 in camera.capture_continuous(rawCapture,
                                            format="bgr",
                                            use_video_port=True):
        t1 = cv2.getTickCount()

        # Acquire frame and expand frame dimensions to have shape: [1, None, None, 3]