Programa de exemplo do Robô TON-BOT no modo seguidor de linha.

Dependencies:   IOTON-API QEI USBDevice mbed-ton ton-bot

Fork of ton-bot_teste by IOTON Technology

Committer:
krebyy
Date:
Wed Jul 05 15:50:40 2017 +0000
Revision:
2:027fe033f5f7
Parent:
1:584ac95c4061
Commit inicial

Who changed what in which revision?

UserRevisionLine numberNew contents of line
krebyy 1:584ac95c4061 1 /**
krebyy 1:584ac95c4061 2 ******************************************************************************
krebyy 1:584ac95c4061 3 * @file main.cpp
krebyy 1:584ac95c4061 4 * @author Kleber Lima da Silva (kleber@ioton.cc)
krebyy 1:584ac95c4061 5 * @version V0.0.1
krebyy 2:027fe033f5f7 6 * @date 05-Julho-2017
krebyy 2:027fe033f5f7 7 * @brief Programa de exemplo do Robô TON-BOT no modo seguidor de linha.
krebyy 1:584ac95c4061 8 ******************************************************************************
krebyy 1:584ac95c4061 9 * @attention
krebyy 1:584ac95c4061 10 *
krebyy 1:584ac95c4061 11 * COPYRIGHT(c) 2017 IOTON Technology
krebyy 1:584ac95c4061 12 *
krebyy 1:584ac95c4061 13 * Licensed under the Apache License, Version 2.0 (the "License");
krebyy 1:584ac95c4061 14 * you may not use this file except in compliance with the License.
krebyy 1:584ac95c4061 15 * You may obtain a copy of the License at
krebyy 1:584ac95c4061 16 *
krebyy 1:584ac95c4061 17 * http://www.apache.org/licenses/LICENSE-2.0
krebyy 1:584ac95c4061 18 *
krebyy 1:584ac95c4061 19 * Unless required by applicable law or agreed to in writing, software
krebyy 1:584ac95c4061 20 * distributed under the License is distributed on an "AS IS" BASIS,
krebyy 1:584ac95c4061 21 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
krebyy 1:584ac95c4061 22 * See the License for the specific language governing permissions and
krebyy 1:584ac95c4061 23 * limitations under the License.
krebyy 1:584ac95c4061 24 ******************************************************************************
krebyy 1:584ac95c4061 25 */
krebyy 0:52cc151dc505 26
krebyy 1:584ac95c4061 27 /* Includes ------------------------------------------------------------------*/
krebyy 1:584ac95c4061 28 #include "main.h"
krebyy 0:52cc151dc505 29
krebyy 2:027fe033f5f7 30 /** @addtogroup Seguidor de linha TON-BOT
krebyy 1:584ac95c4061 31 * @{
krebyy 1:584ac95c4061 32 */
krebyy 0:52cc151dc505 33
krebyy 1:584ac95c4061 34 /* Variáveis privadas --------------------------------------------------------*/
krebyy 0:52cc151dc505 35
krebyy 0:52cc151dc505 36
krebyy 1:584ac95c4061 37 /* Funções Privadas ----------------------------------------------------------*/
krebyy 1:584ac95c4061 38
krebyy 1:584ac95c4061 39 /**
krebyy 1:584ac95c4061 40 * @brief Programa Principal
krebyy 1:584ac95c4061 41 * @param Nenhum
krebyy 1:584ac95c4061 42 * @retval Nenhum
krebyy 1:584ac95c4061 43 */
krebyy 1:584ac95c4061 44 int main(void)
krebyy 0:52cc151dc505 45 {
krebyy 2:027fe033f5f7 46 const float KP = 0.008, PWM_MEDIO = 0.3;
krebyy 2:027fe033f5f7 47 int32_t erro = 0, erro_anterior = 0;
krebyy 2:027fe033f5f7 48 float MV = 0;
krebyy 1:584ac95c4061 49
krebyy 1:584ac95c4061 50 /* Ligue o TON com o botão USER pressionado para indicar o estado da bateria */
krebyy 1:584ac95c4061 51 if (ton.USERisPressed())
krebyy 1:584ac95c4061 52 {
krebyy 1:584ac95c4061 53 /* Necessário pressionar o botão RESET voltar ao modo normal */
krebyy 1:584ac95c4061 54 ton.batteryStatus();
krebyy 1:584ac95c4061 55 }
krebyy 1:584ac95c4061 56
krebyy 2:027fe033f5f7 57 /* Inicialização do robô para seguir linha preta (pista branca) */
krebyy 2:027fe033f5f7 58 ton.setLED(GREEN);
krebyy 2:027fe033f5f7 59 initTonBot(PRETA);
krebyy 1:584ac95c4061 60
krebyy 1:584ac95c4061 61 /* Inicio do programa ------------------------------------------------------*/
krebyy 2:027fe033f5f7 62 /* Aguarda o botão USER ser pressionado para ligar o robô */
krebyy 2:027fe033f5f7 63 while(!ton.USERisPressed())
krebyy 2:027fe033f5f7 64 {
krebyy 2:027fe033f5f7 65 ton.toggleLED(RED);
krebyy 2:027fe033f5f7 66 wait_ms(100);
krebyy 2:027fe033f5f7 67 }
krebyy 1:584ac95c4061 68 wait(1);
krebyy 2:027fe033f5f7 69 ton.setLED(BLUE);
krebyy 1:584ac95c4061 70 beeps(3, 100, 50);
krebyy 1:584ac95c4061 71
krebyy 0:52cc151dc505 72
krebyy 1:584ac95c4061 73 /* LOOP principal ----------------------------------------------------------*/
krebyy 1:584ac95c4061 74 while (1)
krebyy 1:584ac95c4061 75 {
krebyy 2:027fe033f5f7 76 /* Verifica a leitura dos sensores */
krebyy 2:027fe033f5f7 77 erro = getSensoresLinha();
krebyy 2:027fe033f5f7 78 if (erro == INFINITO)
krebyy 0:52cc151dc505 79 {
krebyy 2:027fe033f5f7 80 erro = erro_anterior;
krebyy 1:584ac95c4061 81 }
krebyy 0:52cc151dc505 82
krebyy 2:027fe033f5f7 83 /* Controlador Proporcional */
krebyy 2:027fe033f5f7 84 MV = KP * erro;
krebyy 0:52cc151dc505 85
krebyy 2:027fe033f5f7 86 /* Acionamento dos motores */
krebyy 2:027fe033f5f7 87 setMotores(PWM_MEDIO + MV, PWM_MEDIO - MV);
krebyy 2:027fe033f5f7 88
krebyy 2:027fe033f5f7 89 /* Base de tempo do controlador */
krebyy 2:027fe033f5f7 90 wait_ms(10);
krebyy 0:52cc151dc505 91
krebyy 1:584ac95c4061 92 } // fim do loop principal
krebyy 1:584ac95c4061 93 } // fim da função principal
krebyy 0:52cc151dc505 94
krebyy 0:52cc151dc505 95
krebyy 1:584ac95c4061 96 /**
krebyy 1:584ac95c4061 97 * @}
krebyy 1:584ac95c4061 98 */
krebyy 0:52cc151dc505 99
krebyy 1:584ac95c4061 100 /************************ (C) COPYRIGHT IOTON Technology **********************/
krebyy 1:584ac95c4061 101 /***********************************END OF FILE********************************/