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">
|
||||
<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="USE_STDPERIPH_DRIVER"/>
|
||||
<listOptionValue builtIn="false" value="__NO_INACTIVITY_SHUTDOWN__"/>
|
||||
<listOptionValue builtIn="false" value="USE_STDPERIPH_DRIVER"/>
|
||||
</option>
|
||||
<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"/>
|
||||
|
|
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
|
||||
* @date 16-mai-2016
|
||||
* @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.
|
||||
* Configure une interruption externe pour d<EFBFBD>tecter le branchement
|
||||
* Configure une interruption externe pour détecter le branchement
|
||||
* du chargeur.
|
||||
******************************************************************************
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include <battery.h>
|
||||
#include "system_dumby.h"
|
||||
#include "motor.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;
|
||||
__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
|
||||
* @{
|
||||
|
@ -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
|
||||
* le sch<EFBFBD>ma electrique en ressource. La fonction initialise aussi l'interruption EXTI
|
||||
* de la d<EFBFBD>tection du chargeur.
|
||||
* le schéma electrique en ressource. La fonction initialise aussi l'interruption EXTI
|
||||
* de la détection du chargeur.
|
||||
*
|
||||
* @note A3 en output alternate function.
|
||||
* 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;
|
||||
NVIC_InitTypeDef NVIC_InitStructure;
|
||||
EXTI_InitTypeDef EXTI_InitStructure;
|
||||
ADC_InitTypeDef ADC_InitStructure;
|
||||
|
||||
Init_Structure.GPIO_Pin = GPIO_Pin_3;
|
||||
Init_Structure.GPIO_Speed = GPIO_Speed_10MHz;
|
||||
|
@ -91,20 +97,9 @@ void MAP_batteryPin(void)
|
|||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
NVIC_Init(&NVIC_InitStructure);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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
|
||||
*
|
||||
*/
|
||||
// Initialise la dma pour stocker les valeur dans ADCConvertedValue.
|
||||
|
||||
void DMA_BAT(void)
|
||||
{
|
||||
/* DMA1 channel1 configuration ----------------------------------------------*/
|
||||
DMA_DeInit(DMA1_Channel1);
|
||||
DMA_BAT_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)&(ADC1->DR); // ADC1_DR_Address;
|
||||
DMA_BAT_InitStructure.DMA_MemoryBaseAddr = (uint32_t)&ADCConvertedValue;
|
||||
|
@ -121,70 +116,8 @@ void DMA_BAT(void)
|
|||
|
||||
DMA_Cmd(DMA1_Channel1, ENABLE);
|
||||
DMA_ITConfig(DMA1_Channel1, DMA_IT_TC, ENABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @}
|
||||
*/
|
||||
|
||||
/** @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 ------------------------------------------------------*/
|
||||
// Configuration et Calibration de l'ADC1 sur 1 channel.
|
||||
ADC_InitStructure.ADC_Mode = ADC_Mode_Independent;
|
||||
ADC_InitStructure.ADC_ScanConvMode = ENABLE;
|
||||
ADC_InitStructure.ADC_ContinuousConvMode = ENABLE;
|
||||
|
@ -204,21 +137,8 @@ void ADC1_CONFIG(void)
|
|||
while(ADC_GetCalibrationStatus(ADC1));
|
||||
|
||||
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
/* Enable the ADC1 DMA Interrupt */
|
||||
NVIC_InitStructure.NVIC_IRQChannel = DMA1_Channel1_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;
|
||||
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
|
||||
* @{
|
||||
|
@ -237,8 +270,8 @@ void INIT_IT_DMA(void)
|
|||
|
||||
|
||||
/**
|
||||
* @brief Interruption Handler. Qui va faire la moyenne des derni<EFBFBD>res
|
||||
* acquisitions lorsque la DMA <EFBFBD> rempli son buffer.
|
||||
* @brief Interruption Handler. Qui va faire la moyenne des dernières
|
||||
* acquisitions lorsque la DMA à rempli son buffer.
|
||||
*
|
||||
* @param None
|
||||
* @retval None
|
||||
|
@ -256,8 +289,8 @@ void DMA1_Channel1_IRQHandler(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Interruption qui donne l'ordre d'<EFBFBD>teindre le robot.
|
||||
* L'IT se d<EFBFBD>clenche lorsque le chargeur est branch<EFBFBD>.
|
||||
* @brief Interruption qui donne l'ordre d'éteindre le robot.
|
||||
* L'IT se déclenche lorsque le chargeur est branché.
|
||||
*
|
||||
* @param None
|
||||
* @retval None
|
||||
|
@ -265,7 +298,7 @@ void DMA1_Channel1_IRQHandler(void)
|
|||
*/
|
||||
void EXTI15_10_IRQHandler(void)
|
||||
{
|
||||
shutDown();
|
||||
systemShutDown();
|
||||
while (1);
|
||||
}
|
||||
|
||||
|
|
|
@ -14,24 +14,40 @@
|
|||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef Battery_H
|
||||
#define Battery_H
|
||||
#ifndef _BATTERY_H_
|
||||
#define _BATTERY_H_
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
#define VOLTAGE_BUFFER_SIZE 64
|
||||
extern __IO uint16_t ADCConvertedValue[VOLTAGE_BUFFER_SIZE];
|
||||
|
||||
#define VBAT_SEUIL_LOW 0x878
|
||||
#define VBAT_SEUIL_DISABLE 0x7CA
|
||||
#define VBAT_SEUIL_EMERGENCY_HALT 0x6E0
|
||||
|
||||
void MAP_batteryPin(void);
|
||||
void DMA_BAT(void);
|
||||
void ADC1_CONFIG(void);
|
||||
void INIT_IT_DMA(void);
|
||||
void startACQDMA(void);
|
||||
void voltagePrepare(void);
|
||||
#define COMPTEUR_SEUIL_HIGH 8
|
||||
#define COMPTEUR_SEUIL_LOW 8
|
||||
#define COMPTEUR_SEUIL_DISABLE 8
|
||||
#define COMPTEUR_SEUIL_EMERGENCY_HALT 3000
|
||||
|
||||
#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 "cmdManager.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "cmde_usart.h"
|
||||
#include "cmdManager.h"
|
||||
#include "battery.h"
|
||||
#include "motor.h"
|
||||
#include "system_dumby.h"
|
||||
#include "usart.h"
|
||||
|
||||
/** @addtogroup Projects
|
||||
* @{
|
||||
|
@ -36,9 +34,28 @@
|
|||
* @{
|
||||
*/
|
||||
|
||||
volatile unsigned char checksum;
|
||||
volatile int length;
|
||||
uint16_t j;
|
||||
/* Definition des commandes */
|
||||
|
||||
#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
|
||||
* @{
|
||||
|
@ -53,8 +70,10 @@ uint16_t j;
|
|||
* @retval 0 ou 1
|
||||
*
|
||||
*/
|
||||
void inclusionCheckSum(void) {
|
||||
checksum = 0;
|
||||
void cmdAddChecksum(void) {
|
||||
uint16_t j;
|
||||
unsigned char checksum=0;
|
||||
|
||||
for (j = 0; sendString[j] != '\r'; j++)
|
||||
checksum ^= sendString[j];
|
||||
if (checksum == '\r')
|
||||
|
@ -73,20 +92,23 @@ void inclusionCheckSum(void) {
|
|||
* @retval 0 ou 1
|
||||
*
|
||||
*/
|
||||
char verifyCheckSum(void) {
|
||||
uint16_t j, lenght;
|
||||
checksum = 0;
|
||||
lenght = strlen(receiptString);
|
||||
for (j = 0; j < lenght - 2; j++) {
|
||||
char cmdVerifyChecksum(void) {
|
||||
uint16_t j;
|
||||
uint16_t length;
|
||||
unsigned char checksum=0;
|
||||
|
||||
length = strlen(receiptString);
|
||||
for (j = 0; j < length - 2; j++) {
|
||||
checksum ^= receiptString[j];
|
||||
}
|
||||
if (checksum == '\r')
|
||||
checksum++;
|
||||
|
||||
if (receiptString[j] == checksum) {
|
||||
receiptString[lenght - 2] = 13;
|
||||
receiptString[lenght - 1] = 0;
|
||||
receiptString[lenght] = 0;
|
||||
receiptString[length - 2] = 13;
|
||||
receiptString[length - 1] = 0;
|
||||
receiptString[length] = 0;
|
||||
|
||||
return 0;
|
||||
} else
|
||||
return 1;
|
||||
|
@ -112,56 +134,66 @@ char verifyCheckSum(void) {
|
|||
* @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]) {
|
||||
case PingCMD:
|
||||
actionPing();
|
||||
cmdPingAction();
|
||||
break;
|
||||
|
||||
case ResetCMD:
|
||||
actionReset();
|
||||
cmdResetAction();
|
||||
break;
|
||||
|
||||
case StartWWatchDogCMD:
|
||||
actionStartWithWD();
|
||||
cmdStartWithWatchdogAction();
|
||||
break;
|
||||
|
||||
case ResetWatchdogCMD:
|
||||
actionResetWD();
|
||||
cmdResetWatchdogAction();
|
||||
break;
|
||||
|
||||
case GetBatteryVoltageCMD:
|
||||
actionBatteryVoltage();
|
||||
cmdBatteryVoltageAction();
|
||||
break;
|
||||
|
||||
case GetVersionCMD:
|
||||
actionVersion();
|
||||
cmdVersionAction();
|
||||
break;
|
||||
|
||||
case StartWithoutWatchCMD:
|
||||
actionStartWWD();
|
||||
cmdStartWithoutWatchdogAction();
|
||||
break;
|
||||
|
||||
case MoveCMD:
|
||||
actionMove();
|
||||
cmdMoveAction();
|
||||
break;
|
||||
|
||||
case TurnCMD:
|
||||
actionTurn();
|
||||
cmdTurnAction();
|
||||
break;
|
||||
|
||||
case BusyStateCMD:
|
||||
actionBusyState();
|
||||
cmdBusyStateAction();
|
||||
break;
|
||||
|
||||
case 'a':
|
||||
actionDebug();
|
||||
cmdDebugAction();
|
||||
break;
|
||||
|
||||
default:
|
||||
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
|
||||
*/
|
||||
|
||||
void actionPing(void) {
|
||||
if (receiptString[1] == 13)
|
||||
void cmdPingAction(void) {
|
||||
if (receiptString[1] == '\r')
|
||||
strcpy(sendString, OK_ANS);
|
||||
else
|
||||
strcpy(sendString, ERR_ANS);
|
||||
|
@ -194,13 +226,8 @@ void actionPing(void) {
|
|||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void actionReset(void) {
|
||||
Dumber.StateSystem = IDLE;
|
||||
Dumber.WatchDogStartEnable = TRUE;
|
||||
Dumber.cpt_watchdog = 0;
|
||||
Dumber.cpt_systick = 0;
|
||||
cmdLeftMotor(BRAKE, 0);
|
||||
cmdRightMotor(BRAKE, 0);
|
||||
void cmdResetAction(void) {
|
||||
systemChangeState(STATE_IDLE);
|
||||
strcpy(sendString, OK_ANS);
|
||||
}
|
||||
|
||||
|
@ -210,8 +237,8 @@ void actionReset(void) {
|
|||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void actionVersion(void) {
|
||||
if (receiptString[1] == 13)
|
||||
void cmdVersionAction(void) {
|
||||
if (receiptString[1] == '\r')
|
||||
strcpy(sendString, VERSION);
|
||||
else
|
||||
strcpy(sendString, ERR_ANS);
|
||||
|
@ -225,30 +252,27 @@ void actionVersion(void) {
|
|||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void actionBusyState(void) {
|
||||
if (Dumber.StateSystem == RUN || Dumber.StateSystem == LOW) {
|
||||
void cmdBusyStateAction(void) {
|
||||
if ((Dumber.StateSystem == STATE_RUN) || (Dumber.StateSystem == STATE_LOW)) {
|
||||
if (Dumber.busyState == TRUE)
|
||||
strcpy(sendString, "1");
|
||||
strcpy(sendString, "1\r");
|
||||
else
|
||||
strcpy(sendString, "0");
|
||||
strcpy(sendString, "0\r");
|
||||
} else {
|
||||
strcpy(sendString, ERR_ANS);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Effectue une remise à zero du watchdog.
|
||||
* @brief Effectue une remise à zéro du watchdog.
|
||||
*
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void actionResetWD(void) {
|
||||
if (Dumber.StateSystem == RUN && watchDogState==TRUE){
|
||||
Dumber.cpt_watchdog = 0;
|
||||
void cmdResetWatchdogAction(void) {
|
||||
if (systemResetWatchdog()!=0) { // Réussite
|
||||
strcpy(sendString, OK_ANS);
|
||||
}
|
||||
else
|
||||
strcpy(sendString, ERR_ANS);
|
||||
} else strcpy(sendString, ERR_ANS);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -260,11 +284,11 @@ void actionResetWD(void) {
|
|||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void actionStartWithWD(void) {
|
||||
if (Dumber.StateSystem == IDLE && receiptString[1] == 13) {
|
||||
strcpy(sendString, OK_ANS);
|
||||
void cmdStartWithWatchdogAction(void) {
|
||||
if (Dumber.StateSystem == STATE_IDLE && receiptString[1] == '\r') {
|
||||
Dumber.WatchDogStartEnable = TRUE;
|
||||
Dumber.StateSystem = RUN;
|
||||
systemChangeState(STATE_RUN);
|
||||
strcpy(sendString, OK_ANS);
|
||||
} else
|
||||
strcpy(sendString, ERR_ANS);
|
||||
}
|
||||
|
@ -276,11 +300,11 @@ void actionStartWithWD(void) {
|
|||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void actionStartWWD(void) {
|
||||
if (Dumber.StateSystem == IDLE && receiptString[1] == 13) {
|
||||
strcpy(sendString, OK_ANS);
|
||||
void cmdStartWithoutWatchdogAction(void) {
|
||||
if (Dumber.StateSystem == STATE_IDLE && receiptString[1] == '\r') {
|
||||
Dumber.WatchDogStartEnable = FALSE;
|
||||
Dumber.StateSystem = RUN;
|
||||
systemChangeState(STATE_RUN);
|
||||
strcpy(sendString, OK_ANS);
|
||||
} else
|
||||
strcpy(sendString, ERR_ANS);
|
||||
}
|
||||
|
@ -295,8 +319,8 @@ void actionStartWWD(void) {
|
|||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void actionMove(void) {
|
||||
if (Dumber.StateSystem == RUN || Dumber.StateSystem == LOW) {
|
||||
void cmdMoveAction(void) {
|
||||
if (Dumber.StateSystem == STATE_RUN || Dumber.StateSystem == STATE_LOW) {
|
||||
int laps;
|
||||
uint16_t testReception = sscanf(receiptString, "M=%i\r", &laps);
|
||||
unsigned char mod = 0;
|
||||
|
@ -313,8 +337,10 @@ void actionMove(void) {
|
|||
mod = FORWARD;
|
||||
|
||||
laps = laps * 2;
|
||||
regulationMoteur(mod, mod, (unsigned) laps, (unsigned) laps,
|
||||
|
||||
motorRegulation(mod, mod, (unsigned) laps, (unsigned) laps,
|
||||
COMMONSPEED, COMMONSPEED);
|
||||
|
||||
strcpy(sendString, OK_ANS);
|
||||
} else
|
||||
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
|
||||
* ou negatif.
|
||||
*
|
||||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void actionTurn(void) {
|
||||
if (Dumber.StateSystem == RUN || Dumber.StateSystem == LOW) {
|
||||
void cmdTurnAction(void) {
|
||||
if (Dumber.StateSystem == STATE_RUN || Dumber.StateSystem == STATE_LOW) {
|
||||
int degree;
|
||||
uint16_t testReception = sscanf(receiptString, "T=%i\r", °ree);
|
||||
tourPositionG = 0;
|
||||
tourPositionD = 0;
|
||||
|
||||
if (testReception == 1) {
|
||||
degree = degree * 1.40;
|
||||
Dumber.cpt_inactivity = 0;
|
||||
Dumber.busyState = TRUE;
|
||||
|
||||
if (degree < 0) {
|
||||
degree = degree * -1;
|
||||
if (degree < 30)
|
||||
regulationMoteur(FORWARD, REVERSE, (unsigned) degree,
|
||||
motorRegulation(FORWARD, REVERSE, (unsigned) degree,
|
||||
(unsigned) degree, LOWSPEED, LOWSPEED);
|
||||
else
|
||||
regulationMoteur(FORWARD, REVERSE, (unsigned) degree,
|
||||
(unsigned) degree, COMMONSPEED, COMMONSPEED);
|
||||
} else {
|
||||
if (degree < 30)
|
||||
regulationMoteur(REVERSE, FORWARD, (unsigned) degree,
|
||||
motorRegulation(REVERSE, FORWARD, (unsigned) degree,
|
||||
(unsigned) degree, LOWSPEED, LOWSPEED);
|
||||
else
|
||||
regulationMoteur(REVERSE, FORWARD, (unsigned) degree,
|
||||
(unsigned) degree, COMMONSPEED, COMMONSPEED);
|
||||
}
|
||||
strcpy(sendString, OK_ANS);
|
||||
} else
|
||||
strcpy(sendString, ERR_ANS);
|
||||
}
|
||||
|
@ -370,7 +391,7 @@ void actionTurn(void) {
|
|||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void actionBatteryVoltage(void) {
|
||||
void cmdBatteryVoltageAction(void) {
|
||||
char battery[2];
|
||||
battery[0] = Dumber.stateBattery + '0';
|
||||
battery[1] = '\r';
|
||||
|
@ -386,12 +407,15 @@ void actionBatteryVoltage(void) {
|
|||
* @param None
|
||||
* @retval None
|
||||
*/
|
||||
void actionDebug(void) {
|
||||
void cmdDebugAction(void) {
|
||||
uint8_t j;
|
||||
|
||||
sprintf(sendString, "Th-D=%u G=%u\r", tourPositionD, tourPositionG);
|
||||
sendDataUSART();
|
||||
usartSendData();
|
||||
|
||||
for (j = 0; j < 200; j++);
|
||||
sprintf(sendString, "Re-D=%u G=%u\r", G_lapsRight, G_lapsLeft);
|
||||
sendDataUSART();
|
||||
usartSendData();
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -6,35 +6,35 @@
|
|||
* @date 19-June-2017
|
||||
* @brief Gestion de commande reçu via l'uart
|
||||
*
|
||||
* Traite les chaines de caractére reçu par l'uart.
|
||||
* Permet de verifier les erreurs de checksum,
|
||||
* Traite les chaînes de caractère reçu par l'uart.
|
||||
* Permet de vérifier les erreurs de checksum,
|
||||
* de traiter les valeurs retours.
|
||||
*
|
||||
*@attention Utilise les variables globals - receiptString - sendString
|
||||
* @attention Utilise les variables globales - receiptString - sendString
|
||||
*
|
||||
******************************************************************************
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
#ifndef CMD_MANAGER_H_
|
||||
#define CMD_MANAGER_H_
|
||||
#ifndef _CMD_MANAGER_H_
|
||||
#define _CMD_MANAGER_H_
|
||||
|
||||
#include <stm32f10x.h>
|
||||
|
||||
void manageCmd(void);
|
||||
char verifyCheckSum(void);
|
||||
void inclusionCheckSum(void);
|
||||
void actionReset(void);
|
||||
void actionBusyState(void);
|
||||
void actionPing(void);
|
||||
void actionVersion(void);
|
||||
void actionStartWWD(void);
|
||||
void actionMove(void);
|
||||
void actionTurn(void);
|
||||
void actionBatteryVoltage(void);
|
||||
void actionStartWithWD(void);
|
||||
void actionResetWD(void);
|
||||
void actionDebug(void);
|
||||
void cmdManage(void);
|
||||
char cmdVerifyChecksum(void);
|
||||
void cmdAddChecksum(void);
|
||||
void cmdResetAction(void);
|
||||
void cmdBusyStateAction(void);
|
||||
void cmdPingAction(void);
|
||||
void cmdVersionAction(void);
|
||||
void cmdStartWithoutWatchdogAction(void);
|
||||
void cmdMoveAction(void);
|
||||
void cmdTurnAction(void);
|
||||
void cmdBatteryVoltageAction(void);
|
||||
void cmdStartWithWatchdogAction(void);
|
||||
void cmdResetWatchdogAction(void);
|
||||
void cmdDebugAction(void);
|
||||
|
||||
#endif /* CMD_MANAGER_H_ */
|
||||
#endif /* _CMD_MANAGER_H_ */
|
||||
|
||||
|
|
|
@ -11,11 +11,12 @@
|
|||
******************************************************************************
|
||||
*/
|
||||
|
||||
#include "stm32f10x.h" // Device header
|
||||
#include "debug.h"
|
||||
#include <stm32f10x.h> // Device header
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "debug.h"
|
||||
|
||||
/** @addtogroup Projects
|
||||
* @{
|
||||
*/
|
||||
|
|
|
@ -13,9 +13,8 @@
|
|||
*/
|
||||
|
||||
#include <stm32f10x.h>
|
||||
#include "led.h"
|
||||
|
||||
#include "system_dumby.h"
|
||||
#include "led.h"
|
||||
|
||||
/** @addtogroup Projects
|
||||
* @{
|
||||
|
@ -33,12 +32,23 @@
|
|||
|
||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseLED;
|
||||
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
|
||||
*/
|
||||
void MAP_LEDpin(void)
|
||||
void ledConfigure(void)
|
||||
{
|
||||
GPIO_InitTypeDef Init_Structure;
|
||||
|
||||
|
@ -47,6 +57,9 @@ void MAP_LEDpin(void)
|
|||
Init_Structure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||
Init_Structure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||
GPIO_Init(GPIOB, &Init_Structure);
|
||||
|
||||
etatLED = 1;
|
||||
LEDON =0;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -60,7 +73,7 @@ void MAP_LEDpin(void)
|
|||
* @brief Allume une LED de couleur orange.
|
||||
* @param Aucun
|
||||
*/
|
||||
void LEDorange(void)
|
||||
void ledOrangeOn(void)
|
||||
{
|
||||
GPIO_SetBits(GPIOB, GPIO_Pin_1);
|
||||
GPIO_SetBits(GPIOB,GPIO_Pin_0);
|
||||
|
@ -70,7 +83,7 @@ void LEDorange(void)
|
|||
* @brief Allume une LED de couleur rouge.
|
||||
* @param Aucun
|
||||
*/
|
||||
void LEDred(void)
|
||||
void ledRedOn(void)
|
||||
{
|
||||
GPIO_ResetBits(GPIOB, GPIO_Pin_1);
|
||||
GPIO_SetBits(GPIOB,GPIO_Pin_0);
|
||||
|
@ -80,7 +93,7 @@ void LEDred(void)
|
|||
* @brief Allume une LED de couleur verte.
|
||||
* @param Aucun
|
||||
*/
|
||||
void LEDgreen(void)
|
||||
void ledGreenOn(void)
|
||||
{
|
||||
|
||||
GPIO_SetBits(GPIOB, GPIO_Pin_1);
|
||||
|
@ -88,15 +101,106 @@ void LEDgreen(void)
|
|||
}
|
||||
|
||||
/**
|
||||
* @brief Eteint la LED.
|
||||
* @brief Eteint les LED.
|
||||
* @param Aucun
|
||||
*/
|
||||
void LEDoff(void)
|
||||
void ledOff(void)
|
||||
{
|
||||
GPIO_ResetBits(GPIOB,GPIO_Pin_0);
|
||||
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
|
||||
#define LED_H
|
||||
#ifndef _LED_H_
|
||||
#define _LED_H_
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
#define RED 255
|
||||
#define GREEN 250
|
||||
|
||||
void MAP_LEDpin(void);
|
||||
void INIT_TIM3Led(void);
|
||||
void LEDgreen(void);
|
||||
void LEDred(void);
|
||||
void LEDoff(void);
|
||||
void LEDorange(void);
|
||||
extern char etatLED; // Tout les 200 ms cette variable s'incrémente de 1 jusqu'à 5
|
||||
extern char LEDON;
|
||||
|
||||
#endif /* LED_H */
|
||||
void ledConfigure(void);
|
||||
void ledManagement(States state, char batteryState);
|
||||
|
||||
#endif /* _LED_H_ */
|
||||
|
|
|
@ -5,110 +5,46 @@
|
|||
* @version V1.0
|
||||
* @date 16-mai-2016
|
||||
* @brief Programme principale du robot Dumby.
|
||||
* Dumby est un robot utilis<EFBFBD> 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
|
||||
* derni<EFBFBD>re version de son software. Le micro-controleur utilis<EFBFBD> est
|
||||
* Dumby est un robot utilisé par l'INSA toulouse lors des TPs de temps
|
||||
* Réel en 4éme année. Ce fichier est le fichier principal et la
|
||||
* dernière version de son software. Le micro-controleur utilisé est
|
||||
* un STM32-103-RB.
|
||||
* Il comporte comme fonctionnalit<EFBFBD>e entre autre :
|
||||
* Il comporte comme fonctionnalitée entre autre :
|
||||
* - Asservisement des moteurs
|
||||
* - Detection de tension de batterie
|
||||
* - Gestion de commande via l'uart
|
||||
* 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
|
||||
* du robot.
|
||||
******************************************************************************
|
||||
*/
|
||||
#include <battery.h>
|
||||
|
||||
#include <stm32f10x.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "system_dumby.h"
|
||||
#include "cmde_usart.h"
|
||||
#include "motor.h"
|
||||
#include "led.h"
|
||||
|
||||
#include "usart.h"
|
||||
#include "battery.h"
|
||||
#include "debug.h"
|
||||
|
||||
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 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);
|
||||
void mainConfigureClock(void);
|
||||
void mainPeripheralsInit(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
|
||||
* @retval None
|
||||
*/
|
||||
int main(void)
|
||||
{
|
||||
uint16_t k;
|
||||
/**
|
||||
* Initialisation
|
||||
*/
|
||||
|
||||
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
|
||||
mainPeripheralsInit();
|
||||
|
||||
while (1){
|
||||
__WFE(); // Bascule la puce en sleep mode
|
||||
|
@ -117,157 +53,23 @@ int main(void)
|
|||
{
|
||||
Dumber.flagSystick = 0;
|
||||
|
||||
if(Dumber.acquisition==VOLTAGE && Dumber.BatterieChecking==TRUE)
|
||||
{
|
||||
vbatLowerVal = 0xFFF;
|
||||
vbatHighVal = 0;
|
||||
/* Gestion des niveaux de batterie */
|
||||
batteryManagement();
|
||||
|
||||
for(k=0; k<VOLTAGE_BUFFER_SIZE; k++)
|
||||
{
|
||||
meanVoltage+=ADCConvertedValue[k];
|
||||
/* Gestion des moteurs (asservissement, .. */
|
||||
motorManagement();
|
||||
|
||||
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 == 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();
|
||||
/* Gestion du clignotement de la led, f=100Hz*/
|
||||
ledManagement(Dumber.StateSystem, Dumber.stateBattery);
|
||||
|
||||
if (Dumber.StateSystem == STATE_DISABLE) {
|
||||
cptMesureEmergencyHalt++;
|
||||
|
||||
if (cptMesureEmergencyHalt >= COMPTEUR_SEUIL_EMERGENCY_HALT)
|
||||
{
|
||||
shutDown();
|
||||
if (cptMesureEmergencyHalt >= COMPTEUR_SEUIL_EMERGENCY_HALT) {
|
||||
systemShutDown();
|
||||
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
|
||||
* @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_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_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,
|
||||
|
|
|
@ -28,55 +28,74 @@
|
|||
*/
|
||||
|
||||
#include <stm32f10x.h>
|
||||
#include "system_dumby.h"
|
||||
|
||||
#include "system_dumby.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.
|
||||
* @note tourPositionG correspond exactement <EFBFBD> la m<EFBFBD>me valeur.
|
||||
* @brief Variables globales nombre d'incrémentation de capteur de position de la roue droite.
|
||||
* @note tourPositionG correspond exactement à la même valeur.
|
||||
*/
|
||||
uint16_t tourD = 0;
|
||||
|
||||
/**
|
||||
* @brief Variables Globals nombre d'incr<EFBFBD>mentation de capteur de position de la roue gauche.
|
||||
* @note tourPositionG correspond exactement <EFBFBD> la m<EFBFBD>me valeur.
|
||||
* @brief Variables globales nombre d'incrémentation de capteur de position de la roue gauche.
|
||||
* @note tourPositionG correspond exactement à la même valeur.
|
||||
*/
|
||||
uint16_t tourG = 0;
|
||||
uint16_t tourPositionD;
|
||||
uint16_t tourPositionG;
|
||||
|
||||
/**
|
||||
* @brief Variables Globals des consignes de vitesses du moteur droit.
|
||||
* @note Variables utilis<EFBFBD> dans le programme principal main.c
|
||||
* @brief Variables globales des consignes de vitesses du moteur droit.
|
||||
* @note Variables utilisées dans le programme principal main.c
|
||||
*/
|
||||
uint16_t G_speedRight=20;
|
||||
|
||||
/**
|
||||
* @brief Variables Globals des consignes de vitesses du moteur gauche.
|
||||
* @note Variables utilis<EFBFBD> dans le programme principal main.c
|
||||
* @brief Variables globales des consignes de vitesses du moteur gauche.
|
||||
* @note Variables utilisées dans le programme principal main.c
|
||||
*/
|
||||
uint16_t G_speedLeft=20;
|
||||
|
||||
/**
|
||||
* @brief Variables Globals des consignes de position du moteur gauche.
|
||||
* @note Variables utilis<EFBFBD> dans le programme principal main.c
|
||||
* @brief Variables globales des consignes de position du moteur gauche.
|
||||
* @note Variables utilisées dans le programme principal main.c
|
||||
*/
|
||||
uint16_t G_lapsLeft;
|
||||
|
||||
/**
|
||||
* @brief Variables Globals des consignes de position du moteur droit.
|
||||
* @note Variables utilis<EFBFBD> dans le programme principal main.c
|
||||
* @brief Variables globales des consignes de position du moteur droit.
|
||||
* @note Variables utilisées dans le programme principal main.c
|
||||
*/
|
||||
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
|
||||
* @{
|
||||
*/
|
||||
|
@ -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
|
||||
* 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.
|
||||
* PA8,PA9,PA10,PA11. 4 sortie ppull PB12,PB13,PB14,PB15
|
||||
*
|
||||
|
@ -101,10 +120,13 @@ uint16_t G_lapsRight;
|
|||
* @retval None
|
||||
*
|
||||
*/
|
||||
void MAP_MotorPin(void)
|
||||
void motorConfigure(void)
|
||||
{
|
||||
// Variable local necessaire <20> l'initialisation des structures
|
||||
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
|
||||
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_Mode = GPIO_Mode_IN_FLOATING;
|
||||
GPIO_Init(GPIOA, &Init_Structure);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief La fonction INIT_TIM2 initialise le Timer2 <EFBFBD> une fr<EFBFBD>quence de 25kHz (fc nominal) et initialise
|
||||
* 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
|
||||
// Configuration du timer 2 (pwm moteurs*
|
||||
// On souhaite une résolution du PWM de 256 valeurs MOTOR1 TIM2
|
||||
TIM2_TempsPWMsettings.TIM_Period = 255;
|
||||
TIM2_TempsPWMsettings.TIM_Prescaler = 0;
|
||||
TIM2_TempsPWMsettings.TIM_ClockDivision=0;
|
||||
TIM2_TempsPWMsettings.TIM_CounterMode=TIM_CounterMode_Up;
|
||||
|
||||
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
|
||||
TIM2_Configure.TIM_OCMode=TIM_OCMode_PWM2;
|
||||
TIM2_Configure.TIM_OutputState = TIM_OutputState_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;
|
||||
|
||||
TIM_OC3Init(TIM2, &TIM2_Configure);
|
||||
|
@ -178,18 +180,8 @@ void INIT_OCMotorPwm(void)
|
|||
TIM_Cmd(TIM2, ENABLE);
|
||||
|
||||
TIM_CtrlPWMOutputs(TIM2,ENABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
// Configuration de la capture de l'encodeur 1
|
||||
TIM_ICInitStructure.TIM_Channel = TIM_Channel_1;
|
||||
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
|
||||
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
|
||||
|
@ -199,18 +191,8 @@ void IC_TIM1_CHANEL1(void)
|
|||
TIM_ICInit(TIM1, &TIM_ICInitStructure);
|
||||
TIM_Cmd(TIM1, ENABLE);
|
||||
TIM_ITConfig(TIM1, TIM_IT_CC1, ENABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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;
|
||||
// Configuration de la capture de l'encodeur 1
|
||||
TIM_ICInitStructure.TIM_Channel = TIM_Channel_3;
|
||||
TIM_ICInitStructure.TIM_ICPolarity = TIM_ICPolarity_Rising;
|
||||
TIM_ICInitStructure.TIM_ICSelection = TIM_ICSelection_DirectTI;
|
||||
|
@ -220,24 +202,18 @@ void IC_TIM1_CHANEL3(void)
|
|||
TIM_ICInit(TIM1, &TIM_ICInitStructure);
|
||||
TIM_Cmd(TIM1, ENABLE);
|
||||
TIM_ITConfig(TIM1, TIM_IT_CC3, ENABLE);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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 */
|
||||
// Enable the TIM1 Capture interrupt
|
||||
NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;
|
||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
|
||||
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
|
||||
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 Consigne de vitesse du moteur, d<EFBFBD>finis par un pwm entre 0 et 255.
|
||||
* @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éfini par un pwm entre 0 et 255.
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void cmdRightMotor(char mod, uint16_t pwm)
|
||||
void motorCmdRight(char mod, uint16_t pwm)
|
||||
{
|
||||
pwm = 256 - pwm;
|
||||
|
||||
switch (mod) {
|
||||
case BRAKE:
|
||||
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 Consigne de vitesse du moteur, d<EFBFBD>finis par un pwm entre 0 et 255.
|
||||
* @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éfini par un pwm entre 0 et 255.
|
||||
* @retval None
|
||||
*/
|
||||
|
||||
void cmdLeftMotor(char mod, uint16_t pwm) {
|
||||
void motorCmdLeft(char mod, uint16_t pwm) {
|
||||
pwm = 256 - pwm;
|
||||
switch (mod) {
|
||||
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
|
||||
*/
|
||||
void majVitesseMotorG(uint16_t pwm) {
|
||||
void motorSpeedUpdateLeft(uint16_t pwm) {
|
||||
pwm = 256 - 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
|
||||
*/
|
||||
void majVitesseMotorD(uint16_t pwm) {
|
||||
void motorSpeedUpdateRight(uint16_t pwm) {
|
||||
pwm = 256 - pwm;
|
||||
TIM_SetCompare3(TIM2, pwm);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Regulation des deux moteurs.
|
||||
* @brief Régulation des deux moteurs.
|
||||
*
|
||||
* Modifile le mode de fonctionnement des roues, puis
|
||||
* va mettre <EFBFBD> jour les variables globale G_laps* et G_speed*
|
||||
* utilis<EFBFBD> dans main.c pour l'asservissement.
|
||||
* Modifie le le mode de fonctionnement des roues, puis
|
||||
* va mettre à jour les variables globale G_laps* et G_speed*
|
||||
* 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 Nombre de tour de roue droite <EFBFBD> effectuer.
|
||||
* @param Nombre de tour de roue gauche <EFBFBD> effectuer.
|
||||
* @param Nombre de tour de roue droite à effectuer.
|
||||
* @param Nombre de tour de roue gauche à effectuer.
|
||||
* @param Vitesse de la roue de droite.
|
||||
* @param Vitesse de la roue de gauche.
|
||||
*
|
||||
* @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) {
|
||||
/*Moteur Droit*/
|
||||
switch (modRight) {
|
||||
|
@ -411,7 +388,7 @@ void regulationMoteur(char modRight, char modLeft, uint16_t lapsRight,
|
|||
/**
|
||||
* @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.
|
||||
*
|
||||
* @param None
|
||||
|
@ -422,7 +399,6 @@ void TIM1_CC_IRQHandler(void) {
|
|||
TIM_ClearITPendingBit(TIM1, TIM_IT_CC1);
|
||||
tourD++;
|
||||
tourPositionD++;
|
||||
|
||||
}
|
||||
|
||||
if (TIM_GetITStatus(TIM1, TIM_IT_CC3) == SET) {
|
||||
|
@ -431,6 +407,69 @@ void TIM1_CC_IRQHandler(void) {
|
|||
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
|
||||
*--------------------------------------------------------------------
|
||||
* | CMDA & !CMDB | Avant
|
||||
* 1 | !CMDA & CMDB | Arriére
|
||||
* 1 | !CMDA & CMDB | Arrière
|
||||
* | CMDA = CMDB | Frein
|
||||
******************************************************************************
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef Motor_H
|
||||
#define Motor_H
|
||||
#ifndef _MOTOR_H_
|
||||
#define _MOTOR_H_
|
||||
|
||||
#include "stm32f10x.h"
|
||||
//#include "system_dumby.h"
|
||||
|
||||
extern uint16_t G_speedRight, G_speedLeft, G_lapsLeft, G_lapsRight;
|
||||
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
|
||||
* Avant, Arriére, Frein
|
||||
* @brief États que peuvent prendre chaque moteurs
|
||||
* Avant, Arrière, Frein
|
||||
*/
|
||||
#define FORWARD 11
|
||||
#define REVERSE 12
|
||||
#define BRAKE 13
|
||||
|
||||
void MAP_MotorPin(void);
|
||||
void INIT_TIM2(void);
|
||||
void INIT_OCMotorPwm(void);
|
||||
void commandeMoteur(void);
|
||||
void motorConfigure(void);
|
||||
void motorManagement(void);
|
||||
|
||||
void IC_TIM1_CHANEL3(void);
|
||||
void IC_TIM1_CHANEL1(void);
|
||||
void IT_TIM1(void);
|
||||
void motorCmdRight(char mod, uint16_t pwm);
|
||||
void motorCmdLeft(char mod, uint16_t pwm);
|
||||
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);
|
||||
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 */
|
||||
#endif /* _MOTOR_H_ */
|
||||
|
||||
|
|
|
@ -27,27 +27,17 @@
|
|||
******************************************************************************
|
||||
******************************************************************************
|
||||
*/
|
||||
#include <battery.h>
|
||||
#include "system_dumby.h"
|
||||
#include <stm32f10x.h>
|
||||
#include "led.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "system_dumby.h"
|
||||
#include "battery.h"
|
||||
#include "led.h"
|
||||
#include "motor.h"
|
||||
#include "cmde_usart.h"
|
||||
#include "usart.h"
|
||||
|
||||
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
|
||||
* @{
|
||||
|
@ -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 :
|
||||
* Etat de depart : IDLE
|
||||
|
@ -90,15 +54,29 @@ void MAP_PinShutDown(void)
|
|||
*@param 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.BatteryCurrent = UNDEFINED;
|
||||
// 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.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.InvalidWatchdogResetCpt=0;
|
||||
Dumber.cpt_watchdog = 0;
|
||||
Dumber.cpt_systick = 0;
|
||||
Dumber.cpt_inactivity = 0;
|
||||
|
@ -107,27 +85,104 @@ void default_settings(void)
|
|||
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.
|
||||
* @param None
|
||||
*/
|
||||
|
||||
void shutDown(void) {
|
||||
void systemShutDown(void) {
|
||||
__disable_irq();
|
||||
GPIO_ResetBits(GPIOB, GPIO_Pin_5);
|
||||
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
|
||||
* @{
|
||||
|
@ -136,56 +191,57 @@ void shutDown(void) {
|
|||
|
||||
/**
|
||||
* @brief Interruption systick. Gestion des timers internes.
|
||||
* Definis la vitesse de la loi d'asservissement.
|
||||
* Definis les valeurs de shutdown.
|
||||
* Definis les valeurs d'inactivit<EFBFBD>s.
|
||||
* Definis la valeur de clignotement de la LED.
|
||||
* Défini la vitesse de la loi d'asservissement.
|
||||
* Défini les valeurs de shutdown.
|
||||
* Défini les valeurs d'inactivités.
|
||||
* 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){
|
||||
Dumber.cpt_systick+=10;
|
||||
Dumber.cpt_inactivity+=10;
|
||||
|
||||
if((Dumber.WatchDogStartEnable == TRUE) && (Dumber.StateSystem != IDLE)) Dumber.cpt_watchdog+=10;
|
||||
|
||||
|
||||
if(asservissement == 1){
|
||||
regulation_vitesseD =1;
|
||||
regulation_vitesseG =1;
|
||||
}
|
||||
if(Dumber.cpt_systick % TIMER_1s==0) Dumber.cpt_systick=0;
|
||||
|
||||
if((Dumber.cpt_watchdog % 1000 ) >=975 || (Dumber.cpt_watchdog % 1000) <=25)
|
||||
watchDogState=TRUE;
|
||||
else watchDogState=FALSE;
|
||||
/* Gestion du watchdog */
|
||||
if((Dumber.WatchDogStartEnable == TRUE) && (Dumber.StateSystem != STATE_IDLE))
|
||||
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){
|
||||
Dumber.acquisition=VOLTAGE;
|
||||
voltagePrepare();
|
||||
batteryRefreshData();
|
||||
}
|
||||
|
||||
if(Dumber.cpt_systick % 100==0){
|
||||
/*if(Dumber.cpt_systick % 100==0){
|
||||
etatLED++;
|
||||
|
||||
if (etatLED ==12) etatLED = 0;
|
||||
}
|
||||
}*/
|
||||
|
||||
#if !defined (__NO_INACTIVITY_SHUTDOWN__)
|
||||
if(Dumber.cpt_inactivity>=120000){
|
||||
shutDown();
|
||||
systemShutDown();
|
||||
}
|
||||
#else
|
||||
#warning "Shutdown after inactivity period disabled! Not for production !!!"
|
||||
#endif /* __NO_INACTIVITY_SHUTDOWN__ */
|
||||
|
||||
if(Dumber.cpt_watchdog>=TIMER_Watchdog)
|
||||
{
|
||||
Dumber.StateSystem=DISABLE;
|
||||
cmdRightMotor(BRAKE,0);
|
||||
cmdLeftMotor(BRAKE,0);
|
||||
}
|
||||
|
||||
Dumber.flagSystick=1;
|
||||
}
|
||||
|
||||
|
|
|
@ -27,13 +27,13 @@
|
|||
******************************************************************************
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef system_dumby_H
|
||||
#define system_dumby_H
|
||||
#ifndef _SYSTEM_DUMBY_H_
|
||||
#define _SYSTEM_DUMBY_H_
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
/* Declaration des Constantes */
|
||||
#define VERSION "version 1.2\r"
|
||||
/* Déclaration des Constantes */
|
||||
#define VERSION "version 1.3\r"
|
||||
|
||||
#define SPI 10
|
||||
#define USART 20
|
||||
|
@ -42,68 +42,47 @@
|
|||
#define TRUE 40
|
||||
#define FALSE 50
|
||||
|
||||
#define RUN 51
|
||||
#define IDLE 52
|
||||
#define LOW 53
|
||||
#define DISABLE 54
|
||||
|
||||
#define VOLTAGE 98
|
||||
#define CURRENT 99
|
||||
|
||||
#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_Watchdog 3050 //
|
||||
#define TTMER_Inactivity 120000 // 2 min
|
||||
|
||||
#define RIGHT '>'
|
||||
#define LEFT '<'
|
||||
|
||||
#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 WATCHDOG_MIN 970
|
||||
#define WATCHDOG_MAX 1030
|
||||
#define WATCHDOG_INVALID_COUNTER_MAX 3
|
||||
|
||||
#define COMMONSPEED 5
|
||||
#define LOWSPEED 2
|
||||
#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
|
||||
{
|
||||
// Information
|
||||
uint16_t BatteryPercentage; // Retourne le pourcentage de charge de la batterie
|
||||
uint16_t BatteryCurrent; //
|
||||
char StateSystem; // Etat de la MAE
|
||||
char AddOn; // Un AddOn a <20>t<EFBFBD> d<>tect<63> // Les instructions seront sur le protocol SPI
|
||||
char BatterieChecking; // On doit verifier la valeur de la batterie
|
||||
States StateSystem; // État de la MAE
|
||||
char AddOn; // Un AddOn a été détecté
|
||||
// Les instructions seront sur le protocole SPI
|
||||
char BatterieChecking; // On doit vérifier la valeur de la batterie
|
||||
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;
|
||||
uint8_t InvalidWatchdogResetCpt; // Compteur de remise à zéro du watchdog en dehors du temps imparti
|
||||
char busyState;
|
||||
int cpt_inactivity;
|
||||
char acquisition;
|
||||
|
@ -111,24 +90,17 @@ struct Settings
|
|||
char flagSystick;
|
||||
};
|
||||
|
||||
/* Declaration des variables systemes */
|
||||
extern uint16_t greenLight;
|
||||
extern uint16_t redLight;
|
||||
typedef struct Settings Settings;
|
||||
|
||||
/* Déclaration des variables systèmes */
|
||||
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 */
|
||||
void default_settings(void);
|
||||
void MAP_PinShutDown(void);
|
||||
void SysTick_Handler(void);
|
||||
void Configure_SysTick(void);
|
||||
void shutDown(void);
|
||||
void systemConfigure(void);
|
||||
void systemChangeState(States state);
|
||||
char systemResetWatchdog(void);
|
||||
void systemShutDown(void);
|
||||
|
||||
#endif /* SYSTEM_DUMBY_H_ */
|
||||
#endif /* _SYSTEM_DUMBY_H_ */
|
||||
|
||||
|
||||
|
|
|
@ -16,10 +16,10 @@
|
|||
#include "system_dumby.h"
|
||||
#include <stm32f10x.h>
|
||||
#include <string.h>
|
||||
#include <usart.h>
|
||||
|
||||
#include "cmdManager.h"
|
||||
|
||||
#include "cmde_usart.h"
|
||||
|
||||
//#include "Battery.h"
|
||||
//#include "motor.h"
|
||||
|
@ -64,28 +64,51 @@ volatile uint16_t tmp;
|
|||
*/
|
||||
|
||||
/**
|
||||
* @brief Configuration du GPIO pour l'uart.
|
||||
*
|
||||
* @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.
|
||||
* @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 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_Mode = GPIO_Mode_AF_PP;
|
||||
Init_Structure.GPIO_Speed=GPIO_Speed_50MHz;
|
||||
GPIO_Init(GPIOB, &Init_Structure);
|
||||
|
||||
/// Configure B7 Rx
|
||||
// Configure B7 Rx
|
||||
Init_Structure.GPIO_Pin = GPIO_Pin_7;
|
||||
Init_Structure.GPIO_Mode = GPIO_Mode_IN_FLOATING;
|
||||
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
|
||||
* @retval Aucun
|
||||
*/
|
||||
void INIT_DMASend(uint16_t bufferSize)
|
||||
void usartInitDMA(uint16_t bufferSize)
|
||||
{
|
||||
DMA_InitTypeDef DMA_InitStructure;
|
||||
|
||||
|
@ -110,57 +133,14 @@ void INIT_DMASend(uint16_t bufferSize)
|
|||
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
|
||||
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
|
||||
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
|
||||
|
||||
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
|
||||
* @{
|
||||
*/
|
||||
|
@ -186,15 +166,12 @@ void USART1_IRQHandler(void)
|
|||
if (cpt_Rx < 16)
|
||||
cpt_Rx++;
|
||||
|
||||
if (receiptString[cpt_Rx - 1] == 13) {
|
||||
if (verifyCheckSum() == 0) {
|
||||
manageCmd();
|
||||
} else
|
||||
strcpy(sendString, UNKNOW_ANS);
|
||||
if (receiptString[cpt_Rx - 1] == '\r') {
|
||||
cmdManage();
|
||||
|
||||
if (Dumber.AddOn == FALSE) {
|
||||
inclusionCheckSum();
|
||||
sendDataUSART();
|
||||
cmdAddChecksum();
|
||||
usartSendData(); // Fonction bloquante
|
||||
}
|
||||
|
||||
for (i = 0; i < cpt_Rx + 1; i++)
|
||||
|
@ -221,10 +198,10 @@ void USART1_IRQHandler(void)
|
|||
* @param Aucun
|
||||
* @retval Aucun
|
||||
*/
|
||||
void sendDataUSART(void){
|
||||
void usartSendData(void){
|
||||
int taille;
|
||||
for(taille = 0; sendString[taille]!= '\r'; taille++);
|
||||
INIT_DMASend(taille+1);
|
||||
usartInitDMA(taille+1);
|
||||
DMA_Cmd(DMA1_Channel4, ENABLE);
|
||||
while (DMA_GetFlagStatus(DMA1_FLAG_TC4) == RESET);
|
||||
for(i=0; i<TBuffer;i++)
|
|
@ -13,26 +13,24 @@
|
|||
******************************************************************************
|
||||
******************************************************************************
|
||||
*/
|
||||
#ifndef cmde_usart_H
|
||||
#define cmde_usart_H
|
||||
#ifndef _USART_H_
|
||||
#define _USART_H_
|
||||
|
||||
#include "stm32f10x.h"
|
||||
|
||||
#define TBuffer 30
|
||||
|
||||
/* Prototype des fonctions */
|
||||
|
||||
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*/
|
||||
|
||||
/* Variables externes nécessaire*/
|
||||
extern char sendString[TBuffer];
|
||||
extern char receiptString[TBuffer];
|
||||
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_48MHz 48000000 */
|
||||
/* #define SYSCLK_FREQ_56MHz 56000000 */
|
||||
#define SYSCLK_FREQ_72MHz 72000000
|
||||
/* #define SYSCLK_FREQ_72MHz 72000000 */
|
||||
#endif
|
||||
|
||||
/*!< Uncomment the following line if you need to use external SRAM mounted
|
||||
|
|
Loading…
Reference in a new issue