예제 #1
0
파일: robot.py 프로젝트: javacasm/raspiCar
def left(speed):
    global kit
    utils.myDebug('left ' + str(speed))
    kit.motor4.throttle =  speed
    kit.motor3.throttle = -1 * speed
    kit.motor2.throttle =  speed
    kit.motor1.throttle = -1 * speed
예제 #2
0
파일: robot.py 프로젝트: javacasm/raspiCar
def stop():
    global kit
    utils.myDebug('stop')
    kit.motor4.throttle = 0
    kit.motor3.throttle = 0
    kit.motor2.throttle = 0
    kit.motor1.throttle = 0
예제 #3
0
파일: robot.py 프로젝트: javacasm/raspiCar
def forward(speed):
    global kit
    utils.myDebug('forward ' + str(speed))
    kit.motor4.throttle = speed
    kit.motor3.throttle = speed
    kit.motor2.throttle = -1 * speed
    kit.motor1.throttle = -1 * speed 
예제 #4
0
def checkPythonProcessRunning(pythonScript):
    counter = 0
    for proc in psutil.process_iter():
        if pythonScript in proc.cmdline():
            counter += 1
            utils.myDebug('cmd: ' + str(proc.cmdline()))
    utils.myLog(pythonScript + ' está en ejecución {} veces'.format(counter))
    return counter
예제 #5
0
def getImage(preview=False):
    global camera
    if preview:
        camera.start_preview()  # muestra la previsualizacion
        sleep(1)  # espera 5 segundos
    now = datetime.now()
    date_time = now.strftime("%Y%m%d-%H%M%S")
    fileName = 'image' + date_time + '.jpg'
    fullName = config.ImagesDirectory + fileName
    utils.myDebug("image - " + fullName)
    camera.capture(fullName)  # guarda la imagen
    if preview: camera.stop_preview()  # cierra la previsualizacion
    return fullName
