Newer
Older
#define STM32F4
#if defined(STM32F10X_MD) || defined(STM32F10X_CL)
//#ifdef STM32F1
#include "stm32f10x_gpio.h"
#elif defined(STM32F40_41xxx)
#include "stm32f4xx_conf.h"
#include "system_stm32f4xx.h"
#include "stm32f4xx_rcc.h"
#include "stm32f4xx_gpio.h"
#endif
#include "memory.h"
#include "servo.h"
#include "odometrie.h"
#include "asservissement.h"
#include "sensors.h"
#include "quadratureCoderHandler.h"
#include "ascenseur.h"
#include "pinces.h"
#include "roues.h"
#include "roue.h"
#include "strategieV2.h"
#include "sharpSensor.h"
#include "ax12api.h"
#include "interfaceServosNumeriques.h"
#include "capteurCouleur.h"
#include "tirette.h"
#include "leds.h"
#define NVIC_CCR ((volatile unsigned long *)(0xE000ED14))
#define ALLOW_DEBUG
#ifdef ALLOW_DEBUG
#include "debug.h"
#endif
#define NVIC_CCR ((volatile unsigned long *)(0xE000ED14))
// Dit si on est du coté bleu
#ifdef STM32F40_41xxx // Pin pour le stm32 h103
return GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_9) == Bit_RESET;
#endif
#ifdef STM32F10X_CL // Pin pour le stm32 h107
return GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_4) == Bit_RESET;
#endif
#ifdef STM32F10X_MD // Pin pour le stm32 h103
return GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_9) == Bit_RESET;
#endif
Victor Dubois
committed
return GPIO_ReadInputDataBit(GPIOA, GPIO_Pin_10) == Bit_SET;
#endif
#ifdef STM32F10X_CL // Pin pour le stm32 h107
return GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_5) == Bit_SET;
#endif
}
void initPinPourServoAnalog(GPIO_TypeDef* GPIOx, uint16_t pinX)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = pinX;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOx, &GPIO_InitStructure);
}
#if defined(STM32F10X_MD) || defined(STM32F10X_CL)
*NVIC_CCR = *NVIC_CCR | 0x200; // Set STKALIGN in NVIC
#else
SystemInit(); // Appelée implicitement ?
#endif
// On initialise les horloges
Clk_Init();
// Définit quelques horloges supplémentaires
initAutresHorloges();
// Appel de la fonction qui permet d'initialiser tous les PINS
initialisationDesPIN();
Victor Dubois
committed
#ifdef ALLOW_DEBUG
//Debug::testRemote();
//Debug::testContainer();
//Debug::testBrasLateraux();
//Debug::testADC_DMASampleF4();
//Debug::testSharps();
#endif
Victor Dubois
committed
ServosNumeriques::initClocksAndPortsGPIO();
ServosNumeriques::initUART(1000000);
{
Pinces::getSingleton()->fermerPinces();
for(int j=0; j<15000000; j++);
Pinces::getSingleton()->ouvrirPinces();
for(int j=0; j<15000000; j++);
}*/
/*while(true)
{
Ascenseur::getSingleton()->baisserAscenseur();
Ascenseur::getSingleton()->ouvrirAscenseur();
allumerLED();
while(Ascenseur::getSingleton()->getStatus() != Ascenseur::STOP)
Ascenseur::getSingleton()->update();
for(int j=0; j<150000; j++)
Ascenseur::getSingleton()->update();
Ascenseur::getSingleton()->fermerAscenseur();
for(int j=0; j<150000; j++)
Ascenseur::getSingleton()->update();
Ascenseur::getSingleton()->leverAscenseur();
eteindreLED();
while(Ascenseur::getSingleton()->getStatus() != Ascenseur::STOP)
Ascenseur::getSingleton()->update();
}*/
/*for(int i=0; i<2000; i++)
{
allumerLED();
for(int j=0; j<1000000; j++);
eteindreLED();
for(int j=0; j<1000000; j++);
// #ifdef STM32F40_41xxx // pour la STM32 H405 2014 v1 :
// //MicroSwitch microSwitchBas(GPIOA, GPIO_Pin_10);//Exemple, il n'y a pas de microswitch pour KJ...
// //MicroSwitch microSwitchHaut(GPIOA, GPIO_Pin_10);
// #endif
// #ifdef STM32F10X_MD // pour la STM32 H103 2014 v1 :
// //MicroSwitch microSwitchBas(GPIOA, GPIO_Pin_10);
// //MicroSwitch microSwitchHaut(GPIOA, GPIO_Pin_10);
// #endif
/*#ifdef STM32F10X_CL // pour la STM32 H107 2013 v2 :
MicroSwitch microSwitchBas(GPIOE, GPIO_Pin_3);
MicroSwitch microSwitchHaut(GPIOE, GPIO_Pin_2);
/*while(1){
if(microSwitchBas.ferme()||microSwitchHaut.ferme())
{
allumerLED();
}
else
{
eteindreLED();
}
}*/
#ifdef STM32F40_41xxx // pour la STM32 H405 2014 v1 :
Tirette tirette(GPIOA, GPIO_Pin_10);
#endif
Victor Dubois
committed
#ifdef STM32F10X_MD // pour la STM32 H103 2014 v1 :
Tirette tirette(GPIOA, GPIO_Pin_10);
#endif
#ifdef STM32F10X_CL // pour la STM32 H107 2013 v2 :
Tirette tirette(GPIOE, GPIO_Pin_5);
#endif
#ifdef ALLOW_DEBUG
//Debug::testTirette(&tirette);
#endif
// Initialisation des actionneurs 1
#if defined(STM32F40_41xxx) || defined(STM32F10X_MD) // H405
Victor Dubois
committed
//BrasLateraux::initBrasLateraux();
//Container::getSingleton();
// BrasLateraux::getLeft()->collapse();
// BrasLateraux::getRight()->collapse();
// CanonLances* canon = CanonLances::getSingleton();
#endif
#ifdef ALLOW_DEBUG
//Debug::testBrasLateraux();
#endif
tirette.attendreRemise();
tirette.attendreEnlevee();
Victor Dubois
committed
#if defined(STM32F10X_CL)
Remote::getSingleton();
#endif
// Initialisation des actionneurs 2
#if defined(STM32F40_41xxx) || defined(STM32F10X_MD) // H405
#elif defined(STM32F10X_CL) // H107
Sensors* sensors = Sensors::getSingleton();
ServosNumeriques::setLedState(1, 12);
#endif
Victor Dubois
committed
#ifdef STM32F40_41xxx // pour la STM32 H405 2014 v1 :
QuadratureCoderHandler* rcd = new QuadratureCoderHandler(TIM4, GPIOB, GPIO_Pin_6, GPIOB, GPIO_Pin_7, GPIO_AF_TIM4 ,GPIO_PinSource6, GPIO_PinSource7);
QuadratureCoderHandler* rcg = new QuadratureCoderHandler(TIM1, GPIOA, GPIO_Pin_8, GPIOA, GPIO_Pin_9, GPIO_AF_TIM1 ,GPIO_PinSource8, GPIO_PinSource9);
#endif
Victor Dubois
committed
#ifdef STM32F10X_MD // pour la STM32 H103 2014 v1 :
QuadratureCoderHandler* rcd = new QuadratureCoderHandler(TIM4, GPIOB, GPIO_Pin_6, GPIOB, GPIO_Pin_7);
QuadratureCoderHandler* rcg = new QuadratureCoderHandler(TIM1, GPIOA, GPIO_Pin_8, GPIOA, GPIO_Pin_9);
#endif
#ifdef STM32F10X_CL // pour la STM32 H107 2013 v2 :
QuadratureCoderHandler* rcd = new QuadratureCoderHandler(TIM4, GPIOD, GPIO_Pin_12, GPIOD, GPIO_Pin_13);
GPIO_PinRemapConfig(GPIO_Remap_TIM4, ENABLE);
QuadratureCoderHandler* rcg = new QuadratureCoderHandler(TIM3, GPIOA, GPIO_Pin_6, GPIOA, GPIO_Pin_7);
#endif
#ifdef ALLOW_DEBUG
//Debug::testQuadrature(rcg, rcd);
#endif
// Pour la v1 :
// QuadratureCoderHandler* rcd = new QuadratureCoderHandler(TIM2, GPIOA, GPIO_Pin_0, GPIOA, GPIO_Pin_1);
// QuadratureCoderHandler* rcg = new QuadratureCoderHandler(TIM3, GPIOA, GPIO_Pin_6, GPIOA, GPIO_Pin_7);
Odometrie* odometrie = new Odometrie(rcg, rcd);
Position pos(194, 1000, isBlue());//1500, isBlue());
StrategieV2* strat = new StrategieV2(isBlue());
Asservissement* asserv = new Asservissement(odometrie);
Victor Dubois
committed
/*
CommandAllerA* command = new CommandAllerA(Position(1000,230), false);