Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: IOTON-API QEI USBDevice mbed-ton ton-bot
Fork of ton-bot_teste by
main.cpp
00001 /** 00002 ****************************************************************************** 00003 * @file main.cpp 00004 * @author Kleber Lima da Silva (kleber@ioton.cc) 00005 * @version V0.0.1 00006 * @date 05-Julho-2017 00007 * @brief Programa de exemplo do Robô TON-BOT no modo seguidor de linha. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * COPYRIGHT(c) 2017 IOTON Technology 00012 * 00013 * Licensed under the Apache License, Version 2.0 (the "License"); 00014 * you may not use this file except in compliance with the License. 00015 * You may obtain a copy of the License at 00016 * 00017 * http://www.apache.org/licenses/LICENSE-2.0 00018 * 00019 * Unless required by applicable law or agreed to in writing, software 00020 * distributed under the License is distributed on an "AS IS" BASIS, 00021 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00022 * See the License for the specific language governing permissions and 00023 * limitations under the License. 00024 ****************************************************************************** 00025 */ 00026 00027 /* Includes ------------------------------------------------------------------*/ 00028 #include "main.h" 00029 00030 /** @addtogroup Seguidor de linha TON-BOT 00031 * @{ 00032 */ 00033 00034 /* Variáveis privadas --------------------------------------------------------*/ 00035 00036 00037 /* Funções Privadas ----------------------------------------------------------*/ 00038 00039 /** 00040 * @brief Programa Principal 00041 * @param Nenhum 00042 * @retval Nenhum 00043 */ 00044 int main(void) 00045 { 00046 const float KP = 0.008, PWM_MEDIO = 0.3; 00047 int32_t erro = 0, erro_anterior = 0; 00048 float MV = 0; 00049 00050 /* Ligue o TON com o botão USER pressionado para indicar o estado da bateria */ 00051 if (ton.USERisPressed()) 00052 { 00053 /* Necessário pressionar o botão RESET voltar ao modo normal */ 00054 ton.batteryStatus(); 00055 } 00056 00057 /* Inicialização do robô para seguir linha preta (pista branca) */ 00058 ton.setLED(GREEN); 00059 initTonBot(PRETA); 00060 00061 /* Inicio do programa ------------------------------------------------------*/ 00062 /* Aguarda o botão USER ser pressionado para ligar o robô */ 00063 while(!ton.USERisPressed()) 00064 { 00065 ton.toggleLED(RED); 00066 wait_ms(100); 00067 } 00068 wait(1); 00069 ton.setLED(BLUE); 00070 beeps(3, 100, 50); 00071 00072 00073 /* LOOP principal ----------------------------------------------------------*/ 00074 while (1) 00075 { 00076 /* Verifica a leitura dos sensores */ 00077 erro = getSensoresLinha(); 00078 if (erro == INFINITO) 00079 { 00080 erro = erro_anterior; 00081 } 00082 00083 /* Controlador Proporcional */ 00084 MV = KP * erro; 00085 00086 /* Acionamento dos motores */ 00087 setMotores(PWM_MEDIO + MV, PWM_MEDIO - MV); 00088 00089 /* Base de tempo do controlador */ 00090 wait_ms(10); 00091 00092 } // fim do loop principal 00093 } // fim da função principal 00094 00095 00096 /** 00097 * @} 00098 */ 00099 00100 /************************ (C) COPYRIGHT IOTON Technology **********************/ 00101 /***********************************END OF FILE********************************/
Generated on Wed Jul 20 2022 00:39:11 by
1.7.2