예제 #6
0
def updateBot(bot):
    """Answer the message the user sent."""
    global update_id
    global chat_id
    global time_between_picture
    global welcomeMsg
    global nightMode
    global bReboot

    #utils.myLog('Updating telegramBot')
    # Request updates after the last update_id
    for update in bot.get_updates(offset=update_id, timeout=10):
        update_id = update.update_id + 1

        if update.message:  # your bot can receive updates without messages
            # Proccess the incoming message
            comando = update.message.text  # message text
            command_time = update.message.date  # command date
            user = update.message.from_user  #User full objetct
            chat_id = int(update.message.from_user.id)
            user_real_name = user.first_name  #USER_REAL_NAME
            if chat_id not in config.ALLOWED_USERS:
                message = 'User: {} not allowed. Chat_id {} command: {}. Will be reported'.format(
                    str(user_real_name), str(chat_id), comando)
                sendMsg2Admin(message)
                break
            TelegramBase.chat_ids[user_real_name] = [command_time, chat_id]
            utils.myLog('Command: ' + comando + ' from user ' +
                        str(user_real_name) + ' in chat id:' + str(chat_id) +
                        ' at ' + str(command_time))
            if comando == cmdStart:
                update.message.reply_text(welcomeMsg,
                                          reply_markup=user_keyboard_markup)
            elif comando == cmdHi:
                update.message.reply_text('Hello {}'.format(
                    update.message.from_user.first_name),
                                          reply_markup=user_keyboard_markup)
            elif comando == cmdInfo:
                answer = 'Info: ' + utils.getStrDateTime(
                ) + '\n==========================\n\n' + 'Tiempo entre imágenes: ' + getTimeLapseStr(
                ) + '\n ' + str(len(os.listdir(
                    config.ImagesDirectory))) + ' imágenes'
                update.message.reply_text(
                    answer,
                    parse_mode=telegram.ParseMode.MARKDOWN,
                    reply_markup=user_keyboard_markup)
            elif comando == cmdHelp:
                bot.send_message(chat_id=chat_id,
                                 text=commandList,
                                 reply_markup=user_keyboard_markup)
            elif comando == cmdUsers:
                sUsers = TelegramBase.getUsersInfo()
                TelegramBase.send_message(sUsers, chat_id)
            elif comando == cmdDayMode:
                nightMode == False
                update.message.reply_text('Day mode',
                                          reply_markup=user_keyboard_markup)
            elif comando == cmdNightMode:
                nightMode == True
                update.message.reply_text('Night mode',
                                          reply_markup=user_keyboard_markup)
            elif comando == cmdPhoto:
                answer = getImage()
                utils.myLog(answer)
                TelegramBase.send_picture(answer, chat_id)
                update.message.reply_text(
                    answer,
                    parse_mode=telegram.ParseMode.MARKDOWN,
                    reply_markup=user_keyboard_markup)
            elif comando == cmdLastPhoto:
                imagenes = os.listdir(config.ImagesDirectory)
                answer = config.ImagesDirectory + sorted(imagenes)[-1]
                TelegramBase.send_picture(answer, chat_id)
                update.message.reply_text(
                    answer,
                    parse_mode=telegram.ParseMode.MARKDOWN,
                    reply_markup=user_keyboard_markup)
            elif comando == cmdListPhotos:
                imagenes = sorted(os.listdir(config.ImagesDirectory))
                answer = str(
                    len(imagenes)) + ' Imágenes\n----------------------\n'
                utils.myDebug(answer)
                contadorImagenes = 1
                for imagen in imagenes:
                    answer += str(contadorImagenes) + ' ' + imagen + '\n'
                    contadorImagenes += 1
                utils.myDebug(answer)
                if len(imagenes) > 70:
                    answer = answer[0:2041] + ' \n...'
                update.message.reply_text(
                    answer,
                    parse_mode=telegram.ParseMode.MARKDOWN,
                    reply_markup=user_keyboard_markup)
            elif comando.startswith('/N'):
                numero = int(comando[2:])
                imagenes = sorted(os.listdir(config.ImagesDirectory))
                answer = config.ImagesDirectory + imagenes[numero]
                utils.myLog(answer)
                TelegramBase.send_picture(answer, chat_id)
                update.message.reply_text(
                    answer,
                    parse_mode=telegram.ParseMode.MARKDOWN,
                    reply_markup=user_keyboard_markup)
            elif comando.startswith('/T'):
                time_between_picture = int(comando[2:])
                answer = getTimeLapseStr()
                utils.myLog(answer)
                update.message.reply_text(
                    answer,
                    parse_mode=telegram.ParseMode.MARKDOWN,
                    reply_markup=user_keyboard_markup)
            elif comando.startswith('/image'):
                answer = config.ImagesDirectory + comando[1:]
                TelegramBase.send_picture(answer, chat_id)
                update.message.reply_text(
                    answer,
                    parse_mode=telegram.ParseMode.MARKDOWN,
                    reply_markup=user_keyboard_markup)
            elif comando == cmdTemp:
                answer = raspi.getTemp()
                utils.myLog(answer)
                update.message.reply_text(
                    answer,
                    parse_mode=telegram.ParseMode.MARKDOWN,
                    reply_markup=user_keyboard_markup)
            elif comando == cmdDF:
                answer = raspi.getDiskUsed()
                utils.myLog(answer)
                update.message.reply_text(
                    answer,
                    parse_mode=telegram.ParseMode.MARKDOWN,
                    reply_markup=user_keyboard_markup)
            elif comando == cmdIP:
                answer = raspi.getIP()
                utils.myLog(answer)
                update.message.reply_text(
                    answer,
                    parse_mode=telegram.ParseMode.MARKDOWN,
                    reply_markup=user_keyboard_markup)
            elif comando == cmdReboot:
                answer = 'Reboot in 10 seconds!!!'
                utils.myLog(answer)
                update.message.reply_text(
                    answer,
                    parse_mode=telegram.ParseMode.MARKDOWN,
                    reply_markup=user_keyboard_markup)
                bReboot = True
            else:
                update.message.reply_text('echobot: ' + update.message.text,
                                          reply_markup=user_keyboard_markup)
예제 #7
0
파일: robot.py 프로젝트: javacasm/raspiCar
def init():
    global kit
    utils.myDebug('Robot.py ' + v)
    kit  = MotorKit()