Ejemplo n.º 1
0
from communication.Serial import Serial
from bridge.RobotIO import RobotIO

# configure argument parset
parser = argparse.ArgumentParser(description='Controlls robot')
parser.add_argument('--debug', dest='debug', action='store_true')
parser.set_defaults(feature=False)
args = parser.parse_args()

# configure logging and exception handler
logging_config = LoggingConfig(config.logging['log_file'],
                               config.logging['log_entries'])
logging_config.enable_debug(args.debug)
logger = logging_config.get_logger()
sys.excepthook = logging_config.set_error_hadler

# configure mqtt connection, serial and RobotIO bridge
mqtt_connection = MqttConnection(config.mqtt['host'], config.mqtt['port'],
                                 config.mqtt['user'], config.mqtt['password'])
serial = Serial(config.serial)

robot_io = RobotIO(mqtt_connection, serial, logger)
mqtt_connection.listen(robot_io.received_command)
mqtt_connection.connect()
serial.add_callback(robot_io.received_serial_message)
serial.connect()

# listen to serial commands in an infinite loop
while True:
    serial.listen()
    sleep(0.05)
Ejemplo n.º 2
0
 def serial(self) -> Serial:
     return Serial(
         self.configuration_repository().get_config(
             SerialCommunicationCfg.get_classname()), self.root_logger())
Ejemplo n.º 3
0
# configure argument parser
parser = argparse.ArgumentParser(description='Robot configuration')
parser.add_argument(
    'detector_type', action='store',
    help='Select detector type available types: colored-object, specific-face. For '
         'specific face an --extra-cfg is required with an image path containing the face file to be followed'
)
parser.add_argument(
    '--extra_cfg', dest='extra_cfg', action='store',
    help='Extra parameter for detector_type'
)
parser.add_argument('--show-video', dest='video', action='store_true', help='shows images on GUI')
parser.set_defaults(feature=False)
args = parser.parse_args()

serial = Serial(config.serial)  #configure serial
serial.connect()
detector = ObjectDetectorFactory.get(args.detector_type, args.extra_cfg)
object_follower = ObjectFollower(detector, RobotSerialCommandsConverter(), config_navigation.object_size_threshold)
image_debug = ImageDebug((0, 255, 255), 2)

frame_provider = VideoStream(usePiCamera=True, resolution=(1024, 768)).start()
time.sleep(2.0)


while not cv2.waitKey(30) & 0xFF == ord('q'):
    frame = frame_provider.read()
    # image is resised by with with some amount in px for better performance
    frame = imutils.resize(frame, width=config_navigation.resize_image_by_width)
    frame = imutils.rotate(frame, config_navigation.rotate_camera_by)
    object_follower.process(frame)
from multiprocessing import Queue

from flask import Flask, Response, request

import config
from communication.Serial import Serial
from navigation.RobotSerialCommandsConverter import RobotSerialCommandsConverter
from navigation.LongRunningCommand import LongRunningCommand

app = Flask(__name__)
serial = Serial(config.serial['port'], config.serial['baud_rate'])
serial.connect()
commands_converter = RobotSerialCommandsConverter()

communication_queue = Queue(maxsize=3)
process = LongRunningCommand(serial, communication_queue, 5000)
process.daemon = True
process.start()


@app.route("/api/motors", methods=["POST"])
# this is a naive implementation, will be refactored in the final release
def motors_command():
    request_params = request.form
    command = request_params['command']
    angle = 90 if request_params['angle'] == 'None' else int(
        request_params['angle'])
    if command == 'left':
        angle = 90 - angle
    elif command == 'right':
        angle = 90 + angle
Ejemplo n.º 5
0
from communication.Serial import Serial
from communication.SerialMqttBridge import SerialMqttBridge

# configure argument parser
parser = argparse.ArgumentParser(description='Controlls robot')
parser.add_argument('--debug', dest='debug', action='store_true')
parser.set_defaults(feature=False)
args = parser.parse_args()

# configure logging and exception handler
logging_config = LoggingConfig(config.logging['log_file'],
                               config.logging['log_entries'])
logging_config.enable_debug(args.debug)
logger = logging_config.get_logger()
sys.excepthook = logging_config.set_error_hadler

# configure mqtt connection, serial and SerialMqttBridge bridge
mqtt_connection = MqttConnection(config.mqtt['host'], config.mqtt['port'],
                                 config.mqtt['user'], config.mqtt['password'])
serial = Serial(config.serial['port'], config.serial['baud_rate'])

bridge = SerialMqttBridge(mqtt_connection, serial, logger)
mqtt_connection.listen(bridge.received_command)
mqtt_connection.connect()
serial.add_callback(bridge.received_serial_message)
serial.connect()

# listen to serial commands in an infinite loop
while True:
    serial.loop()
    sleep(0.05)