Version 1.3 du soft robot
This commit is contained in:
parent
b1d9461430
commit
365843d786
17 changed files with 917 additions and 847 deletions
|
@ -41,8 +41,8 @@
|
||||||
<tool id="com.atollic.truestudio.exe.debug.toolchain.gcc.507098916" name="C Compiler" superClass="com.atollic.truestudio.exe.debug.toolchain.gcc">
|
<tool id="com.atollic.truestudio.exe.debug.toolchain.gcc.507098916" name="C Compiler" superClass="com.atollic.truestudio.exe.debug.toolchain.gcc">
|
||||||
<option id="com.atollic.truestudio.gcc.symbols.defined.110632980" name="Defined symbols" superClass="com.atollic.truestudio.gcc.symbols.defined" useByScannerDiscovery="false" valueType="definedSymbols">
|
<option id="com.atollic.truestudio.gcc.symbols.defined.110632980" name="Defined symbols" superClass="com.atollic.truestudio.gcc.symbols.defined" useByScannerDiscovery="false" valueType="definedSymbols">
|
||||||
<listOptionValue builtIn="false" value="STM32F10X_LD"/>
|
<listOptionValue builtIn="false" value="STM32F10X_LD"/>
|
||||||
<listOptionValue builtIn="false" value="USE_STDPERIPH_DRIVER"/>
|
|
||||||
<listOptionValue builtIn="false" value="__NO_INACTIVITY_SHUTDOWN__"/>
|
<listOptionValue builtIn="false" value="__NO_INACTIVITY_SHUTDOWN__"/>
|
||||||
|
<listOptionValue builtIn="false" value="USE_STDPERIPH_DRIVER"/>
|
||||||
</option>
|
</option>
|
||||||
<option id="com.atollic.truestudio.gcc.directories.select.902131530" name="Include path" superClass="com.atollic.truestudio.gcc.directories.select" useByScannerDiscovery="false" valueType="includePath">
|
<option id="com.atollic.truestudio.gcc.directories.select.902131530" name="Include path" superClass="com.atollic.truestudio.gcc.directories.select" useByScannerDiscovery="false" valueType="includePath">
|
||||||
<listOptionValue builtIn="false" value="../src"/>
|
<listOptionValue builtIn="false" value="../src"/>
|
||||||
|
|
42
software/robot/X-CTU_command_List.xml
Normal file
42
software/robot/X-CTU_command_List.xml
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<data>
|
||||||
|
<loop>false</loop>
|
||||||
|
<repeat_times>1</repeat_times>
|
||||||
|
<repeat_period>500</repeat_period>
|
||||||
|
<packets_list>
|
||||||
|
<packet name="Move">
|
||||||
|
<payload>4D3D313030410D</payload>
|
||||||
|
</packet>
|
||||||
|
<packet name="Turn">
|
||||||
|
<payload>543D313030580D</payload>
|
||||||
|
</packet>
|
||||||
|
<packet name="Ping">
|
||||||
|
<payload>70700D</payload>
|
||||||
|
</packet>
|
||||||
|
<packet name="Start without watchdog">
|
||||||
|
<payload>75750D</payload>
|
||||||
|
</packet>
|
||||||
|
<packet name="GetVersion">
|
||||||
|
<payload>56560D</payload>
|
||||||
|
</packet>
|
||||||
|
<packet name="Reset">
|
||||||
|
<payload>72720D</payload>
|
||||||
|
</packet>
|
||||||
|
<packet name="Start With Wtachdog">
|
||||||
|
<payload>57570D</payload>
|
||||||
|
</packet>
|
||||||
|
<packet name="Reset Watchdog">
|
||||||
|
<payload>77770D</payload>
|
||||||
|
</packet>
|
||||||
|
<packet name="GetState">
|
||||||
|
<payload>62620D</payload>
|
||||||
|
</packet>
|
||||||
|
<packet name="LongMove">
|
||||||
|
<payload>4D3D31303030710D</payload>
|
||||||
|
</packet>
|
||||||
|
<packet name="GetBattery">
|
||||||
|
<payload>76760D</payload>
|
||||||
|
</packet>
|
||||||
|
</packets_list>
|
||||||
|
</data>
|
|
@ -5,28 +5,33 @@
|
||||||
* @version V1.0
|
* @version V1.0
|
||||||
* @date 16-mai-2016
|
* @date 16-mai-2016
|
||||||
* @brief Supervision de la tension batterie et detection de charge.
|
* @brief Supervision de la tension batterie et detection de charge.
|
||||||
* Calcule le voltage de la batterie <EFBFBD> interval r<EFBFBD>gulier.
|
* Calcule le voltage de la batterie à interval régulier.
|
||||||
* Converti le voltage batterie en signaux de commande - 2 -1 - 0.
|
* Converti le voltage batterie en signaux de commande - 2 -1 - 0.
|
||||||
* Configure une interruption externe pour d<EFBFBD>tecter le branchement
|
* Configure une interruption externe pour détecter le branchement
|
||||||
* du chargeur.
|
* du chargeur.
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <battery.h>
|
|
||||||
#include "system_dumby.h"
|
|
||||||
#include "motor.h"
|
|
||||||
#include <stm32f10x.h>
|
#include <stm32f10x.h>
|
||||||
|
#include "battery.h"
|
||||||
|
#include "system_dumby.h"
|
||||||
|
|
||||||
uint16_t PrescalerValue = 0;
|
|
||||||
uint16_t PWM_BATTERY_ON = 0xC0;
|
|
||||||
uint16_t PWM_BATTERY_OFF = 0;
|
|
||||||
TIM_TimeBaseInitTypeDef TIM_BaseTempsTimer;
|
|
||||||
TIM_OCInitTypeDef TIM_PWMConfigure;
|
|
||||||
|
|
||||||
ADC_InitTypeDef ADC_InitStructure;
|
|
||||||
DMA_InitTypeDef DMA_BAT_InitStructure;
|
DMA_InitTypeDef DMA_BAT_InitStructure;
|
||||||
__IO uint16_t ADCConvertedValue[VOLTAGE_BUFFER_SIZE];
|
uint16_t ADCConvertedValue[VOLTAGE_BUFFER_SIZE];
|
||||||
|
|
||||||
|
char cptMesureHigh=0;
|
||||||
|
char cptMesureLow=0;
|
||||||
|
char cptMesureDisable=0;
|
||||||
|
|
||||||
|
uint16_t vbatLowerVal;
|
||||||
|
uint16_t vbatHighVal;
|
||||||
|
uint16_t vbatDiff;
|
||||||
|
|
||||||
|
uint16_t testPostion=0;
|
||||||
|
uint32_t mesureVoltage;
|
||||||
|
uint32_t meanVoltage;
|
||||||
|
|
||||||
|
uint32_t cptMesureEmergencyHalt=0;
|
||||||
|
|
||||||
/** @addtogroup Projects
|
/** @addtogroup Projects
|
||||||
* @{
|
* @{
|
||||||
|
@ -42,11 +47,11 @@ __IO uint16_t ADCConvertedValue[VOLTAGE_BUFFER_SIZE];
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Definis les GPIO necessaires pour la batterie.
|
* @brief Défini les GPIO nécessaires pour la batterie.
|
||||||
*
|
*
|
||||||
* La fonction MAP_MotorPin va venir configurer le E/S du GPIO pour correspondre avec
|
* La fonction MAP_MotorPin va venir configurer le E/S du GPIO pour correspondre avec
|
||||||
* le sch<EFBFBD>ma electrique en ressource. La fonction initialise aussi l'interruption EXTI
|
* le schéma electrique en ressource. La fonction initialise aussi l'interruption EXTI
|
||||||
* de la d<EFBFBD>tection du chargeur.
|
* de la détection du chargeur.
|
||||||
*
|
*
|
||||||
* @note A3 en output alternate function.
|
* @note A3 en output alternate function.
|
||||||
* A0 et A4 en floating input.
|
* A0 et A4 en floating input.
|
||||||
|
@ -57,11 +62,12 @@ __IO uint16_t ADCConvertedValue[VOLTAGE_BUFFER_SIZE];
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void MAP_batteryPin(void)
|
void batteryConfigure(void)
|
||||||
{
|
{
|
||||||
GPIO_InitTypeDef Init_Structure;
|
GPIO_InitTypeDef Init_Structure;
|
||||||
NVIC_InitTypeDef NVIC_InitStructure;
|
NVIC_InitTypeDef NVIC_InitStructure;
|
||||||
EXTI_InitTypeDef EXTI_InitStructure;
|
EXTI_InitTypeDef EXTI_InitStructure;
|
||||||
|
ADC_InitTypeDef ADC_InitStructure;
|
||||||
|
|
||||||
Init_Structure.GPIO_Pin = GPIO_Pin_3;
|
Init_Structure.GPIO_Pin = GPIO_Pin_3;
|
||||||
Init_Structure.GPIO_Speed = GPIO_Speed_10MHz;
|
Init_Structure.GPIO_Speed = GPIO_Speed_10MHz;
|
||||||
|
@ -91,20 +97,9 @@ void MAP_batteryPin(void)
|
||||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||||
NVIC_Init(&NVIC_InitStructure);
|
NVIC_Init(&NVIC_InitStructure);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// Initialise la dma pour stocker les valeur dans ADCConvertedValue.
|
||||||
* @brief Initialise la dma pour stocker les valeur dans ADCConvertedValue.
|
|
||||||
* On stockera 16 valeurs de fa<EFBFBD>on <EFBFBD> faire un moyennage.
|
|
||||||
*
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
void DMA_BAT(void)
|
|
||||||
{
|
|
||||||
/* DMA1 channel1 configuration ----------------------------------------------*/
|
|
||||||
DMA_DeInit(DMA1_Channel1);
|
DMA_DeInit(DMA1_Channel1);
|
||||||
DMA_BAT_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(ADC1->DR); // ADC1_DR_Address;
|
DMA_BAT_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(ADC1->DR); // ADC1_DR_Address;
|
||||||
DMA_BAT_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADCConvertedValue;
|
DMA_BAT_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADCConvertedValue;
|
||||||
|
@ -121,70 +116,8 @@ void DMA_BAT(void)
|
||||||
|
|
||||||
DMA_Cmd(DMA1_Channel1, ENABLE);
|
DMA_Cmd(DMA1_Channel1, ENABLE);
|
||||||
DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);
|
DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// Configuration et Calibration de l'ADC1 sur 1 channel.
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @addtogroup Lancer_acquisition
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
/**
|
|
||||||
* @brief Demarrage des Acquisitions de la DMA.
|
|
||||||
*
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
void startACQDMA(void)
|
|
||||||
{
|
|
||||||
ADC_DMACmd(ADC1, ENABLE);
|
|
||||||
DMA_DeInit(DMA1_Channel1);
|
|
||||||
DMA_Init(DMA1_Channel1, &DMA_BAT_InitStructure);
|
|
||||||
DMA_Cmd(DMA1_Channel1, ENABLE);
|
|
||||||
DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Fonction de plus haut niveau qui initialisera la DMA et qui lancera une nouvelle acquisition.
|
|
||||||
* Cette fonction est appell<EFBFBD> <EFBFBD> interval r<EFBFBD>gulier dans le systick. Cette fonction utilise startACQDMA.
|
|
||||||
*
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
void voltagePrepare(void)
|
|
||||||
{
|
|
||||||
DMA_BAT_InitStructure.DMA_BufferSize = VOLTAGE_BUFFER_SIZE;
|
|
||||||
|
|
||||||
ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 1, ADC_SampleTime_55Cycles5);
|
|
||||||
ADC_Cmd(ADC1, ENABLE);
|
|
||||||
startACQDMA();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/** @addtogroup Init_GPIO_DMA_IT_Battery
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Configuration et Calibration de l'ADC1 sur 1 channel.
|
|
||||||
* L'adc lira en mode continue.
|
|
||||||
*
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
void ADC1_CONFIG(void)
|
|
||||||
{
|
|
||||||
/* ADC1 configuration ------------------------------------------------------*/
|
|
||||||
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
|
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
|
||||||
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
|
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
|
||||||
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
|
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
|
||||||
|
@ -204,21 +137,8 @@ void ADC1_CONFIG(void)
|
||||||
while(ADC_GetCalibrationStatus(ADC1));
|
while(ADC_GetCalibrationStatus(ADC1));
|
||||||
|
|
||||||
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
|
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/* Enable the ADC1 DMA Interrupt */
|
||||||
* @brief Initialise l'interruption <EFBFBD> la fin des acquisitions sur la DMA.
|
|
||||||
*
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
void INIT_IT_DMA(void)
|
|
||||||
{
|
|
||||||
NVIC_InitTypeDef NVIC_InitStructure;
|
|
||||||
|
|
||||||
/* Enable the USARTz Interrupt */
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;
|
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;
|
||||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
|
||||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||||
|
@ -230,6 +150,119 @@ void INIT_IT_DMA(void)
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/** @addtogroup Lancer_acquisition
|
||||||
|
* @{
|
||||||
|
*/
|
||||||
|
/**
|
||||||
|
* @brief Demarrage des Acquisitions de la DMA.
|
||||||
|
*
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void batteryStartAcquisition(void)
|
||||||
|
{
|
||||||
|
ADC_DMACmd(ADC1, ENABLE);
|
||||||
|
DMA_DeInit(DMA1_Channel1);
|
||||||
|
DMA_Init(DMA1_Channel1, &DMA_BAT_InitStructure);
|
||||||
|
DMA_Cmd(DMA1_Channel1, ENABLE);
|
||||||
|
DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Fonction de plus haut niveau qui initialisera la DMA et qui lancera une nouvelle acquisition.
|
||||||
|
* Cette fonction est appelée à intervalle régulier dans le systick. Cette fonction utilise startACQDMA.
|
||||||
|
*
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
void batteryRefreshData(void)
|
||||||
|
{
|
||||||
|
DMA_BAT_InitStructure.DMA_BufferSize = VOLTAGE_BUFFER_SIZE;
|
||||||
|
|
||||||
|
ADC_RegularChannelConfig(ADC1, ADC_Channel_4, 1, ADC_SampleTime_55Cycles5);
|
||||||
|
ADC_Cmd(ADC1, ENABLE);
|
||||||
|
batteryStartAcquisition();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Appelé de manière régulière pour mettre à jour le niveau batterie
|
||||||
|
*
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void batteryManagement(void) {
|
||||||
|
int k;
|
||||||
|
|
||||||
|
if(Dumber.acquisition==VOLTAGE && Dumber.BatterieChecking==TRUE) {
|
||||||
|
vbatLowerVal = 0xFFF;
|
||||||
|
vbatHighVal = 0;
|
||||||
|
|
||||||
|
for(k=0; k<VOLTAGE_BUFFER_SIZE; k++)
|
||||||
|
{
|
||||||
|
meanVoltage+=ADCConvertedValue[k];
|
||||||
|
|
||||||
|
if (vbatLowerVal> ADCConvertedValue[k]) vbatLowerVal = ADCConvertedValue[k];
|
||||||
|
if (vbatHighVal< ADCConvertedValue[k]) vbatHighVal = ADCConvertedValue[k];
|
||||||
|
}
|
||||||
|
|
||||||
|
vbatDiff = vbatHighVal - vbatLowerVal;
|
||||||
|
|
||||||
|
meanVoltage= meanVoltage/VOLTAGE_BUFFER_SIZE;
|
||||||
|
mesureVoltage = meanVoltage;
|
||||||
|
|
||||||
|
Dumber.BatteryPercentage = mesureVoltage;
|
||||||
|
Dumber.acquisition=FALSE;
|
||||||
|
|
||||||
|
if(Dumber.BatteryPercentage >= VBAT_SEUIL_LOW)
|
||||||
|
{
|
||||||
|
cptMesureHigh++;
|
||||||
|
if(cptMesureHigh >= COMPTEUR_SEUIL_HIGH)
|
||||||
|
{
|
||||||
|
if(Dumber.StateSystem == STATE_LOW)
|
||||||
|
systemChangeState(STATE_RUN);
|
||||||
|
|
||||||
|
Dumber.stateBattery = 2;
|
||||||
|
cptMesureHigh=0;
|
||||||
|
cptMesureLow=0;
|
||||||
|
cptMesureDisable=0;
|
||||||
|
cptMesureEmergencyHalt=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (Dumber.BatteryPercentage < VBAT_SEUIL_LOW && Dumber.BatteryPercentage >= VBAT_SEUIL_DISABLE)
|
||||||
|
{
|
||||||
|
cptMesureLow++;
|
||||||
|
if(cptMesureLow >= COMPTEUR_SEUIL_LOW)
|
||||||
|
{
|
||||||
|
if(Dumber.StateSystem == STATE_RUN)
|
||||||
|
systemChangeState(STATE_LOW);
|
||||||
|
|
||||||
|
Dumber.stateBattery =1;
|
||||||
|
cptMesureHigh=0;
|
||||||
|
cptMesureLow=0;
|
||||||
|
cptMesureDisable=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else // Dumber.BatteryPercentage < VBAT_SEUIL_DISABLE
|
||||||
|
{
|
||||||
|
cptMesureDisable++;
|
||||||
|
|
||||||
|
if(cptMesureDisable >= COMPTEUR_SEUIL_DISABLE)
|
||||||
|
{
|
||||||
|
systemChangeState(STATE_DISABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @}
|
||||||
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @addtogroup Handler
|
/** @addtogroup Handler
|
||||||
* @{
|
* @{
|
||||||
|
@ -237,8 +270,8 @@ void INIT_IT_DMA(void)
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Interruption Handler. Qui va faire la moyenne des derni<EFBFBD>res
|
* @brief Interruption Handler. Qui va faire la moyenne des dernières
|
||||||
* acquisitions lorsque la DMA <EFBFBD> rempli son buffer.
|
* acquisitions lorsque la DMA à rempli son buffer.
|
||||||
*
|
*
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
|
@ -256,8 +289,8 @@ void DMA1_Channel1_IRQHandler(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Interruption qui donne l'ordre d'<EFBFBD>teindre le robot.
|
* @brief Interruption qui donne l'ordre d'éteindre le robot.
|
||||||
* L'IT se d<EFBFBD>clenche lorsque le chargeur est branch<EFBFBD>.
|
* L'IT se déclenche lorsque le chargeur est branché.
|
||||||
*
|
*
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
|
@ -265,7 +298,7 @@ void DMA1_Channel1_IRQHandler(void)
|
||||||
*/
|
*/
|
||||||
void EXTI15_10_IRQHandler(void)
|
void EXTI15_10_IRQHandler(void)
|
||||||
{
|
{
|
||||||
shutDown();
|
systemShutDown();
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,24 +14,40 @@
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef Battery_H
|
#ifndef _BATTERY_H_
|
||||||
#define Battery_H
|
#define _BATTERY_H_
|
||||||
|
|
||||||
#include "stm32f10x.h"
|
#include "stm32f10x.h"
|
||||||
|
|
||||||
#define VOLTAGE_BUFFER_SIZE 64
|
#define VOLTAGE_BUFFER_SIZE 64
|
||||||
extern __IO uint16_t ADCConvertedValue[VOLTAGE_BUFFER_SIZE];
|
|
||||||
|
|
||||||
#define VBAT_SEUIL_LOW 0x878
|
#define VBAT_SEUIL_LOW 0x878
|
||||||
#define VBAT_SEUIL_DISABLE 0x7CA
|
#define VBAT_SEUIL_DISABLE 0x7CA
|
||||||
#define VBAT_SEUIL_EMERGENCY_HALT 0x6E0
|
#define VBAT_SEUIL_EMERGENCY_HALT 0x6E0
|
||||||
|
|
||||||
void MAP_batteryPin(void);
|
#define COMPTEUR_SEUIL_HIGH 8
|
||||||
void DMA_BAT(void);
|
#define COMPTEUR_SEUIL_LOW 8
|
||||||
void ADC1_CONFIG(void);
|
#define COMPTEUR_SEUIL_DISABLE 8
|
||||||
void INIT_IT_DMA(void);
|
#define COMPTEUR_SEUIL_EMERGENCY_HALT 3000
|
||||||
void startACQDMA(void);
|
|
||||||
void voltagePrepare(void);
|
|
||||||
|
|
||||||
#endif /* Battery_H */
|
extern char cptMesureHigh;
|
||||||
|
extern char cptMesureLow;
|
||||||
|
extern char cptMesureDisable;
|
||||||
|
|
||||||
|
extern uint16_t vbatLowerVal;
|
||||||
|
extern uint16_t vbatHighVal;
|
||||||
|
extern uint16_t vbatDiff;
|
||||||
|
|
||||||
|
extern uint16_t testPostion;
|
||||||
|
extern uint32_t mesureVoltage;
|
||||||
|
extern uint32_t meanVoltage;
|
||||||
|
|
||||||
|
extern uint32_t cptMesureEmergencyHalt;
|
||||||
|
|
||||||
|
void batteryConfigure(void);
|
||||||
|
void batteryManagement(void);
|
||||||
|
void batteryStartAcquisition(void);
|
||||||
|
void batteryRefreshData(void);
|
||||||
|
|
||||||
|
#endif /* _BATTERY_H_ */
|
||||||
|
|
||||||
|
|
|
@ -16,17 +16,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stm32f10x.h>
|
#include <stm32f10x.h>
|
||||||
|
|
||||||
#include "cmdManager.h"
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "cmde_usart.h"
|
#include "cmdManager.h"
|
||||||
#include "battery.h"
|
#include "battery.h"
|
||||||
#include "motor.h"
|
#include "motor.h"
|
||||||
#include "system_dumby.h"
|
#include "system_dumby.h"
|
||||||
|
#include "usart.h"
|
||||||
|
|
||||||
/** @addtogroup Projects
|
/** @addtogroup Projects
|
||||||
* @{
|
* @{
|
||||||
|
@ -36,9 +34,28 @@
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
volatile unsigned char checksum;
|
/* Definition des commandes */
|
||||||
volatile int length;
|
|
||||||
uint16_t j;
|
#define PingCMD 'p'
|
||||||
|
#define ResetCMD 'r'
|
||||||
|
#define SetMotorCMD 'm'
|
||||||
|
#define StartWWatchDogCMD 'W'
|
||||||
|
#define ResetWatchdogCMD 'w'
|
||||||
|
#define GetBatteryVoltageCMD 'v'
|
||||||
|
#define GetVersionCMD 'V'
|
||||||
|
#define StartWithoutWatchCMD 'u'
|
||||||
|
#define MoveCMD 'M'
|
||||||
|
#define TurnCMD 'T'
|
||||||
|
#define BusyStateCMD 'b'
|
||||||
|
#define TestCMD 't'
|
||||||
|
#define DebugCMD 'a'
|
||||||
|
|
||||||
|
#define OK_ANS "O\r"
|
||||||
|
#define ERR_ANS "E\r"
|
||||||
|
#define UNKNOW_ANS "C\r"
|
||||||
|
#define BAT_OK "2\r"
|
||||||
|
#define BAT_LOW "1\r"
|
||||||
|
#define BAT_EMPTY "0\r"
|
||||||
|
|
||||||
/** @addtogroup Checksum
|
/** @addtogroup Checksum
|
||||||
* @{
|
* @{
|
||||||
|
@ -53,8 +70,10 @@ uint16_t j;
|
||||||
* @retval 0 ou 1
|
* @retval 0 ou 1
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void inclusionCheckSum(void) {
|
void cmdAddChecksum(void) {
|
||||||
checksum = 0;
|
uint16_t j;
|
||||||
|
unsigned char checksum=0;
|
||||||
|
|
||||||
for (j = 0; sendString[j] != '\r'; j++)
|
for (j = 0; sendString[j] != '\r'; j++)
|
||||||
checksum ^= sendString[j];
|
checksum ^= sendString[j];
|
||||||
if (checksum == '\r')
|
if (checksum == '\r')
|
||||||
|
@ -73,20 +92,23 @@ void inclusionCheckSum(void) {
|
||||||
* @retval 0 ou 1
|
* @retval 0 ou 1
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
char verifyCheckSum(void) {
|
char cmdVerifyChecksum(void) {
|
||||||
uint16_t j, lenght;
|
uint16_t j;
|
||||||
checksum = 0;
|
uint16_t length;
|
||||||
lenght = strlen(receiptString);
|
unsigned char checksum=0;
|
||||||
for (j = 0; j < lenght - 2; j++) {
|
|
||||||
|
length = strlen(receiptString);
|
||||||
|
for (j = 0; j < length - 2; j++) {
|
||||||
checksum ^= receiptString[j];
|
checksum ^= receiptString[j];
|
||||||
}
|
}
|
||||||
if (checksum == '\r')
|
if (checksum == '\r')
|
||||||
checksum++;
|
checksum++;
|
||||||
|
|
||||||
if (receiptString[j] == checksum) {
|
if (receiptString[j] == checksum) {
|
||||||
receiptString[lenght - 2] = 13;
|
receiptString[length - 2] = 13;
|
||||||
receiptString[lenght - 1] = 0;
|
receiptString[length - 1] = 0;
|
||||||
receiptString[lenght] = 0;
|
receiptString[length] = 0;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
} else
|
} else
|
||||||
return 1;
|
return 1;
|
||||||
|
@ -112,55 +134,65 @@ char verifyCheckSum(void) {
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void manageCmd(void) {
|
void cmdManage(void) {
|
||||||
|
if (cmdVerifyChecksum() != 0) {
|
||||||
|
strcpy(sendString, UNKNOW_ANS);
|
||||||
|
} else { // Checksum valide
|
||||||
|
if (Dumber.StateSystem==STATE_DISABLE) { // SI la batterie est trop faible, impossible d'accepter une commande: on reste dans ce mode
|
||||||
|
strcpy(sendString, ERR_ANS);
|
||||||
|
} else {
|
||||||
switch (receiptString[0]) {
|
switch (receiptString[0]) {
|
||||||
case PingCMD:
|
case PingCMD:
|
||||||
actionPing();
|
cmdPingAction();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ResetCMD:
|
case ResetCMD:
|
||||||
actionReset();
|
cmdResetAction();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case StartWWatchDogCMD:
|
case StartWWatchDogCMD:
|
||||||
actionStartWithWD();
|
cmdStartWithWatchdogAction();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ResetWatchdogCMD:
|
case ResetWatchdogCMD:
|
||||||
actionResetWD();
|
cmdResetWatchdogAction();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GetBatteryVoltageCMD:
|
case GetBatteryVoltageCMD:
|
||||||
actionBatteryVoltage();
|
cmdBatteryVoltageAction();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case GetVersionCMD:
|
case GetVersionCMD:
|
||||||
actionVersion();
|
cmdVersionAction();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case StartWithoutWatchCMD:
|
case StartWithoutWatchCMD:
|
||||||
actionStartWWD();
|
cmdStartWithoutWatchdogAction();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MoveCMD:
|
case MoveCMD:
|
||||||
actionMove();
|
cmdMoveAction();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case TurnCMD:
|
case TurnCMD:
|
||||||
actionTurn();
|
cmdTurnAction();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BusyStateCMD:
|
case BusyStateCMD:
|
||||||
actionBusyState();
|
cmdBusyStateAction();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'a':
|
case 'a':
|
||||||
actionDebug();
|
cmdDebugAction();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
strcpy(sendString, UNKNOW_ANS);
|
strcpy(sendString, UNKNOW_ANS);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Dumber.cpt_inactivity=0; // remise a zéro du compteur d'inativité
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -179,8 +211,8 @@ void manageCmd(void) {
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void actionPing(void) {
|
void cmdPingAction(void) {
|
||||||
if (receiptString[1] == 13)
|
if (receiptString[1] == '\r')
|
||||||
strcpy(sendString, OK_ANS);
|
strcpy(sendString, OK_ANS);
|
||||||
else
|
else
|
||||||
strcpy(sendString, ERR_ANS);
|
strcpy(sendString, ERR_ANS);
|
||||||
|
@ -194,13 +226,8 @@ void actionPing(void) {
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void actionReset(void) {
|
void cmdResetAction(void) {
|
||||||
Dumber.StateSystem = IDLE;
|
systemChangeState(STATE_IDLE);
|
||||||
Dumber.WatchDogStartEnable = TRUE;
|
|
||||||
Dumber.cpt_watchdog = 0;
|
|
||||||
Dumber.cpt_systick = 0;
|
|
||||||
cmdLeftMotor(BRAKE, 0);
|
|
||||||
cmdRightMotor(BRAKE, 0);
|
|
||||||
strcpy(sendString, OK_ANS);
|
strcpy(sendString, OK_ANS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -210,8 +237,8 @@ void actionReset(void) {
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void actionVersion(void) {
|
void cmdVersionAction(void) {
|
||||||
if (receiptString[1] == 13)
|
if (receiptString[1] == '\r')
|
||||||
strcpy(sendString, VERSION);
|
strcpy(sendString, VERSION);
|
||||||
else
|
else
|
||||||
strcpy(sendString, ERR_ANS);
|
strcpy(sendString, ERR_ANS);
|
||||||
|
@ -225,30 +252,27 @@ void actionVersion(void) {
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void actionBusyState(void) {
|
void cmdBusyStateAction(void) {
|
||||||
if (Dumber.StateSystem == RUN || Dumber.StateSystem == LOW) {
|
if ((Dumber.StateSystem == STATE_RUN) || (Dumber.StateSystem == STATE_LOW)) {
|
||||||
if (Dumber.busyState == TRUE)
|
if (Dumber.busyState == TRUE)
|
||||||
strcpy(sendString, "1");
|
strcpy(sendString, "1\r");
|
||||||
else
|
else
|
||||||
strcpy(sendString, "0");
|
strcpy(sendString, "0\r");
|
||||||
} else {
|
} else {
|
||||||
strcpy(sendString, ERR_ANS);
|
strcpy(sendString, ERR_ANS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Effectue une remise à zero du watchdog.
|
* @brief Effectue une remise à zéro du watchdog.
|
||||||
*
|
*
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void actionResetWD(void) {
|
void cmdResetWatchdogAction(void) {
|
||||||
if (Dumber.StateSystem == RUN && watchDogState==TRUE){
|
if (systemResetWatchdog()!=0) { // Réussite
|
||||||
Dumber.cpt_watchdog = 0;
|
|
||||||
strcpy(sendString, OK_ANS);
|
strcpy(sendString, OK_ANS);
|
||||||
}
|
} else strcpy(sendString, ERR_ANS);
|
||||||
else
|
|
||||||
strcpy(sendString, ERR_ANS);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -260,11 +284,11 @@ void actionResetWD(void) {
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void actionStartWithWD(void) {
|
void cmdStartWithWatchdogAction(void) {
|
||||||
if (Dumber.StateSystem == IDLE && receiptString[1] == 13) {
|
if (Dumber.StateSystem == STATE_IDLE && receiptString[1] == '\r') {
|
||||||
strcpy(sendString, OK_ANS);
|
|
||||||
Dumber.WatchDogStartEnable = TRUE;
|
Dumber.WatchDogStartEnable = TRUE;
|
||||||
Dumber.StateSystem = RUN;
|
systemChangeState(STATE_RUN);
|
||||||
|
strcpy(sendString, OK_ANS);
|
||||||
} else
|
} else
|
||||||
strcpy(sendString, ERR_ANS);
|
strcpy(sendString, ERR_ANS);
|
||||||
}
|
}
|
||||||
|
@ -276,11 +300,11 @@ void actionStartWithWD(void) {
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void actionStartWWD(void) {
|
void cmdStartWithoutWatchdogAction(void) {
|
||||||
if (Dumber.StateSystem == IDLE && receiptString[1] == 13) {
|
if (Dumber.StateSystem == STATE_IDLE && receiptString[1] == '\r') {
|
||||||
strcpy(sendString, OK_ANS);
|
|
||||||
Dumber.WatchDogStartEnable = FALSE;
|
Dumber.WatchDogStartEnable = FALSE;
|
||||||
Dumber.StateSystem = RUN;
|
systemChangeState(STATE_RUN);
|
||||||
|
strcpy(sendString, OK_ANS);
|
||||||
} else
|
} else
|
||||||
strcpy(sendString, ERR_ANS);
|
strcpy(sendString, ERR_ANS);
|
||||||
}
|
}
|
||||||
|
@ -295,8 +319,8 @@ void actionStartWWD(void) {
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void actionMove(void) {
|
void cmdMoveAction(void) {
|
||||||
if (Dumber.StateSystem == RUN || Dumber.StateSystem == LOW) {
|
if (Dumber.StateSystem == STATE_RUN || Dumber.StateSystem == STATE_LOW) {
|
||||||
int laps;
|
int laps;
|
||||||
uint16_t testReception = sscanf(receiptString, "M=%i\r", &laps);
|
uint16_t testReception = sscanf(receiptString, "M=%i\r", &laps);
|
||||||
unsigned char mod = 0;
|
unsigned char mod = 0;
|
||||||
|
@ -313,8 +337,10 @@ void actionMove(void) {
|
||||||
mod = FORWARD;
|
mod = FORWARD;
|
||||||
|
|
||||||
laps = laps * 2;
|
laps = laps * 2;
|
||||||
regulationMoteur(mod, mod, (unsigned) laps, (unsigned) laps,
|
|
||||||
|
motorRegulation(mod, mod, (unsigned) laps, (unsigned) laps,
|
||||||
COMMONSPEED, COMMONSPEED);
|
COMMONSPEED, COMMONSPEED);
|
||||||
|
|
||||||
strcpy(sendString, OK_ANS);
|
strcpy(sendString, OK_ANS);
|
||||||
} else
|
} else
|
||||||
strcpy(sendString, ERR_ANS);
|
strcpy(sendString, ERR_ANS);
|
||||||
|
@ -322,39 +348,34 @@ void actionMove(void) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Execute une action tourne avec les paramétres dans receitpString.
|
* @brief Execute une action tourne avec les paramètres dans receitpString.
|
||||||
* Type de commande à envoyer : "T=val\r". Ou val peut être positif
|
* Type de commande à envoyer : "T=val\r". Ou val peut être positif
|
||||||
* ou negatif.
|
* ou negatif.
|
||||||
*
|
*
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void actionTurn(void) {
|
void cmdTurnAction(void) {
|
||||||
if (Dumber.StateSystem == RUN || Dumber.StateSystem == LOW) {
|
if (Dumber.StateSystem == STATE_RUN || Dumber.StateSystem == STATE_LOW) {
|
||||||
int degree;
|
int degree;
|
||||||
uint16_t testReception = sscanf(receiptString, "T=%i\r", °ree);
|
uint16_t testReception = sscanf(receiptString, "T=%i\r", °ree);
|
||||||
tourPositionG = 0;
|
tourPositionG = 0;
|
||||||
tourPositionD = 0;
|
tourPositionD = 0;
|
||||||
|
|
||||||
if (testReception == 1) {
|
if (testReception == 1) {
|
||||||
degree = degree * 1.40;
|
degree = degree * 1.40;
|
||||||
Dumber.cpt_inactivity = 0;
|
Dumber.cpt_inactivity = 0;
|
||||||
Dumber.busyState = TRUE;
|
Dumber.busyState = TRUE;
|
||||||
|
|
||||||
if (degree < 0) {
|
if (degree < 0) {
|
||||||
degree = degree * -1;
|
degree = degree * -1;
|
||||||
if (degree < 30)
|
motorRegulation(FORWARD, REVERSE, (unsigned) degree,
|
||||||
regulationMoteur(FORWARD, REVERSE, (unsigned) degree,
|
|
||||||
(unsigned) degree, LOWSPEED, LOWSPEED);
|
(unsigned) degree, LOWSPEED, LOWSPEED);
|
||||||
else
|
|
||||||
regulationMoteur(FORWARD, REVERSE, (unsigned) degree,
|
|
||||||
(unsigned) degree, COMMONSPEED, COMMONSPEED);
|
|
||||||
} else {
|
} else {
|
||||||
if (degree < 30)
|
motorRegulation(REVERSE, FORWARD, (unsigned) degree,
|
||||||
regulationMoteur(REVERSE, FORWARD, (unsigned) degree,
|
|
||||||
(unsigned) degree, LOWSPEED, LOWSPEED);
|
(unsigned) degree, LOWSPEED, LOWSPEED);
|
||||||
else
|
|
||||||
regulationMoteur(REVERSE, FORWARD, (unsigned) degree,
|
|
||||||
(unsigned) degree, COMMONSPEED, COMMONSPEED);
|
|
||||||
}
|
}
|
||||||
|
strcpy(sendString, OK_ANS);
|
||||||
} else
|
} else
|
||||||
strcpy(sendString, ERR_ANS);
|
strcpy(sendString, ERR_ANS);
|
||||||
}
|
}
|
||||||
|
@ -370,7 +391,7 @@ void actionTurn(void) {
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void actionBatteryVoltage(void) {
|
void cmdBatteryVoltageAction(void) {
|
||||||
char battery[2];
|
char battery[2];
|
||||||
battery[0] = Dumber.stateBattery + '0';
|
battery[0] = Dumber.stateBattery + '0';
|
||||||
battery[1] = '\r';
|
battery[1] = '\r';
|
||||||
|
@ -386,12 +407,15 @@ void actionBatteryVoltage(void) {
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void actionDebug(void) {
|
void cmdDebugAction(void) {
|
||||||
|
uint8_t j;
|
||||||
|
|
||||||
sprintf(sendString, "Th-D=%u G=%u\r", tourPositionD, tourPositionG);
|
sprintf(sendString, "Th-D=%u G=%u\r", tourPositionD, tourPositionG);
|
||||||
sendDataUSART();
|
usartSendData();
|
||||||
|
|
||||||
for (j = 0; j < 200; j++);
|
for (j = 0; j < 200; j++);
|
||||||
sprintf(sendString, "Re-D=%u G=%u\r", G_lapsRight, G_lapsLeft);
|
sprintf(sendString, "Re-D=%u G=%u\r", G_lapsRight, G_lapsLeft);
|
||||||
sendDataUSART();
|
usartSendData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -6,35 +6,35 @@
|
||||||
* @date 19-June-2017
|
* @date 19-June-2017
|
||||||
* @brief Gestion de commande reçu via l'uart
|
* @brief Gestion de commande reçu via l'uart
|
||||||
*
|
*
|
||||||
* Traite les chaines de caractére reçu par l'uart.
|
* Traite les chaînes de caractère reçu par l'uart.
|
||||||
* Permet de verifier les erreurs de checksum,
|
* Permet de vérifier les erreurs de checksum,
|
||||||
* de traiter les valeurs retours.
|
* de traiter les valeurs retours.
|
||||||
*
|
*
|
||||||
*@attention Utilise les variables globals - receiptString - sendString
|
* @attention Utilise les variables globales - receiptString - sendString
|
||||||
*
|
*
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef CMD_MANAGER_H_
|
#ifndef _CMD_MANAGER_H_
|
||||||
#define CMD_MANAGER_H_
|
#define _CMD_MANAGER_H_
|
||||||
|
|
||||||
#include <stm32f10x.h>
|
#include <stm32f10x.h>
|
||||||
|
|
||||||
void manageCmd(void);
|
void cmdManage(void);
|
||||||
char verifyCheckSum(void);
|
char cmdVerifyChecksum(void);
|
||||||
void inclusionCheckSum(void);
|
void cmdAddChecksum(void);
|
||||||
void actionReset(void);
|
void cmdResetAction(void);
|
||||||
void actionBusyState(void);
|
void cmdBusyStateAction(void);
|
||||||
void actionPing(void);
|
void cmdPingAction(void);
|
||||||
void actionVersion(void);
|
void cmdVersionAction(void);
|
||||||
void actionStartWWD(void);
|
void cmdStartWithoutWatchdogAction(void);
|
||||||
void actionMove(void);
|
void cmdMoveAction(void);
|
||||||
void actionTurn(void);
|
void cmdTurnAction(void);
|
||||||
void actionBatteryVoltage(void);
|
void cmdBatteryVoltageAction(void);
|
||||||
void actionStartWithWD(void);
|
void cmdStartWithWatchdogAction(void);
|
||||||
void actionResetWD(void);
|
void cmdResetWatchdogAction(void);
|
||||||
void actionDebug(void);
|
void cmdDebugAction(void);
|
||||||
|
|
||||||
#endif /* CMD_MANAGER_H_ */
|
#endif /* _CMD_MANAGER_H_ */
|
||||||
|
|
||||||
|
|
|
@ -11,11 +11,12 @@
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "stm32f10x.h" // Device header
|
#include <stm32f10x.h> // Device header
|
||||||
#include "debug.h"
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
/** @addtogroup Projects
|
/** @addtogroup Projects
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -13,9 +13,8 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stm32f10x.h>
|
#include <stm32f10x.h>
|
||||||
#include "led.h"
|
|
||||||
|
|
||||||
#include "system_dumby.h"
|
#include "system_dumby.h"
|
||||||
|
#include "led.h"
|
||||||
|
|
||||||
/** @addtogroup Projects
|
/** @addtogroup Projects
|
||||||
* @{
|
* @{
|
||||||
|
@ -33,12 +32,23 @@
|
||||||
|
|
||||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseLED;
|
TIM_TimeBaseInitTypeDef TIM_TimeBaseLED;
|
||||||
TIM_OCInitTypeDef TIM_OCConfigure;
|
TIM_OCInitTypeDef TIM_OCConfigure;
|
||||||
|
char etatLED;
|
||||||
|
char LEDON;
|
||||||
|
|
||||||
|
#define LED_GREEN 0
|
||||||
|
#define LED_RED 1
|
||||||
|
#define LED_ORANGE 2
|
||||||
|
|
||||||
|
/*void ledGreenOn(void);
|
||||||
|
void ledRedOn(void);
|
||||||
|
void ledOff(void);
|
||||||
|
void ledOrangeOn(void);*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Configure le GPIO PB0 et PB1 afin de contr<EFBFBD>ler la led.
|
* @brief Configure le GPIO PB0 et PB1 afin de contrôler la led.
|
||||||
* @param Aucun
|
* @param Aucun
|
||||||
*/
|
*/
|
||||||
void MAP_LEDpin(void)
|
void ledConfigure(void)
|
||||||
{
|
{
|
||||||
GPIO_InitTypeDef Init_Structure;
|
GPIO_InitTypeDef Init_Structure;
|
||||||
|
|
||||||
|
@ -47,6 +57,9 @@ void MAP_LEDpin(void)
|
||||||
Init_Structure.GPIO_Speed = GPIO_Speed_50MHz;
|
Init_Structure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||||
Init_Structure.GPIO_Mode = GPIO_Mode_Out_PP;
|
Init_Structure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||||
GPIO_Init(GPIOB, &Init_Structure);
|
GPIO_Init(GPIOB, &Init_Structure);
|
||||||
|
|
||||||
|
etatLED = 1;
|
||||||
|
LEDON =0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,7 +73,7 @@ void MAP_LEDpin(void)
|
||||||
* @brief Allume une LED de couleur orange.
|
* @brief Allume une LED de couleur orange.
|
||||||
* @param Aucun
|
* @param Aucun
|
||||||
*/
|
*/
|
||||||
void LEDorange(void)
|
void ledOrangeOn(void)
|
||||||
{
|
{
|
||||||
GPIO_SetBits(GPIOB, GPIO_Pin_1);
|
GPIO_SetBits(GPIOB, GPIO_Pin_1);
|
||||||
GPIO_SetBits(GPIOB,GPIO_Pin_0);
|
GPIO_SetBits(GPIOB,GPIO_Pin_0);
|
||||||
|
@ -70,7 +83,7 @@ void LEDorange(void)
|
||||||
* @brief Allume une LED de couleur rouge.
|
* @brief Allume une LED de couleur rouge.
|
||||||
* @param Aucun
|
* @param Aucun
|
||||||
*/
|
*/
|
||||||
void LEDred(void)
|
void ledRedOn(void)
|
||||||
{
|
{
|
||||||
GPIO_ResetBits(GPIOB, GPIO_Pin_1);
|
GPIO_ResetBits(GPIOB, GPIO_Pin_1);
|
||||||
GPIO_SetBits(GPIOB,GPIO_Pin_0);
|
GPIO_SetBits(GPIOB,GPIO_Pin_0);
|
||||||
|
@ -80,7 +93,7 @@ void LEDred(void)
|
||||||
* @brief Allume une LED de couleur verte.
|
* @brief Allume une LED de couleur verte.
|
||||||
* @param Aucun
|
* @param Aucun
|
||||||
*/
|
*/
|
||||||
void LEDgreen(void)
|
void ledGreenOn(void)
|
||||||
{
|
{
|
||||||
|
|
||||||
GPIO_SetBits(GPIOB, GPIO_Pin_1);
|
GPIO_SetBits(GPIOB, GPIO_Pin_1);
|
||||||
|
@ -88,15 +101,106 @@ void LEDgreen(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Eteint la LED.
|
* @brief Eteint les LED.
|
||||||
* @param Aucun
|
* @param Aucun
|
||||||
*/
|
*/
|
||||||
void LEDoff(void)
|
void ledOff(void)
|
||||||
{
|
{
|
||||||
GPIO_ResetBits(GPIOB,GPIO_Pin_0);
|
GPIO_ResetBits(GPIOB,GPIO_Pin_0);
|
||||||
GPIO_ResetBits(GPIOB,GPIO_Pin_1);
|
GPIO_ResetBits(GPIOB,GPIO_Pin_1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Allume une couleur de LED.
|
||||||
|
* @param Aucun
|
||||||
|
*/
|
||||||
|
void ledOn(char color)
|
||||||
|
{
|
||||||
|
switch (color)
|
||||||
|
{
|
||||||
|
case LED_GREEN:
|
||||||
|
GPIO_SetBits(GPIOB, GPIO_Pin_1);
|
||||||
|
GPIO_ResetBits(GPIOB,GPIO_Pin_0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LED_RED:
|
||||||
|
GPIO_ResetBits(GPIOB, GPIO_Pin_1);
|
||||||
|
GPIO_SetBits(GPIOB,GPIO_Pin_0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case LED_ORANGE:
|
||||||
|
GPIO_SetBits(GPIOB, GPIO_Pin_1);
|
||||||
|
GPIO_SetBits(GPIOB,GPIO_Pin_0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
ledOff();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gere l'etat du clignotement de la led en fonction de l'etat du système
|
||||||
|
* Appelée toutes les 10 ms
|
||||||
|
* @param state: état actuel du système
|
||||||
|
* @param batteryState: état de la batterie
|
||||||
|
*/
|
||||||
|
void ledManagement(States state, char batteryState) {
|
||||||
|
static char ledCounter=0;
|
||||||
|
char color;
|
||||||
|
|
||||||
|
if (batteryState>1) color=LED_GREEN;
|
||||||
|
else color = LED_RED;
|
||||||
|
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case STATE_IDLE:
|
||||||
|
if ((ledCounter<15) || ((ledCounter>=100) && (ledCounter<115))) ledOn(color);
|
||||||
|
else ledOff();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATE_RUN:
|
||||||
|
case STATE_LOW:
|
||||||
|
ledOn(color);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATE_WATCHDOG_DISABLE:
|
||||||
|
if (ledCounter<100) ledOn(LED_RED);
|
||||||
|
else ledOff();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATE_DISABLE:
|
||||||
|
default:
|
||||||
|
if (ledCounter%10 ==0) ledOn(LED_RED);
|
||||||
|
else ledOff();
|
||||||
|
}
|
||||||
|
|
||||||
|
ledCounter++;
|
||||||
|
if (ledCounter>200) ledCounter=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//void ledManagement(States state) {
|
||||||
|
// if (state == STATE_IDLE) {
|
||||||
|
// if (etatLED == 1) {
|
||||||
|
// LEDON = 1;
|
||||||
|
// } else if (etatLED == 2)
|
||||||
|
// LEDON = 0;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// if (state == STATE_RUN || state == STATE_LOW)
|
||||||
|
// LEDON = 1;
|
||||||
|
//
|
||||||
|
// if (state == STATE_DISABLE) {
|
||||||
|
// if (etatLED % 2 == 0) ledRedOn();
|
||||||
|
// else ledOff();
|
||||||
|
// }
|
||||||
|
// else if (LEDON) {
|
||||||
|
// if (Dumber.stateBattery == 1 && Dumber.StateSystem != STATE_DISABLE)
|
||||||
|
// ledOrangeOn();
|
||||||
|
// else if (Dumber.stateBattery == 2 && Dumber.StateSystem != STATE_DISABLE)
|
||||||
|
// ledGreenOn();
|
||||||
|
// } else
|
||||||
|
// ledOff();
|
||||||
|
//}
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -12,19 +12,18 @@
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
#ifndef LED_H
|
#ifndef _LED_H_
|
||||||
#define LED_H
|
#define _LED_H_
|
||||||
|
|
||||||
#include "stm32f10x.h"
|
#include "stm32f10x.h"
|
||||||
|
|
||||||
#define RED 255
|
#define RED 255
|
||||||
#define GREEN 250
|
#define GREEN 250
|
||||||
|
|
||||||
void MAP_LEDpin(void);
|
extern char etatLED; // Tout les 200 ms cette variable s'incrémente de 1 jusqu'à 5
|
||||||
void INIT_TIM3Led(void);
|
extern char LEDON;
|
||||||
void LEDgreen(void);
|
|
||||||
void LEDred(void);
|
|
||||||
void LEDoff(void);
|
|
||||||
void LEDorange(void);
|
|
||||||
|
|
||||||
#endif /* LED_H */
|
void ledConfigure(void);
|
||||||
|
void ledManagement(States state, char batteryState);
|
||||||
|
|
||||||
|
#endif /* _LED_H_ */
|
||||||
|
|
|
@ -5,110 +5,46 @@
|
||||||
* @version V1.0
|
* @version V1.0
|
||||||
* @date 16-mai-2016
|
* @date 16-mai-2016
|
||||||
* @brief Programme principale du robot Dumby.
|
* @brief Programme principale du robot Dumby.
|
||||||
* Dumby est un robot utilis<EFBFBD> par l'INSA toulouse lors des TPs de temps
|
* Dumby est un robot utilisé par l'INSA toulouse lors des TPs de temps
|
||||||
* R<EFBFBD>el en 4<EFBFBD>me ann<EFBFBD>e. Ce fichier est le fichier principal et la
|
* Réel en 4éme année. Ce fichier est le fichier principal et la
|
||||||
* derni<EFBFBD>re version de son software. Le micro-controleur utilis<EFBFBD> est
|
* dernière version de son software. Le micro-controleur utilisé est
|
||||||
* un STM32-103-RB.
|
* un STM32-103-RB.
|
||||||
* Il comporte comme fonctionnalit<EFBFBD>e entre autre :
|
* Il comporte comme fonctionnalitée entre autre :
|
||||||
* - Asservisement des moteurs
|
* - Asservisement des moteurs
|
||||||
* - Detection de tension de batterie
|
* - Detection de tension de batterie
|
||||||
* - Gestion de commande via l'uart
|
* - Gestion de commande via l'uart
|
||||||
* La tache du fichier est de :
|
* La tache du fichier est de :
|
||||||
* - Alimenter les horloges des periph<EFBFBD>riques necessaires.
|
* - Alimenter les horloges des periphériques necessaires.
|
||||||
* - Appeller les sous programme necessaire au bon fonctionnement
|
* - Appeller les sous programme necessaire au bon fonctionnement
|
||||||
* du robot.
|
* du robot.
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
#include <battery.h>
|
|
||||||
#include <stm32f10x.h>
|
#include <stm32f10x.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "system_dumby.h"
|
#include "system_dumby.h"
|
||||||
#include "cmde_usart.h"
|
|
||||||
#include "motor.h"
|
#include "motor.h"
|
||||||
#include "led.h"
|
#include "led.h"
|
||||||
|
#include "usart.h"
|
||||||
|
#include "battery.h"
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
|
||||||
float integration1 = 0;
|
void mainConfigureClock(void);
|
||||||
float integration2 = 0;
|
void mainPeripheralsInit(void);
|
||||||
/**
|
|
||||||
* @brief Coefficient PI
|
|
||||||
*/
|
|
||||||
const float kp = 15;
|
|
||||||
/**
|
|
||||||
* @brief Coefficient PI
|
|
||||||
*/
|
|
||||||
const float ki = 1.5;
|
|
||||||
/**
|
|
||||||
* @brief Valeurs de vitesse
|
|
||||||
*/
|
|
||||||
float motD = 0, motG = 0;
|
|
||||||
/**
|
|
||||||
* @brief erreurs entre vitesse reel et moteurs (droite)
|
|
||||||
*/
|
|
||||||
int erreurD;
|
|
||||||
/**
|
|
||||||
* @brief erreurs entre vitesse reel et moteurs (gauche)
|
|
||||||
*/
|
|
||||||
int erreurG;
|
|
||||||
|
|
||||||
char cptMesureHigh=0;
|
|
||||||
char cptMesureLow=0;
|
|
||||||
char cptMesureDisable=0;
|
|
||||||
uint32_t cptMesureEmergencyHalt=0;
|
|
||||||
|
|
||||||
uint16_t vbatLowerVal;
|
|
||||||
uint16_t vbatHighVal;
|
|
||||||
uint16_t vbatDiff;
|
|
||||||
|
|
||||||
uint16_t testPostion=0;
|
|
||||||
uint32_t mesureVoltage;
|
|
||||||
uint32_t meanVoltage;
|
|
||||||
|
|
||||||
#define COMPTEUR_SEUIL_HIGH 8
|
|
||||||
#define COMPTEUR_SEUIL_LOW 8
|
|
||||||
#define COMPTEUR_SEUIL_DISABLE 8
|
|
||||||
#define COMPTEUR_SEUIL_EMERGENCY_HALT 3000
|
|
||||||
|
|
||||||
void Configure_Clock_Periph(void);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialise les horloges du micro et de ses p<EFBFBD>riph<EFBFBD>riques.
|
* @brief Initialise les horloges du micro et de ses périphériques.
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
uint16_t k;
|
|
||||||
/**
|
/**
|
||||||
* Initialisation
|
* Initialisation
|
||||||
*/
|
*/
|
||||||
|
mainPeripheralsInit();
|
||||||
Configure_Clock_Periph();
|
|
||||||
default_settings();
|
|
||||||
|
|
||||||
MAP_PinShutDown();
|
|
||||||
|
|
||||||
MAP_MotorPin();
|
|
||||||
MAP_LEDpin();
|
|
||||||
MAP_UsartPin();
|
|
||||||
MAP_batteryPin();
|
|
||||||
INIT_TIM2();
|
|
||||||
INIT_OCMotorPwm();
|
|
||||||
Configure_SysTick();
|
|
||||||
|
|
||||||
INIT_USART();
|
|
||||||
INIT_IT_UsartReceive();
|
|
||||||
|
|
||||||
DMA_BAT();
|
|
||||||
ADC1_CONFIG();
|
|
||||||
INIT_IT_DMA();
|
|
||||||
IC_TIM1_CHANEL3();
|
|
||||||
IC_TIM1_CHANEL1();
|
|
||||||
IT_TIM1();
|
|
||||||
GPIO_ResetBits(GPIOA,GPIO_Pin_12); //enable encodeurs
|
|
||||||
|
|
||||||
while (1){
|
while (1){
|
||||||
__WFE(); // Bascule la puce en sleep mode
|
__WFE(); // Bascule la puce en sleep mode
|
||||||
|
@ -117,157 +53,23 @@ int main(void)
|
||||||
{
|
{
|
||||||
Dumber.flagSystick = 0;
|
Dumber.flagSystick = 0;
|
||||||
|
|
||||||
if(Dumber.acquisition==VOLTAGE && Dumber.BatterieChecking==TRUE)
|
/* Gestion des niveaux de batterie */
|
||||||
{
|
batteryManagement();
|
||||||
vbatLowerVal = 0xFFF;
|
|
||||||
vbatHighVal = 0;
|
|
||||||
|
|
||||||
for(k=0; k<VOLTAGE_BUFFER_SIZE; k++)
|
/* Gestion des moteurs (asservissement, .. */
|
||||||
{
|
motorManagement();
|
||||||
meanVoltage+=ADCConvertedValue[k];
|
|
||||||
|
|
||||||
if (vbatLowerVal> ADCConvertedValue[k]) vbatLowerVal = ADCConvertedValue[k];
|
/* Gestion du clignotement de la led, f=100Hz*/
|
||||||
if (vbatHighVal< ADCConvertedValue[k]) vbatHighVal = ADCConvertedValue[k];
|
ledManagement(Dumber.StateSystem, Dumber.stateBattery);
|
||||||
}
|
|
||||||
|
|
||||||
vbatDiff = vbatHighVal - vbatLowerVal;
|
|
||||||
|
|
||||||
meanVoltage= meanVoltage/VOLTAGE_BUFFER_SIZE;
|
|
||||||
|
|
||||||
mesureVoltage = meanVoltage;
|
|
||||||
|
|
||||||
Dumber.BatteryPercentage = mesureVoltage;
|
|
||||||
Dumber.acquisition=FALSE;
|
|
||||||
|
|
||||||
if(Dumber.BatteryPercentage >= VBAT_SEUIL_LOW)
|
|
||||||
{
|
|
||||||
cptMesureHigh++;
|
|
||||||
if(cptMesureHigh >= COMPTEUR_SEUIL_HIGH)
|
|
||||||
{
|
|
||||||
if(Dumber.StateSystem == LOW) Dumber.StateSystem = RUN;
|
|
||||||
|
|
||||||
Dumber.stateBattery = 2;
|
|
||||||
cptMesureHigh=0;
|
|
||||||
cptMesureLow=0;
|
|
||||||
cptMesureDisable=0;
|
|
||||||
cptMesureEmergencyHalt=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (Dumber.BatteryPercentage < VBAT_SEUIL_LOW && Dumber.BatteryPercentage >= VBAT_SEUIL_DISABLE)
|
|
||||||
{
|
|
||||||
cptMesureLow++;
|
|
||||||
if(cptMesureLow >= COMPTEUR_SEUIL_LOW)
|
|
||||||
{
|
|
||||||
if(Dumber.StateSystem == RUN) Dumber.StateSystem=LOW;
|
|
||||||
|
|
||||||
Dumber.stateBattery =1;
|
|
||||||
cptMesureHigh=0;
|
|
||||||
cptMesureLow=0;
|
|
||||||
cptMesureDisable=0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else // Dumber.BatteryPercentage < VBAT_SEUIL_DISABLE
|
|
||||||
{
|
|
||||||
cptMesureDisable++;
|
|
||||||
|
|
||||||
if(cptMesureDisable >= COMPTEUR_SEUIL_DISABLE)
|
|
||||||
{
|
|
||||||
Dumber.StateSystem = DISABLE;
|
|
||||||
cptMesureHigh=0;
|
|
||||||
cptMesureLow=0;
|
|
||||||
cptMesureDisable=0;
|
|
||||||
Dumber.stateBattery= 0;
|
|
||||||
|
|
||||||
cmdRightMotor(BRAKE,0);
|
|
||||||
cmdLeftMotor(BRAKE,0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (regulation_vitesseD) {
|
|
||||||
erreurD = (signed int) G_speedRight - (signed int) tourD;
|
|
||||||
motD = kp * erreurD + integration1;
|
|
||||||
integration1 += ki * erreurD;
|
|
||||||
|
|
||||||
if (motD > 255) motD = 255;
|
|
||||||
|
|
||||||
if (motD < 0) motD = 0;
|
|
||||||
|
|
||||||
motD = (uint16_t) motD;
|
|
||||||
majVitesseMotorD(motD);
|
|
||||||
tourD = 0;
|
|
||||||
regulation_vitesseD = 0;
|
|
||||||
|
|
||||||
if (G_lapsRight - tourPositionD < 0) {
|
|
||||||
cmdRightMotor(BRAKE, 255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (regulation_vitesseG) {
|
|
||||||
erreurG = (signed int) G_speedLeft - (signed int) tourG;
|
|
||||||
motG = kp * erreurG + integration2;
|
|
||||||
|
|
||||||
integration2 += ki * erreurG;
|
|
||||||
|
|
||||||
if (motG > 255) motG = 255;
|
|
||||||
|
|
||||||
if (motG < 0) motG = 0;
|
|
||||||
|
|
||||||
motG = (uint16_t) motG;
|
|
||||||
|
|
||||||
majVitesseMotorG(motG);
|
|
||||||
tourG = 0;
|
|
||||||
regulation_vitesseG = 0;
|
|
||||||
|
|
||||||
if (G_lapsLeft - tourPositionG < 0) {
|
|
||||||
cmdLeftMotor(BRAKE, 255);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (G_lapsLeft - tourPositionG < 0 && G_lapsRight - tourPositionD < 0
|
|
||||||
&& asservissement == 1) {
|
|
||||||
|
|
||||||
cmdLeftMotor(BRAKE, 255);
|
|
||||||
cmdRightMotor(BRAKE, 255);
|
|
||||||
asservissement = 0;
|
|
||||||
erreurD = 0;
|
|
||||||
erreurG = 0;
|
|
||||||
integration1 = 0;
|
|
||||||
integration2 = 0;
|
|
||||||
Dumber.busyState = FALSE;
|
|
||||||
Dumber.cpt_inactivity = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Dumber.StateSystem == IDLE) {
|
|
||||||
if (etatLED == 1) {
|
|
||||||
LEDON = 1;
|
|
||||||
} else if (etatLED == 2)
|
|
||||||
LEDON = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (Dumber.StateSystem == DISABLE) {
|
|
||||||
if (etatLED % 2 == 0) LEDred();
|
|
||||||
else LEDoff();
|
|
||||||
|
|
||||||
|
if (Dumber.StateSystem == STATE_DISABLE) {
|
||||||
cptMesureEmergencyHalt++;
|
cptMesureEmergencyHalt++;
|
||||||
|
|
||||||
if (cptMesureEmergencyHalt >= COMPTEUR_SEUIL_EMERGENCY_HALT)
|
if (cptMesureEmergencyHalt >= COMPTEUR_SEUIL_EMERGENCY_HALT) {
|
||||||
{
|
systemShutDown();
|
||||||
shutDown();
|
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Dumber.StateSystem == RUN || Dumber.StateSystem == LOW)
|
|
||||||
LEDON = 1;
|
|
||||||
|
|
||||||
if (LEDON) {
|
|
||||||
if (Dumber.stateBattery == 1 && Dumber.StateSystem != DISABLE)
|
|
||||||
LEDorange();
|
|
||||||
if (Dumber.stateBattery == 2 && Dumber.StateSystem != DISABLE)
|
|
||||||
LEDgreen();
|
|
||||||
} else
|
|
||||||
LEDoff();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -278,17 +80,32 @@ int main(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Initialise les horloges du micro et de ses p<EFBFBD>riph<EFBFBD>riques.
|
* @brief Initialise les périphériques pour leur utilisation.
|
||||||
* @param None
|
* @param None
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void Configure_Clock_Periph(void)
|
void mainPeripheralsInit(void) {
|
||||||
|
mainConfigureClock();
|
||||||
|
|
||||||
|
systemConfigure();
|
||||||
|
motorConfigure();
|
||||||
|
ledConfigure();
|
||||||
|
usartConfigure();
|
||||||
|
batteryConfigure();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Initialise les horloges du micro et de ses périphériques.
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void mainConfigureClock(void)
|
||||||
{
|
{
|
||||||
//Configuration de la fr<66>qyence d'horloge de l'adc */
|
//Configuration de la fréquence d'horloge de l'adc */
|
||||||
RCC_ADCCLKConfig(RCC_PCLK2_Div2);
|
RCC_ADCCLKConfig(RCC_PCLK2_Div2);
|
||||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
|
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
|
||||||
|
|
||||||
//Activation de l'horloge du GPIO, de A B et C, de ADC1, de AFIO
|
//Activation de l'horloge du GPIO, de A, B et C, de ADC1, de AFIO
|
||||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3|RCC_APB1Periph_TIM2|RCC_APB2Periph_USART1, ENABLE);
|
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3|RCC_APB1Periph_TIM2|RCC_APB2Periph_USART1, ENABLE);
|
||||||
RCC_APB2PeriphClockCmd( RCC_APB2Periph_ADC1| RCC_APB2Periph_TIM1 |RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
|
RCC_APB2PeriphClockCmd( RCC_APB2Periph_ADC1| RCC_APB2Periph_TIM1 |RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |
|
||||||
RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO|RCC_APB2Periph_USART1|RCC_APB2Periph_SPI1,
|
RCC_APB2Periph_GPIOC | RCC_APB2Periph_AFIO|RCC_APB2Periph_USART1|RCC_APB2Periph_SPI1,
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
* - La commandes des moteurs dans leurs 3 modes de fonctionnement (AVANT, ARRIERE, FREIN)
|
* - La commandes des moteurs dans leurs 3 modes de fonctionnement (AVANT, ARRIERE, FREIN)
|
||||||
* et de leurs vitesse (valeur de PWM entre 0 et 255).
|
* et de leurs vitesse (valeur de PWM entre 0 et 255).
|
||||||
*
|
*
|
||||||
*@note TABLE DE VERITEE DU DRIVER MOTEUR
|
* @note TABLE DE VERITEE DU DRIVER MOTEUR
|
||||||
*
|
*
|
||||||
* ENABLE | INPUTS | Moteurs
|
* ENABLE | INPUTS | Moteurs
|
||||||
* | |
|
* | |
|
||||||
|
@ -28,55 +28,74 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stm32f10x.h>
|
#include <stm32f10x.h>
|
||||||
#include "system_dumby.h"
|
|
||||||
|
|
||||||
|
#include "system_dumby.h"
|
||||||
#include "motor.h"
|
#include "motor.h"
|
||||||
|
|
||||||
__IO uint16_t IC1ReadValue1 = 0, IC1ReadValue2 = 0, IC3ReadValue1 = 0, IC3ReadValue2 = 0;
|
|
||||||
__IO uint16_t CaptureMotor1Nbr = 0, CaptureMotor2Nbr = 0;
|
|
||||||
__IO uint32_t motor1Capture, motor2Capture = 0;
|
|
||||||
|
|
||||||
TIM_TimeBaseInitTypeDef TIM2_TempsPWMsettings;
|
|
||||||
TIM_OCInitTypeDef TIM2_Configure;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Variables Globals nombre d'incr<EFBFBD>mentation de capteur de position de la roue droite.
|
* @brief Variables globales nombre d'incrémentation de capteur de position de la roue droite.
|
||||||
* @note tourPositionG correspond exactement <EFBFBD> la m<EFBFBD>me valeur.
|
* @note tourPositionG correspond exactement à la même valeur.
|
||||||
*/
|
*/
|
||||||
uint16_t tourD = 0;
|
uint16_t tourD = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Variables Globals nombre d'incr<EFBFBD>mentation de capteur de position de la roue gauche.
|
* @brief Variables globales nombre d'incrémentation de capteur de position de la roue gauche.
|
||||||
* @note tourPositionG correspond exactement <EFBFBD> la m<EFBFBD>me valeur.
|
* @note tourPositionG correspond exactement à la même valeur.
|
||||||
*/
|
*/
|
||||||
uint16_t tourG = 0;
|
uint16_t tourG = 0;
|
||||||
uint16_t tourPositionD;
|
uint16_t tourPositionD;
|
||||||
uint16_t tourPositionG;
|
uint16_t tourPositionG;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Variables Globals des consignes de vitesses du moteur droit.
|
* @brief Variables globales des consignes de vitesses du moteur droit.
|
||||||
* @note Variables utilis<EFBFBD> dans le programme principal main.c
|
* @note Variables utilisées dans le programme principal main.c
|
||||||
*/
|
*/
|
||||||
uint16_t G_speedRight=20;
|
uint16_t G_speedRight=20;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Variables Globals des consignes de vitesses du moteur gauche.
|
* @brief Variables globales des consignes de vitesses du moteur gauche.
|
||||||
* @note Variables utilis<EFBFBD> dans le programme principal main.c
|
* @note Variables utilisées dans le programme principal main.c
|
||||||
*/
|
*/
|
||||||
uint16_t G_speedLeft=20;
|
uint16_t G_speedLeft=20;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Variables Globals des consignes de position du moteur gauche.
|
* @brief Variables globales des consignes de position du moteur gauche.
|
||||||
* @note Variables utilis<EFBFBD> dans le programme principal main.c
|
* @note Variables utilisées dans le programme principal main.c
|
||||||
*/
|
*/
|
||||||
uint16_t G_lapsLeft;
|
uint16_t G_lapsLeft;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Variables Globals des consignes de position du moteur droit.
|
* @brief Variables globales des consignes de position du moteur droit.
|
||||||
* @note Variables utilis<EFBFBD> dans le programme principal main.c
|
* @note Variables utilisées dans le programme principal main.c
|
||||||
*/
|
*/
|
||||||
uint16_t G_lapsRight;
|
uint16_t G_lapsRight;
|
||||||
|
|
||||||
|
float integration1 = 0;
|
||||||
|
float integration2 = 0;
|
||||||
|
/**
|
||||||
|
* @brief Coefficient PI
|
||||||
|
*/
|
||||||
|
const float kp = 15;
|
||||||
|
/**
|
||||||
|
* @brief Coefficient PI
|
||||||
|
*/
|
||||||
|
const float ki = 1.5;
|
||||||
|
/**
|
||||||
|
* @brief Valeurs de vitesse
|
||||||
|
*/
|
||||||
|
float motD = 0, motG = 0;
|
||||||
|
/**
|
||||||
|
* @brief erreurs entre vitesse réelle et moteur (droite)
|
||||||
|
*/
|
||||||
|
int erreurD;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief erreurs entre vitesse réelle et moteur (gauche)
|
||||||
|
*/
|
||||||
|
int erreurG;
|
||||||
|
|
||||||
|
uint16_t asservissement;
|
||||||
|
uint16_t regulation_vitesseD, regulation_vitesseG;
|
||||||
/** @addtogroup Projects
|
/** @addtogroup Projects
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
@ -90,10 +109,10 @@ uint16_t G_lapsRight;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Assigne et d<EFBFBD>finis le GPIO necessaire pour le moteur.
|
* @brief Assigne et définis le GPIO nécessaire pour le moteur.
|
||||||
*
|
*
|
||||||
* La fonction MAP_MotorPin va venir configurer le E/S du GPIO pour correspondre avec
|
* La fonction MAP_MotorPin va venir configurer le E/S du GPIO pour correspondre avec
|
||||||
* le sch<EFBFBD>ma electrique en ressource.
|
* le schéma électrique en ressource.
|
||||||
* @note 2 pwm en alternate fonction : PA1,PA2. 4 entr<EFBFBD>e timer.
|
* @note 2 pwm en alternate fonction : PA1,PA2. 4 entr<EFBFBD>e timer.
|
||||||
* PA8,PA9,PA10,PA11. 4 sortie ppull PB12,PB13,PB14,PB15
|
* PA8,PA9,PA10,PA11. 4 sortie ppull PB12,PB13,PB14,PB15
|
||||||
*
|
*
|
||||||
|
@ -101,10 +120,13 @@ uint16_t G_lapsRight;
|
||||||
* @retval None
|
* @retval None
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
void MAP_MotorPin(void)
|
void motorConfigure(void)
|
||||||
{
|
{
|
||||||
// Variable local necessaire <20> l'initialisation des structures
|
|
||||||
GPIO_InitTypeDef Init_Structure;
|
GPIO_InitTypeDef Init_Structure;
|
||||||
|
TIM_TimeBaseInitTypeDef TIM2_TempsPWMsettings;
|
||||||
|
TIM_OCInitTypeDef TIM2_Configure;
|
||||||
|
TIM_ICInitTypeDef TIM_ICInitStructure;
|
||||||
|
NVIC_InitTypeDef NVIC_InitStructure;
|
||||||
|
|
||||||
// Configure les PIN A1 et A2 en output / alternate fonction
|
// Configure les PIN A1 et A2 en output / alternate fonction
|
||||||
Init_Structure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2;
|
Init_Structure.GPIO_Pin = GPIO_Pin_1|GPIO_Pin_2;
|
||||||
|
@ -130,41 +152,21 @@ void MAP_MotorPin(void)
|
||||||
Init_Structure.GPIO_Speed = GPIO_Speed_50MHz;
|
Init_Structure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||||
Init_Structure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
Init_Structure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||||
GPIO_Init(GPIOA, &Init_Structure);
|
GPIO_Init(GPIOA, &Init_Structure);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// Configuration du timer 2 (pwm moteurs*
|
||||||
* @brief La fonction INIT_TIM2 initialise le Timer2 <EFBFBD> une fr<EFBFBD>quence de 25kHz (fc nominal) et initialise
|
// On souhaite une résolution du PWM de 256 valeurs MOTOR1 TIM2
|
||||||
* les pwm des moteurs <EFBFBD> un dutycycle <EFBFBD> 0% de 255
|
|
||||||
*
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void INIT_TIM2(void)
|
|
||||||
{
|
|
||||||
// On souhaite une r<>solution du PWM de 256 valeurs MOTOR1 TIM2
|
|
||||||
TIM2_TempsPWMsettings.TIM_Period = 255;
|
TIM2_TempsPWMsettings.TIM_Period = 255;
|
||||||
TIM2_TempsPWMsettings.TIM_Prescaler = 0;
|
TIM2_TempsPWMsettings.TIM_Prescaler = 0;
|
||||||
TIM2_TempsPWMsettings.TIM_ClockDivision=0;
|
TIM2_TempsPWMsettings.TIM_ClockDivision=0;
|
||||||
TIM2_TempsPWMsettings.TIM_CounterMode=TIM_CounterMode_Up;
|
TIM2_TempsPWMsettings.TIM_CounterMode=TIM_CounterMode_Up;
|
||||||
|
|
||||||
TIM_TimeBaseInit(TIM2, &TIM2_TempsPWMsettings);
|
TIM_TimeBaseInit(TIM2, &TIM2_TempsPWMsettings);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initialise les channels
|
|
||||||
*
|
|
||||||
* Initialise le chanel 2 et 3 du TM2 pour g<EFBFBD>rer les moteurs
|
|
||||||
*
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void INIT_OCMotorPwm(void)
|
|
||||||
{
|
|
||||||
// Configuration du PWM sur le timer 2
|
// Configuration du PWM sur le timer 2
|
||||||
TIM2_Configure.TIM_OCMode=TIM_OCMode_PWM2;
|
TIM2_Configure.TIM_OCMode=TIM_OCMode_PWM2;
|
||||||
TIM2_Configure.TIM_OutputState = TIM_OutputState_Enable;
|
TIM2_Configure.TIM_OutputState = TIM_OutputState_Enable;
|
||||||
TIM2_Configure.TIM_OutputNState = TIM_OutputNState_Enable;
|
TIM2_Configure.TIM_OutputNState = TIM_OutputNState_Enable;
|
||||||
TIM2_Configure.TIM_Pulse = 256; // Constante initialis<EFBFBD> <20> 256, Pour un rapport cyclique nul
|
TIM2_Configure.TIM_Pulse = 256; // Constante initialisée à 256, pour un rapport cyclique nul
|
||||||
TIM2_Configure.TIM_OCPolarity = TIM_OCPolarity_High;
|
TIM2_Configure.TIM_OCPolarity = TIM_OCPolarity_High;
|
||||||
|
|
||||||
TIM_OC3Init(TIM2, &TIM2_Configure);
|
TIM_OC3Init(TIM2, &TIM2_Configure);
|
||||||
|
@ -178,18 +180,8 @@ void INIT_OCMotorPwm(void)
|
||||||
TIM_Cmd(TIM2, ENABLE);
|
TIM_Cmd(TIM2, ENABLE);
|
||||||
|
|
||||||
TIM_CtrlPWMOutputs(TIM2,ENABLE);
|
TIM_CtrlPWMOutputs(TIM2,ENABLE);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// Configuration de la capture de l'encodeur 1
|
||||||
* @brief Initialise le channel 1 pour le retour des capteurs de position
|
|
||||||
* de la roue droite.
|
|
||||||
*
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void IC_TIM1_CHANEL1(void)
|
|
||||||
{
|
|
||||||
TIM_ICInitTypeDef TIM_ICInitStructure;
|
|
||||||
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
|
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
|
||||||
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
|
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
|
||||||
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
|
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
|
||||||
|
@ -199,18 +191,8 @@ void IC_TIM1_CHANEL1(void)
|
||||||
TIM_ICInit(TIM1, &TIM_ICInitStructure);
|
TIM_ICInit(TIM1, &TIM_ICInitStructure);
|
||||||
TIM_Cmd(TIM1, ENABLE);
|
TIM_Cmd(TIM1, ENABLE);
|
||||||
TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE);
|
TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// Configuration de la capture de l'encodeur 1
|
||||||
* @brief Initialise le channel 3 pour le retour des capteurs de position
|
|
||||||
* de la roue gauche.
|
|
||||||
*
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void IC_TIM1_CHANEL3(void)
|
|
||||||
{
|
|
||||||
TIM_ICInitTypeDef TIM_ICInitStructure;
|
|
||||||
TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;
|
TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;
|
||||||
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
|
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
|
||||||
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
|
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
|
||||||
|
@ -220,24 +202,18 @@ void IC_TIM1_CHANEL3(void)
|
||||||
TIM_ICInit(TIM1, &TIM_ICInitStructure);
|
TIM_ICInit(TIM1, &TIM_ICInitStructure);
|
||||||
TIM_Cmd(TIM1, ENABLE);
|
TIM_Cmd(TIM1, ENABLE);
|
||||||
TIM_ITConfig(TIM1, TIM_IT_CC3, ENABLE);
|
TIM_ITConfig(TIM1, TIM_IT_CC3, ENABLE);
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
// Enable the TIM1 Capture interrupt
|
||||||
* @brief D<EFBFBD>finis une interuptions sur le Timer1.
|
|
||||||
*
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void IT_TIM1(void)
|
|
||||||
{
|
|
||||||
NVIC_InitTypeDef NVIC_InitStructure;
|
|
||||||
|
|
||||||
/* Enable the TIM1 global Interrupt */
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;
|
NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;
|
||||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||||
NVIC_Init(&NVIC_InitStructure);
|
NVIC_Init(&NVIC_InitStructure);
|
||||||
|
|
||||||
|
// RAZ des variables
|
||||||
|
regulation_vitesseD = 0;
|
||||||
|
regulation_vitesseG = 0;
|
||||||
|
asservissement =0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -248,16 +224,17 @@ void IT_TIM1(void)
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
/**
|
/**
|
||||||
* @brief Commande de plus haut niveau pour contr<EFBFBD>ler le moteur droit.
|
* @brief Commande de plus haut niveau pour contrôler le moteur droit.
|
||||||
*
|
*
|
||||||
* @param Mode de fonctionnement du moteur, peut <EFBFBD>tre <EFBFBD>gal aux constantes BRAKE, FORWARD, REVERSE d<EFBFBD>finis dans moteur.h
|
* @param Mode de fonctionnement du moteur, peut être égal aux constantes BRAKE, FORWARD, REVERSE définis dans moteur.h
|
||||||
* @param Consigne de vitesse du moteur, d<EFBFBD>finis par un pwm entre 0 et 255.
|
* @param Consigne de vitesse du moteur, défini par un pwm entre 0 et 255.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void cmdRightMotor(char mod, uint16_t pwm)
|
void motorCmdRight(char mod, uint16_t pwm)
|
||||||
{
|
{
|
||||||
pwm = 256 - pwm;
|
pwm = 256 - pwm;
|
||||||
|
|
||||||
switch (mod) {
|
switch (mod) {
|
||||||
case BRAKE:
|
case BRAKE:
|
||||||
GPIO_SetBits(GPIOB, GPIO_Pin_12);
|
GPIO_SetBits(GPIOB, GPIO_Pin_12);
|
||||||
|
@ -281,14 +258,14 @@ void cmdRightMotor(char mod, uint16_t pwm)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Commande de plus haut niveau pour contr<EFBFBD>ler le moteur Gauche.
|
* @brief Commande de plus haut niveau pour contrôler le moteur Gauche.
|
||||||
*
|
*
|
||||||
* @param Mode de fonctionnement du moteur, peut <EFBFBD>tre <EFBFBD>gal aux constantes BRAKE, FORWARD, REVERSE d<EFBFBD>finis dans moteur.h
|
* @param Mode de fonctionnement du moteur, peut être égal aux constantes BRAKE, FORWARD, REVERSE définis dans moteur.h
|
||||||
* @param Consigne de vitesse du moteur, d<EFBFBD>finis par un pwm entre 0 et 255.
|
* @param Consigne de vitesse du moteur, défini par un pwm entre 0 et 255.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void cmdLeftMotor(char mod, uint16_t pwm) {
|
void motorCmdLeft(char mod, uint16_t pwm) {
|
||||||
pwm = 256 - pwm;
|
pwm = 256 - pwm;
|
||||||
switch (mod) {
|
switch (mod) {
|
||||||
case BRAKE:
|
case BRAKE:
|
||||||
|
@ -313,44 +290,44 @@ void cmdLeftMotor(char mod, uint16_t pwm) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Commande de plus haut niveau pour contr<EFBFBD>ler la vitesse moteur Gauche.
|
* @brief Commande de plus haut niveau pour contrôler la vitesse moteur Gauche.
|
||||||
*
|
*
|
||||||
* @param Consigne de vitesse du moteur, d<EFBFBD>finis par un pwm entre 0 et 255.
|
* @param Consigne de vitesse du moteur, défini par un pwm entre 0 et 255.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void majVitesseMotorG(uint16_t pwm) {
|
void motorSpeedUpdateLeft(uint16_t pwm) {
|
||||||
pwm = 256 - pwm;
|
pwm = 256 - pwm;
|
||||||
TIM_SetCompare2(TIM2, pwm);
|
TIM_SetCompare2(TIM2, pwm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Commande de plus haut niveau pour contr<EFBFBD>ler la vitesse moteur Droit.
|
* @brief Commande de plus haut niveau pour contrôler la vitesse moteur Droit.
|
||||||
*
|
*
|
||||||
* @param Consigne de vitesse du moteur, d<EFBFBD>finis par un pwm entre 0 et 255.
|
* @param Consigne de vitesse du moteur, défini par un pwm entre 0 et 255.
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void majVitesseMotorD(uint16_t pwm) {
|
void motorSpeedUpdateRight(uint16_t pwm) {
|
||||||
pwm = 256 - pwm;
|
pwm = 256 - pwm;
|
||||||
TIM_SetCompare3(TIM2, pwm);
|
TIM_SetCompare3(TIM2, pwm);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Regulation des deux moteurs.
|
* @brief Régulation des deux moteurs.
|
||||||
*
|
*
|
||||||
* Modifile le mode de fonctionnement des roues, puis
|
* Modifie le le mode de fonctionnement des roues, puis
|
||||||
* va mettre <EFBFBD> jour les variables globale G_laps* et G_speed*
|
* va mettre à jour les variables globale G_laps* et G_speed*
|
||||||
* utilis<EFBFBD> dans main.c pour l'asservissement.
|
* utilisé dans main.c pour l'asservissement.
|
||||||
*
|
*
|
||||||
* @param Mode de fonctionnement la roue droite (BRAKE, REVERSE, FORWARD)
|
* @param Mode de fonctionnement la roue droite (BRAKE, REVERSE, FORWARD)
|
||||||
* @param Mode de fonctionnement la roue droite (BRAKE, REVERSE, FORWARD)
|
* @param Mode de fonctionnement la roue droite (BRAKE, REVERSE, FORWARD)
|
||||||
* @param Nombre de tour de roue droite <EFBFBD> effectuer.
|
* @param Nombre de tour de roue droite à effectuer.
|
||||||
* @param Nombre de tour de roue gauche <EFBFBD> effectuer.
|
* @param Nombre de tour de roue gauche à effectuer.
|
||||||
* @param Vitesse de la roue de droite.
|
* @param Vitesse de la roue de droite.
|
||||||
* @param Vitesse de la roue de gauche.
|
* @param Vitesse de la roue de gauche.
|
||||||
*
|
*
|
||||||
* @retval None
|
* @retval None
|
||||||
*/
|
*/
|
||||||
void regulationMoteur(char modRight, char modLeft, uint16_t lapsRight,
|
void motorRegulation(char modRight, char modLeft, uint16_t lapsRight,
|
||||||
uint16_t lapsLeft, uint16_t speedRight, uint16_t speedLeft) {
|
uint16_t lapsLeft, uint16_t speedRight, uint16_t speedLeft) {
|
||||||
/*Moteur Droit*/
|
/*Moteur Droit*/
|
||||||
switch (modRight) {
|
switch (modRight) {
|
||||||
|
@ -411,7 +388,7 @@ void regulationMoteur(char modRight, char modLeft, uint16_t lapsRight,
|
||||||
/**
|
/**
|
||||||
* @brief Gestion de l'interuption des capteurs de positions.
|
* @brief Gestion de l'interuption des capteurs de positions.
|
||||||
*
|
*
|
||||||
* Fonctin de callback permettant d'incr<EFBFBD>menter le nombre
|
* Fonction de callback permettant d'incrémenter le nombre
|
||||||
* de tour des deux roues.
|
* de tour des deux roues.
|
||||||
*
|
*
|
||||||
* @param None
|
* @param None
|
||||||
|
@ -422,7 +399,6 @@ void TIM1_CC_IRQHandler(void) {
|
||||||
TIM_ClearITPendingBit(TIM1, TIM_IT_CC1);
|
TIM_ClearITPendingBit(TIM1, TIM_IT_CC1);
|
||||||
tourD++;
|
tourD++;
|
||||||
tourPositionD++;
|
tourPositionD++;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (TIM_GetITStatus(TIM1, TIM_IT_CC3) == SET) {
|
if (TIM_GetITStatus(TIM1, TIM_IT_CC3) == SET) {
|
||||||
|
@ -431,6 +407,69 @@ void TIM1_CC_IRQHandler(void) {
|
||||||
tourPositionG++;
|
tourPositionG++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Gestion de l'asservissement des moteurs
|
||||||
|
*
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void motorManagement(void) {
|
||||||
|
if (regulation_vitesseD) {
|
||||||
|
erreurD = (signed int) G_speedRight - (signed int) tourD;
|
||||||
|
motD = kp * erreurD + integration1;
|
||||||
|
integration1 += ki * erreurD;
|
||||||
|
|
||||||
|
if (motD > 255) motD = 255;
|
||||||
|
|
||||||
|
if (motD < 0) motD = 0;
|
||||||
|
|
||||||
|
motD = (uint16_t) motD;
|
||||||
|
motorSpeedUpdateRight(motD);
|
||||||
|
tourD = 0;
|
||||||
|
regulation_vitesseD = 0;
|
||||||
|
|
||||||
|
if (G_lapsRight - tourPositionD < 0) {
|
||||||
|
motorCmdRight(BRAKE, 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (regulation_vitesseG) {
|
||||||
|
erreurG = (signed int) G_speedLeft - (signed int) tourG;
|
||||||
|
motG = kp * erreurG + integration2;
|
||||||
|
|
||||||
|
integration2 += ki * erreurG;
|
||||||
|
|
||||||
|
if (motG > 255) motG = 255;
|
||||||
|
|
||||||
|
if (motG < 0) motG = 0;
|
||||||
|
|
||||||
|
motG = (uint16_t) motG;
|
||||||
|
|
||||||
|
motorSpeedUpdateLeft(motG);
|
||||||
|
tourG = 0;
|
||||||
|
regulation_vitesseG = 0;
|
||||||
|
|
||||||
|
if (G_lapsLeft - tourPositionG < 0) {
|
||||||
|
motorCmdLeft(BRAKE, 255);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (G_lapsLeft - tourPositionG < 0 && G_lapsRight - tourPositionD < 0
|
||||||
|
&& asservissement == 1) {
|
||||||
|
|
||||||
|
motorCmdLeft(BRAKE, 255);
|
||||||
|
motorCmdRight(BRAKE, 255);
|
||||||
|
asservissement = 0;
|
||||||
|
erreurD = 0;
|
||||||
|
erreurG = 0;
|
||||||
|
integration1 = 0;
|
||||||
|
integration2 = 0;
|
||||||
|
Dumber.busyState = FALSE;
|
||||||
|
Dumber.cpt_inactivity = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -22,45 +22,37 @@
|
||||||
* 0 | X | Roue Libre
|
* 0 | X | Roue Libre
|
||||||
*--------------------------------------------------------------------
|
*--------------------------------------------------------------------
|
||||||
* | CMDA & !CMDB | Avant
|
* | CMDA & !CMDB | Avant
|
||||||
* 1 | !CMDA & CMDB | Arriére
|
* 1 | !CMDA & CMDB | Arrière
|
||||||
* | CMDA = CMDB | Frein
|
* | CMDA = CMDB | Frein
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
#ifndef Motor_H
|
#ifndef _MOTOR_H_
|
||||||
#define Motor_H
|
#define _MOTOR_H_
|
||||||
|
|
||||||
#include "stm32f10x.h"
|
#include "stm32f10x.h"
|
||||||
//#include "system_dumby.h"
|
|
||||||
|
|
||||||
extern uint16_t G_speedRight, G_speedLeft, G_lapsLeft, G_lapsRight;
|
extern uint16_t G_speedRight, G_speedLeft, G_lapsLeft, G_lapsRight;
|
||||||
extern uint16_t tourG, tourD, tourPositionD,tourPositionG;
|
extern uint16_t tourG, tourD, tourPositionD,tourPositionG;
|
||||||
|
|
||||||
|
extern uint16_t asservissement;
|
||||||
|
extern uint16_t regulation_vitesseD, regulation_vitesseG;
|
||||||
/**
|
/**
|
||||||
* @brief Etats que peuvent prendre chaques moteurs
|
* @brief États que peuvent prendre chaque moteurs
|
||||||
* Avant, Arriére, Frein
|
* Avant, Arrière, Frein
|
||||||
*/
|
*/
|
||||||
#define FORWARD 11
|
#define FORWARD 11
|
||||||
#define REVERSE 12
|
#define REVERSE 12
|
||||||
#define BRAKE 13
|
#define BRAKE 13
|
||||||
|
|
||||||
void MAP_MotorPin(void);
|
void motorConfigure(void);
|
||||||
void INIT_TIM2(void);
|
void motorManagement(void);
|
||||||
void INIT_OCMotorPwm(void);
|
|
||||||
void commandeMoteur(void);
|
|
||||||
|
|
||||||
void IC_TIM1_CHANEL3(void);
|
void motorCmdRight(char mod, uint16_t pwm);
|
||||||
void IC_TIM1_CHANEL1(void);
|
void motorCmdLeft(char mod, uint16_t pwm);
|
||||||
void IT_TIM1(void);
|
void motorSpeedUpdateLeft(uint16_t pwm);
|
||||||
|
void motorSpeedUpdateRight(uint16_t pwm);
|
||||||
|
void motorRegulation(char modRight, char modLeft, uint16_t lapsRight, uint16_t lapsLeft, uint16_t speedRight, uint16_t speedLeft);
|
||||||
|
|
||||||
void cmdRightMotor(char mod, uint16_t pwm);
|
#endif /* _MOTOR_H_ */
|
||||||
void cmdLeftMotor(char mod, uint16_t pwm);
|
|
||||||
|
|
||||||
void majVitesseMotorG(uint16_t pwm);
|
|
||||||
void majVitesseMotorD(uint16_t pwm);
|
|
||||||
|
|
||||||
void regulationMoteur(char modRight, char modLeft, uint16_t lapsRight, uint16_t lapsLeft, uint16_t speedRight, uint16_t speedLeft);
|
|
||||||
//void regulationCBK(void);
|
|
||||||
|
|
||||||
#endif /* Motor_H */
|
|
||||||
|
|
||||||
|
|
|
@ -27,27 +27,17 @@
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
#include <battery.h>
|
|
||||||
#include "system_dumby.h"
|
|
||||||
#include <stm32f10x.h>
|
#include <stm32f10x.h>
|
||||||
#include "led.h"
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include "system_dumby.h"
|
||||||
|
#include "battery.h"
|
||||||
|
#include "led.h"
|
||||||
#include "motor.h"
|
#include "motor.h"
|
||||||
#include "cmde_usart.h"
|
#include "usart.h"
|
||||||
|
|
||||||
Settings Dumber;
|
Settings Dumber;
|
||||||
static __IO uint32_t TimingBattery=10000;
|
|
||||||
uint16_t greenLight = 0;
|
|
||||||
uint16_t redLight = 0;
|
|
||||||
uint16_t regulation_vitesseD = 0, regulation_vitesseG = 0, asservissement =0;
|
|
||||||
char etatLED = 1;
|
|
||||||
uint16_t watchDogState;;
|
|
||||||
char vClignotement1s=0;
|
|
||||||
uint16_t tourPositionGprec =1, tourPositionDprec=1;
|
|
||||||
char LEDON =0;
|
|
||||||
|
|
||||||
int led=0;
|
|
||||||
|
|
||||||
/** @addtogroup Projects
|
/** @addtogroup Projects
|
||||||
* @{
|
* @{
|
||||||
|
@ -57,32 +47,6 @@ int led=0;
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** @addtogroup init shutdown_gpio init
|
|
||||||
* @{
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Assigne et défini le GPIO necessaire pour la gestion du shutdown.
|
|
||||||
*
|
|
||||||
* @param None
|
|
||||||
* @retval None
|
|
||||||
*/
|
|
||||||
void MAP_PinShutDown(void)
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef Init_Structure;
|
|
||||||
Init_Structure.GPIO_Pin = GPIO_Pin_5;
|
|
||||||
Init_Structure.GPIO_Mode = GPIO_Mode_Out_PP;
|
|
||||||
Init_Structure.GPIO_Speed = GPIO_Speed_50MHz;
|
|
||||||
GPIO_SetBits(GPIOB, GPIO_Pin_5);
|
|
||||||
GPIO_Init(GPIOB, &Init_Structure);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @}
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*@brief Configure les propriété de dumber au démarage :
|
*@brief Configure les propriété de dumber au démarage :
|
||||||
* Etat de depart : IDLE
|
* Etat de depart : IDLE
|
||||||
|
@ -90,15 +54,29 @@ void MAP_PinShutDown(void)
|
||||||
*@param None
|
*@param None
|
||||||
*@retval None
|
*@retval None
|
||||||
*/
|
*/
|
||||||
void default_settings(void)
|
void systemConfigure(void)
|
||||||
{
|
{
|
||||||
|
GPIO_InitTypeDef Init_Structure;
|
||||||
|
|
||||||
|
// Configure le systick pour générer des interruptions toutes les 10ms.
|
||||||
|
SysTick_Config(SystemCoreClock / 100); //configuration du systick à 10ms
|
||||||
|
|
||||||
|
// Assigne et défini le GPIO necessaire pour la gestion du shutdown.
|
||||||
|
Init_Structure.GPIO_Pin = GPIO_Pin_5;
|
||||||
|
Init_Structure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||||
|
Init_Structure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||||
|
GPIO_SetBits(GPIOB, GPIO_Pin_5);
|
||||||
|
GPIO_Init(GPIOB, &Init_Structure);
|
||||||
|
|
||||||
|
// Initialise la structure system Dumber
|
||||||
Dumber.BatteryPercentage = UNDEFINED;
|
Dumber.BatteryPercentage = UNDEFINED;
|
||||||
Dumber.BatteryCurrent = UNDEFINED;
|
Dumber.BatteryCurrent = UNDEFINED;
|
||||||
// Retourne le pourcentage de charge de la batterie
|
// Retourne le pourcentage de charge de la batterie
|
||||||
Dumber.StateSystem = IDLE; // Etat de la MAE
|
Dumber.StateSystem = STATE_IDLE; // État de la MAE
|
||||||
Dumber.AddOn = FALSE; // Un AddOn a été détecté
|
Dumber.AddOn = FALSE; // Un AddOn a été détecté
|
||||||
Dumber.BatterieChecking = FALSE; // On doit verifier la valeur de la batterie
|
Dumber.BatterieChecking = FALSE; // On doit vérifier la valeur de la batterie
|
||||||
Dumber.WatchDogStartEnable = FALSE; // Le Robot a été lancé en mode WithWatchDog ou WithoutWatchDog
|
Dumber.WatchDogStartEnable = FALSE; // Le Robot a été lancé en mode WithWatchDog ou WithoutWatchDog
|
||||||
|
Dumber.InvalidWatchdogResetCpt=0;
|
||||||
Dumber.cpt_watchdog = 0;
|
Dumber.cpt_watchdog = 0;
|
||||||
Dumber.cpt_systick = 0;
|
Dumber.cpt_systick = 0;
|
||||||
Dumber.cpt_inactivity = 0;
|
Dumber.cpt_inactivity = 0;
|
||||||
|
@ -107,27 +85,104 @@ void default_settings(void)
|
||||||
Dumber.stateBattery = 2;
|
Dumber.stateBattery = 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*@brief Configure le systick pour générer des interruptions toutes les 50ms.
|
|
||||||
*
|
|
||||||
*@param None
|
|
||||||
*@retval None
|
|
||||||
*/
|
|
||||||
void Configure_SysTick(void) {
|
|
||||||
SysTick_Config(SystemCoreClock / 100); //configuration du systick à 50ms
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Désactive les interruptions et entre dans une boucle while (1) en attendant l'extinction du CPU.
|
* @brief Désactive les interruptions et entre dans une boucle while (1) en attendant l'extinction du CPU.
|
||||||
* @param None
|
* @param None
|
||||||
*/
|
*/
|
||||||
|
|
||||||
void shutDown(void) {
|
void systemShutDown(void) {
|
||||||
__disable_irq();
|
__disable_irq();
|
||||||
GPIO_ResetBits(GPIOB, GPIO_Pin_5);
|
GPIO_ResetBits(GPIOB, GPIO_Pin_5);
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Bascule le système dans un état.
|
||||||
|
*
|
||||||
|
* @param state: Nouvel état
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
void systemChangeState(States state) {
|
||||||
|
switch (state)
|
||||||
|
{
|
||||||
|
case STATE_IDLE:
|
||||||
|
Dumber.StateSystem = STATE_IDLE;
|
||||||
|
Dumber.WatchDogStartEnable = FALSE;
|
||||||
|
Dumber.cpt_watchdog = 0;
|
||||||
|
Dumber.InvalidWatchdogResetCpt=0;
|
||||||
|
Dumber.cpt_systick = 0;
|
||||||
|
GPIO_SetBits(GPIOA,GPIO_Pin_12); // Désactive les encodeurs
|
||||||
|
motorCmdLeft(BRAKE, 0);
|
||||||
|
motorCmdRight(BRAKE, 0);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATE_RUN:
|
||||||
|
Dumber.StateSystem=STATE_RUN;
|
||||||
|
GPIO_ResetBits(GPIOA,GPIO_Pin_12); // Active les encodeurs
|
||||||
|
Dumber.cpt_watchdog=0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATE_LOW:
|
||||||
|
Dumber.StateSystem=STATE_LOW;
|
||||||
|
GPIO_ResetBits(GPIOA,GPIO_Pin_12); // Active les encodeurs
|
||||||
|
Dumber.cpt_watchdog=0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATE_DISABLE:
|
||||||
|
Dumber.StateSystem=STATE_DISABLE;
|
||||||
|
GPIO_SetBits(GPIOA,GPIO_Pin_12); // Désactive les encodeurs
|
||||||
|
motorCmdRight(BRAKE,0);
|
||||||
|
motorCmdLeft(BRAKE,0);
|
||||||
|
Dumber.WatchDogStartEnable = FALSE;
|
||||||
|
|
||||||
|
cptMesureHigh=0;
|
||||||
|
cptMesureLow=0;
|
||||||
|
cptMesureDisable=0;
|
||||||
|
Dumber.stateBattery= 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case STATE_WATCHDOG_DISABLE:
|
||||||
|
Dumber.StateSystem=STATE_WATCHDOG_DISABLE;
|
||||||
|
GPIO_SetBits(GPIOA,GPIO_Pin_12); // Désactive les encodeurs
|
||||||
|
motorCmdRight(BRAKE,0);
|
||||||
|
motorCmdLeft(BRAKE,0);
|
||||||
|
Dumber.WatchDogStartEnable = FALSE;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
/* Unknown state -> go into DISABLE */
|
||||||
|
systemChangeState(STATE_DISABLE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Remise à zéro du watchdog, en fonction de l'état en cours.
|
||||||
|
*
|
||||||
|
* @param None
|
||||||
|
* @retval None
|
||||||
|
*/
|
||||||
|
char systemResetWatchdog(void) {
|
||||||
|
char resultat =0;
|
||||||
|
|
||||||
|
if ((Dumber.StateSystem == STATE_RUN) || (Dumber.StateSystem == STATE_LOW)) { // si on est actif
|
||||||
|
if (Dumber.WatchDogStartEnable == TRUE) { // si le watchdog est lancé
|
||||||
|
if ((Dumber.cpt_watchdog >= WATCHDOG_MIN) && (Dumber.cpt_watchdog <= WATCHDOG_MAX)) { // si le watchdog est dans sa plage réarmable
|
||||||
|
|
||||||
|
Dumber.InvalidWatchdogResetCpt=0; // on remet le compteur d'erreur à zéro
|
||||||
|
} else {
|
||||||
|
Dumber.InvalidWatchdogResetCpt++; // on incrémente le compteur d'erreur
|
||||||
|
if (Dumber.InvalidWatchdogResetCpt>WATCHDOG_INVALID_COUNTER_MAX) // on a atteint le max d'erreur possible
|
||||||
|
systemChangeState(STATE_WATCHDOG_DISABLE); // le système est désactivé
|
||||||
|
}
|
||||||
|
|
||||||
|
Dumber.cpt_watchdog = 0; // on remet le watchdog à zéro
|
||||||
|
|
||||||
|
resultat=1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return resultat;
|
||||||
|
}
|
||||||
|
|
||||||
/** @addtogroup Gestion Gestions compteurs systick
|
/** @addtogroup Gestion Gestions compteurs systick
|
||||||
* @{
|
* @{
|
||||||
|
@ -136,56 +191,57 @@ void shutDown(void) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Interruption systick. Gestion des timers internes.
|
* @brief Interruption systick. Gestion des timers internes.
|
||||||
* Definis la vitesse de la loi d'asservissement.
|
* Défini la vitesse de la loi d'asservissement.
|
||||||
* Definis les valeurs de shutdown.
|
* Défini les valeurs de shutdown.
|
||||||
* Definis les valeurs d'inactivit<EFBFBD>s.
|
* Défini les valeurs d'inactivités.
|
||||||
* Definis la valeur de clignotement de la LED.
|
* Défini la valeur de clignotement de la LED.
|
||||||
*
|
*
|
||||||
* @note Tout ces temps sont calcul<EFBFBD> sous base du systick.
|
* @note Tout ces temps sont calculés sous base du systick.
|
||||||
*/
|
*/
|
||||||
void SysTick_Handler(void){
|
void SysTick_Handler(void){
|
||||||
Dumber.cpt_systick+=10;
|
Dumber.cpt_systick+=10;
|
||||||
Dumber.cpt_inactivity+=10;
|
Dumber.cpt_inactivity+=10;
|
||||||
|
|
||||||
if((Dumber.WatchDogStartEnable == TRUE) && (Dumber.StateSystem != IDLE)) Dumber.cpt_watchdog+=10;
|
|
||||||
|
|
||||||
|
|
||||||
if(asservissement == 1){
|
if(asservissement == 1){
|
||||||
regulation_vitesseD =1;
|
regulation_vitesseD =1;
|
||||||
regulation_vitesseG =1;
|
regulation_vitesseG =1;
|
||||||
}
|
}
|
||||||
if(Dumber.cpt_systick % TIMER_1s==0) Dumber.cpt_systick=0;
|
if(Dumber.cpt_systick % TIMER_1s==0) Dumber.cpt_systick=0;
|
||||||
|
|
||||||
if((Dumber.cpt_watchdog % 1000 ) >=975 || (Dumber.cpt_watchdog % 1000) <=25)
|
/* Gestion du watchdog */
|
||||||
watchDogState=TRUE;
|
if((Dumber.WatchDogStartEnable == TRUE) && (Dumber.StateSystem != STATE_IDLE))
|
||||||
else watchDogState=FALSE;
|
Dumber.cpt_watchdog+=10;
|
||||||
|
else
|
||||||
|
Dumber.cpt_watchdog=0;
|
||||||
|
|
||||||
|
if (Dumber.cpt_watchdog > WATCHDOG_MAX) {
|
||||||
|
Dumber.cpt_watchdog=30; // pour avoir toujours un watchdog cadancé à 1000 ms, et pas 1030ms
|
||||||
|
Dumber.InvalidWatchdogResetCpt++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Dumber.InvalidWatchdogResetCpt > WATCHDOG_INVALID_COUNTER_MAX) {
|
||||||
|
systemChangeState(STATE_WATCHDOG_DISABLE);
|
||||||
|
}
|
||||||
|
|
||||||
if(Dumber.cpt_systick % 500 == 0){
|
if(Dumber.cpt_systick % 500 == 0){
|
||||||
Dumber.acquisition=VOLTAGE;
|
Dumber.acquisition=VOLTAGE;
|
||||||
voltagePrepare();
|
batteryRefreshData();
|
||||||
}
|
}
|
||||||
|
|
||||||
if(Dumber.cpt_systick % 100==0){
|
/*if(Dumber.cpt_systick % 100==0){
|
||||||
etatLED++;
|
etatLED++;
|
||||||
|
|
||||||
if(etatLED ==12) etatLED = 0;
|
if (etatLED ==12) etatLED = 0;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
#if !defined (__NO_INACTIVITY_SHUTDOWN__)
|
#if !defined (__NO_INACTIVITY_SHUTDOWN__)
|
||||||
if(Dumber.cpt_inactivity>=120000){
|
if(Dumber.cpt_inactivity>=120000){
|
||||||
shutDown();
|
systemShutDown();
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
#warning "Shutdown after inactivity period disabled! Not for production !!!"
|
#warning "Shutdown after inactivity period disabled! Not for production !!!"
|
||||||
#endif /* __NO_INACTIVITY_SHUTDOWN__ */
|
#endif /* __NO_INACTIVITY_SHUTDOWN__ */
|
||||||
|
|
||||||
if(Dumber.cpt_watchdog>=TIMER_Watchdog)
|
|
||||||
{
|
|
||||||
Dumber.StateSystem=DISABLE;
|
|
||||||
cmdRightMotor(BRAKE,0);
|
|
||||||
cmdLeftMotor(BRAKE,0);
|
|
||||||
}
|
|
||||||
|
|
||||||
Dumber.flagSystick=1;
|
Dumber.flagSystick=1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,13 +27,13 @@
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
#ifndef system_dumby_H
|
#ifndef _SYSTEM_DUMBY_H_
|
||||||
#define system_dumby_H
|
#define _SYSTEM_DUMBY_H_
|
||||||
|
|
||||||
#include "stm32f10x.h"
|
#include "stm32f10x.h"
|
||||||
|
|
||||||
/* Declaration des Constantes */
|
/* Déclaration des Constantes */
|
||||||
#define VERSION "version 1.2\r"
|
#define VERSION "version 1.3\r"
|
||||||
|
|
||||||
#define SPI 10
|
#define SPI 10
|
||||||
#define USART 20
|
#define USART 20
|
||||||
|
@ -42,68 +42,47 @@
|
||||||
#define TRUE 40
|
#define TRUE 40
|
||||||
#define FALSE 50
|
#define FALSE 50
|
||||||
|
|
||||||
#define RUN 51
|
|
||||||
#define IDLE 52
|
|
||||||
#define LOW 53
|
|
||||||
#define DISABLE 54
|
|
||||||
|
|
||||||
#define VOLTAGE 98
|
#define VOLTAGE 98
|
||||||
#define CURRENT 99
|
#define CURRENT 99
|
||||||
|
|
||||||
#define UNDEFINED 101
|
#define UNDEFINED 101
|
||||||
|
|
||||||
//CMDE
|
|
||||||
|
|
||||||
#define PingCMD 'p'
|
|
||||||
#define ResetCMD 'r'
|
|
||||||
#define SetMotorCMD 'm'
|
|
||||||
#define StartWWatchDogCMD 'W'
|
|
||||||
#define ResetWatchdogCMD 'w'
|
|
||||||
#define GetBatteryVoltageCMD 'v'
|
|
||||||
#define GetVersionCMD 'V'
|
|
||||||
#define StartWithoutWatchCMD 'u'
|
|
||||||
#define MoveCMD 'M'
|
|
||||||
#define TurnCMD 'T'
|
|
||||||
#define BusyStateCMD 'b'
|
|
||||||
#define TestCMD 't'
|
|
||||||
#define DebugCMD 'a'
|
|
||||||
|
|
||||||
#define SystemCoreClock 8000000
|
|
||||||
|
|
||||||
//extern volatile uint16_t voltageADC;
|
|
||||||
|
|
||||||
#define TIMER_1s 1000 // 1 sec
|
#define TIMER_1s 1000 // 1 sec
|
||||||
#define TIMER_Watchdog 3050 //
|
#define TIMER_Watchdog 3050 //
|
||||||
#define TTMER_Inactivity 120000 // 2 min
|
#define TTMER_Inactivity 120000 // 2 min
|
||||||
|
|
||||||
#define RIGHT '>'
|
#define WATCHDOG_MIN 970
|
||||||
#define LEFT '<'
|
#define WATCHDOG_MAX 1030
|
||||||
|
#define WATCHDOG_INVALID_COUNTER_MAX 3
|
||||||
#define OK_ANS "O\r"
|
|
||||||
#define ERR_ANS "E\r"
|
|
||||||
#define UNKNOW_ANS "C\r"
|
|
||||||
#define BAT_OK "2\r"
|
|
||||||
#define BAT_LOW "1\r"
|
|
||||||
#define BAT_EMPTY "0\r"
|
|
||||||
|
|
||||||
#define COMMONSPEED 5
|
#define COMMONSPEED 5
|
||||||
#define LOWSPEED 2
|
#define LOWSPEED 2
|
||||||
#define HYPERVITESSE 7
|
#define HYPERVITESSE 7
|
||||||
|
|
||||||
/* Declaration de structure */
|
/* Déclaration de structure */
|
||||||
|
|
||||||
|
enum States {
|
||||||
|
STATE_IDLE = 0,
|
||||||
|
STATE_RUN,
|
||||||
|
STATE_LOW,
|
||||||
|
STATE_DISABLE,
|
||||||
|
STATE_WATCHDOG_DISABLE
|
||||||
|
};
|
||||||
|
typedef enum States States;
|
||||||
|
|
||||||
typedef struct Settings Settings;
|
|
||||||
struct Settings
|
struct Settings
|
||||||
{
|
{
|
||||||
// Information
|
// Information
|
||||||
uint16_t BatteryPercentage; // Retourne le pourcentage de charge de la batterie
|
uint16_t BatteryPercentage; // Retourne le pourcentage de charge de la batterie
|
||||||
uint16_t BatteryCurrent; //
|
uint16_t BatteryCurrent; //
|
||||||
char StateSystem; // Etat de la MAE
|
States StateSystem; // État de la MAE
|
||||||
char AddOn; // Un AddOn a <20>t<EFBFBD> d<>tect<63> // Les instructions seront sur le protocol SPI
|
char AddOn; // Un AddOn a été détecté
|
||||||
char BatterieChecking; // On doit verifier la valeur de la batterie
|
// Les instructions seront sur le protocole SPI
|
||||||
|
char BatterieChecking; // On doit vérifier la valeur de la batterie
|
||||||
uint16_t cpt_systick;
|
uint16_t cpt_systick;
|
||||||
char WatchDogStartEnable; // Le Robot a <20>t<EFBFBD> lanc<6E> en mode WithWatchDog ou WithoutWatchDog
|
char WatchDogStartEnable; // Le Robot a été lancé en mode WithWatchDog ou WithoutWatchDog
|
||||||
uint16_t cpt_watchdog;
|
uint16_t cpt_watchdog;
|
||||||
|
uint8_t InvalidWatchdogResetCpt; // Compteur de remise à zéro du watchdog en dehors du temps imparti
|
||||||
char busyState;
|
char busyState;
|
||||||
int cpt_inactivity;
|
int cpt_inactivity;
|
||||||
char acquisition;
|
char acquisition;
|
||||||
|
@ -111,24 +90,17 @@ struct Settings
|
||||||
char flagSystick;
|
char flagSystick;
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Declaration des variables systemes */
|
typedef struct Settings Settings;
|
||||||
extern uint16_t greenLight;
|
|
||||||
extern uint16_t redLight;
|
/* Déclaration des variables systèmes */
|
||||||
extern Settings Dumber;
|
extern Settings Dumber;
|
||||||
extern uint16_t asservissement;
|
|
||||||
extern uint16_t regulation_vitesseD, regulation_vitesseG;
|
|
||||||
extern uint16_t watchDogState;
|
|
||||||
extern char etatLED; // Tout les 200 ms cette variable s'incr<63>mente de 1 jusqu'<27> 5
|
|
||||||
extern char vClignotement1s;
|
|
||||||
extern char LEDON;
|
|
||||||
|
|
||||||
/* Prototype Fonctions */
|
/* Prototype Fonctions */
|
||||||
void default_settings(void);
|
void systemConfigure(void);
|
||||||
void MAP_PinShutDown(void);
|
void systemChangeState(States state);
|
||||||
void SysTick_Handler(void);
|
char systemResetWatchdog(void);
|
||||||
void Configure_SysTick(void);
|
void systemShutDown(void);
|
||||||
void shutDown(void);
|
|
||||||
|
|
||||||
#endif /* SYSTEM_DUMBY_H_ */
|
#endif /* _SYSTEM_DUMBY_H_ */
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
#include "system_dumby.h"
|
#include "system_dumby.h"
|
||||||
#include <stm32f10x.h>
|
#include <stm32f10x.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <usart.h>
|
||||||
|
|
||||||
#include "cmdManager.h"
|
#include "cmdManager.h"
|
||||||
|
|
||||||
#include "cmde_usart.h"
|
|
||||||
|
|
||||||
//#include "Battery.h"
|
//#include "Battery.h"
|
||||||
//#include "motor.h"
|
//#include "motor.h"
|
||||||
|
@ -64,28 +64,51 @@ volatile uint16_t tmp;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Configuration du GPIO pour l'uart.
|
* @brief Initialise l'UART avec les paramètres suivants : 9600 bauds / 1bits de stop / pas de partité ou de controle
|
||||||
*
|
|
||||||
* @note La fonction mapUsartPin va venir configurer le E/S du GPIO pour correspondre avec le sch<EFBFBD>ma electrique en ressource.
|
|
||||||
* PB7 Analog Input / PB6 Alternate function output.
|
|
||||||
*
|
*
|
||||||
* @param Aucun
|
* @param Aucun
|
||||||
* @retval Aucun
|
* @retval Aucun
|
||||||
*/
|
*/
|
||||||
void MAP_UsartPin()
|
|
||||||
{
|
|
||||||
GPIO_InitTypeDef Init_Structure;
|
|
||||||
|
|
||||||
/// Configure Output ALTERNATE FONCTION PPULL PORT B6 Tx
|
void usartConfigure(void)
|
||||||
|
{
|
||||||
|
USART_InitTypeDef USART_InitStructure;
|
||||||
|
GPIO_InitTypeDef Init_Structure;
|
||||||
|
NVIC_InitTypeDef NVIC_InitStructure;
|
||||||
|
|
||||||
|
// Configure les lignes d'E/S
|
||||||
|
// Configure Output ALTERNATE FONCTION PPULL PORT B6 Tx
|
||||||
Init_Structure.GPIO_Pin = GPIO_Pin_6;
|
Init_Structure.GPIO_Pin = GPIO_Pin_6;
|
||||||
Init_Structure.GPIO_Mode = GPIO_Mode_AF_PP;
|
Init_Structure.GPIO_Mode = GPIO_Mode_AF_PP;
|
||||||
Init_Structure.GPIO_Speed=GPIO_Speed_50MHz;
|
Init_Structure.GPIO_Speed=GPIO_Speed_50MHz;
|
||||||
GPIO_Init(GPIOB, &Init_Structure);
|
GPIO_Init(GPIOB, &Init_Structure);
|
||||||
|
|
||||||
/// Configure B7 Rx
|
// Configure B7 Rx
|
||||||
Init_Structure.GPIO_Pin = GPIO_Pin_7;
|
Init_Structure.GPIO_Pin = GPIO_Pin_7;
|
||||||
Init_Structure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
Init_Structure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||||
GPIO_Init(GPIOB, &Init_Structure);
|
GPIO_Init(GPIOB, &Init_Structure);
|
||||||
|
|
||||||
|
// Configure l'USART
|
||||||
|
USART_InitStructure.USART_BaudRate = 9600;
|
||||||
|
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
||||||
|
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
||||||
|
USART_InitStructure.USART_Parity = USART_Parity_No;
|
||||||
|
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
||||||
|
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
||||||
|
|
||||||
|
USART_Init(USART1, &USART_InitStructure);
|
||||||
|
|
||||||
|
USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE);
|
||||||
|
USART_Cmd(USART1, ENABLE);
|
||||||
|
GPIO_PinRemapConfig(GPIO_Remap_USART1,ENABLE);
|
||||||
|
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
|
||||||
|
|
||||||
|
// configure les interruptions de l'USART
|
||||||
|
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
|
||||||
|
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
||||||
|
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||||
|
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||||
|
NVIC_Init(&NVIC_InitStructure);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,7 +117,7 @@ void MAP_UsartPin()
|
||||||
* @param Aucun
|
* @param Aucun
|
||||||
* @retval Aucun
|
* @retval Aucun
|
||||||
*/
|
*/
|
||||||
void INIT_DMASend(uint16_t bufferSize)
|
void usartInitDMA(uint16_t bufferSize)
|
||||||
{
|
{
|
||||||
DMA_InitTypeDef DMA_InitStructure;
|
DMA_InitTypeDef DMA_InitStructure;
|
||||||
|
|
||||||
|
@ -110,57 +133,14 @@ void INIT_DMASend(uint16_t bufferSize)
|
||||||
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
|
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
|
||||||
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
|
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
|
||||||
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
|
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
|
||||||
|
|
||||||
DMA_Init(DMA1_Channel4, &DMA_InitStructure);
|
DMA_Init(DMA1_Channel4, &DMA_InitStructure);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Configure l'IT sur la reception d'un caractère sur l'uart.
|
|
||||||
*
|
|
||||||
* @param Aucun
|
|
||||||
* @retval Aucun
|
|
||||||
*/
|
|
||||||
void INIT_IT_UsartReceive(void)
|
|
||||||
{
|
|
||||||
NVIC_InitTypeDef NVIC_InitStructure;
|
|
||||||
|
|
||||||
/* Enable the USARTz Interrupt */
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannel = USART1_IRQn;
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
|
||||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
|
||||||
NVIC_Init(&NVIC_InitStructure);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @}
|
* @}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
|
||||||
* @brief Initialise l'UART avec les paramètres suivants : 9600 bauds / 1bits de stop / pas de partité ou de controle
|
|
||||||
*
|
|
||||||
* @param Aucun
|
|
||||||
* @retval Aucun
|
|
||||||
*/
|
|
||||||
|
|
||||||
void INIT_USART(void)
|
|
||||||
{
|
|
||||||
USART_InitTypeDef USART_InitStructure;
|
|
||||||
|
|
||||||
USART_InitStructure.USART_BaudRate = 9600;
|
|
||||||
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
|
|
||||||
USART_InitStructure.USART_StopBits = USART_StopBits_1;
|
|
||||||
USART_InitStructure.USART_Parity = USART_Parity_No;
|
|
||||||
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
|
|
||||||
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
|
|
||||||
|
|
||||||
USART_Init(USART1, &USART_InitStructure);
|
|
||||||
|
|
||||||
USART_DMACmd(USART1, USART_DMAReq_Tx, ENABLE);
|
|
||||||
USART_Cmd(USART1, ENABLE);
|
|
||||||
GPIO_PinRemapConfig(GPIO_Remap_USART1,ENABLE);
|
|
||||||
USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** @addtogroup Function Send - Receive
|
/** @addtogroup Function Send - Receive
|
||||||
* @{
|
* @{
|
||||||
*/
|
*/
|
||||||
|
@ -186,15 +166,12 @@ void USART1_IRQHandler(void)
|
||||||
if (cpt_Rx < 16)
|
if (cpt_Rx < 16)
|
||||||
cpt_Rx++;
|
cpt_Rx++;
|
||||||
|
|
||||||
if (receiptString[cpt_Rx - 1] == 13) {
|
if (receiptString[cpt_Rx - 1] == '\r') {
|
||||||
if (verifyCheckSum() == 0) {
|
cmdManage();
|
||||||
manageCmd();
|
|
||||||
} else
|
|
||||||
strcpy(sendString, UNKNOW_ANS);
|
|
||||||
|
|
||||||
if (Dumber.AddOn == FALSE) {
|
if (Dumber.AddOn == FALSE) {
|
||||||
inclusionCheckSum();
|
cmdAddChecksum();
|
||||||
sendDataUSART();
|
usartSendData(); // Fonction bloquante
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < cpt_Rx + 1; i++)
|
for (i = 0; i < cpt_Rx + 1; i++)
|
||||||
|
@ -221,10 +198,10 @@ void USART1_IRQHandler(void)
|
||||||
* @param Aucun
|
* @param Aucun
|
||||||
* @retval Aucun
|
* @retval Aucun
|
||||||
*/
|
*/
|
||||||
void sendDataUSART(void){
|
void usartSendData(void){
|
||||||
int taille;
|
int taille;
|
||||||
for(taille = 0; sendString[taille]!= '\r'; taille++);
|
for(taille = 0; sendString[taille]!= '\r'; taille++);
|
||||||
INIT_DMASend(taille+1);
|
usartInitDMA(taille+1);
|
||||||
DMA_Cmd(DMA1_Channel4, ENABLE);
|
DMA_Cmd(DMA1_Channel4, ENABLE);
|
||||||
while (DMA_GetFlagStatus(DMA1_FLAG_TC4) == RESET);
|
while (DMA_GetFlagStatus(DMA1_FLAG_TC4) == RESET);
|
||||||
for(i=0; i<TBuffer;i++)
|
for(i=0; i<TBuffer;i++)
|
|
@ -13,26 +13,24 @@
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
******************************************************************************
|
******************************************************************************
|
||||||
*/
|
*/
|
||||||
#ifndef cmde_usart_H
|
#ifndef _USART_H_
|
||||||
#define cmde_usart_H
|
#define _USART_H_
|
||||||
|
|
||||||
#include "stm32f10x.h"
|
#include "stm32f10x.h"
|
||||||
|
|
||||||
#define TBuffer 30
|
#define TBuffer 30
|
||||||
|
|
||||||
/* Prototype des fonctions */
|
/* Variables externes nécessaire*/
|
||||||
|
|
||||||
void INIT_IT_UsartReceive(void);
|
|
||||||
void INIT_DMASend(uint16_t bufferSize);
|
|
||||||
void sendDataUSART(void);
|
|
||||||
void INIT_USART(void);
|
|
||||||
void MAP_UsartPin(void);
|
|
||||||
|
|
||||||
/* Variable Externes necessair e*/
|
|
||||||
|
|
||||||
extern char sendString[TBuffer];
|
extern char sendString[TBuffer];
|
||||||
extern char receiptString[TBuffer];
|
extern char receiptString[TBuffer];
|
||||||
extern uint16_t cpt_Rx;
|
extern uint16_t cpt_Rx;
|
||||||
|
|
||||||
#endif /* CMD_UART_H_ */
|
/* Prototype des fonctions */
|
||||||
|
void INIT_IT_UsartReceive(void);
|
||||||
|
void usartInitDMA(uint16_t bufferSize);
|
||||||
|
void usartSendData(void);
|
||||||
|
void usartConfigure(void);
|
||||||
|
void MAP_UsartPin(void);
|
||||||
|
|
||||||
|
#endif /* _USART_H_ */
|
||||||
|
|
|
@ -118,7 +118,7 @@
|
||||||
/* #define SYSCLK_FREQ_36MHz 36000000 */
|
/* #define SYSCLK_FREQ_36MHz 36000000 */
|
||||||
/* #define SYSCLK_FREQ_48MHz 48000000 */
|
/* #define SYSCLK_FREQ_48MHz 48000000 */
|
||||||
/* #define SYSCLK_FREQ_56MHz 56000000 */
|
/* #define SYSCLK_FREQ_56MHz 56000000 */
|
||||||
#define SYSCLK_FREQ_72MHz 72000000
|
/* #define SYSCLK_FREQ_72MHz 72000000 */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*!< Uncomment the following line if you need to use external SRAM mounted
|
/*!< Uncomment the following line if you need to use external SRAM mounted
|
||||||
|
|
Loading…
Reference in a new issue