Commit 4571ba57 authored by Arnaud Cadot's avatar Arnaud Cadot

- Moved the sys clock handler to a dedicated class (Clock)

parent 22feea19
......@@ -35,10 +35,10 @@ HEADERS += \
../../include/actionneurs/ascenseur.h \
../../include/asservissement/pidFilterDistance.h \
../../include/asservissement/pidFilterAngle.h \
../../include/asservissement/odometrie.h \
../../include/asservissement/commandAllerA.h \
../../include/asservissement/odometrie.h \
../../include/asservissement/commandAllerA.h \
../../include/asservissement/command.h \
../../include/asservissement/asservissement.h \
../../include/asservissement/asservissement.h \
../../include/simul/XMLReader.h \
../../include/simul/TableGraphics.h \
../../include/simul/table.h \
......@@ -108,22 +108,23 @@ HEADERS += \
../../include/strategie/benne.h \
../../include/actionneurs/fishingNet.h \
../../include/actionneurs/parasol.h \
../../include/strategie/benne.h
../../include/strategie/benne.h \
../../include/clock.h
SOURCES += \
../../src/asservissement/pidFilterDistance.cpp \
../../src/asservissement/pidFilterAngle.cpp \
../../src/asservissement/commandAllerA.cpp \
../../src/asservissement/pidFilterAngle.cpp \
../../src/asservissement/commandAllerA.cpp \
../../src/asservissement/command.cpp \
../../src/asservissement/asservissement.cpp \
../../src/asservissement/asservissement.cpp \
../../src/actionneurs/servo.cpp \
../../src/actionneurs/sensors.cpp \
../../src/actionneurs/sensor.cpp \
../../src/position.cpp \
../../src/distance.cpp \
../../src/angle.cpp \
../../src/positionPlusAngle.cpp \
../../src/positionPlusAngle.cpp \
../../src/simul/XMLReader.cpp \
../../src/simul/TableGraphics.cpp \
../../src/simul/table.cpp \
......@@ -140,12 +141,12 @@ SOURCES += \
../../src/hardware/limitSwitchSensor.cpp \
../../src/hardware/ligthBarrierSensor.cpp \
../../src/hardware/ax12api.cpp \
../../src/hardware/leds.cpp \
../../src/hardware/leds.cpp \
../../src/hardware/analogSensor.cpp \
../../src/strategie/strategieV2.cpp \
../../src/strategie/recalibrerOdometrie.cpp \
../../src/strategie/mediumLevelAction.cpp \
../../src/strategie/actionGoTo.cpp \
../../src/strategie/actionGoTo.cpp \
../../src/simul/userdata.cpp \
../../src/simul/contactlistener.cpp \
../../src/strategie/strategiev3.cpp \
......@@ -180,7 +181,6 @@ SOURCES += \
../../src/strategie/manipulationCoinGaucheHautPiedSolitaire.cpp \
../../src/vec3d.cpp \
../../src/vec2d.cpp \
../../src/loop.cpp \
../../src/InitKrabiJunior.cpp \
../../src/initkrabi.cpp \
../../src/initialisation.cpp \
......@@ -190,7 +190,8 @@ SOURCES += \
../../src/strategie/benne.cpp \
../../src/strategie/zoneConstruction.cpp \
../../src/actionneurs/fishingNet.cpp \
../../src/actionneurs/parasol.cpp
../../src/actionneurs/parasol.cpp \
../../src/clock.cpp
FORMS += \
../../include/simul/remotedebug.ui \
......
......@@ -18,8 +18,7 @@
#include "roues.h"
//#include "capteurs.h"
#endif
#include "loop.h"
#include "sensors.h"
#include "constantes.h"
#include "odometrie.h"
......
#ifndef CLOCK_H
#define CLOCK_H
/**@brief Interuption appelée régulièrement par le microcontroleur
* @see Clock::MS_PER_TICK
*/
extern "C" void SysTick_Handler();
class Clock
{
protected:
virtual void everyTick();
virtual void every5ms();
virtual void everySecond();
public:
static const unsigned long MS_PER_TICK = 5;
static const unsigned long MATCH_DURATION_MS = 90*1000;
static Clock* getInstance();
unsigned long elapsedSinceStartup() const;
void matchStart();
unsigned long elapsedSinceMatchStart() const;
bool isMatchStarted() const;
bool hasMatchEnded() const;
protected:
Clock();
private:
void tick();
friend void ::SysTick_Handler();
unsigned long m_tickCount;
unsigned long m_last5msTick;
unsigned long m_last1sTick;
unsigned long m_matchStartTime;
bool m_matchStarted;
};
#endif // CLOCK_H
......@@ -8,7 +8,7 @@
#include "quadratureCoderHandler.h"
#include "odometrie.h"
#include "strategieV2.h"
#include "loop.h"
#include "asservissement.h"
#include "interfaceServosNumeriques.h"
......
#ifndef LOOP_H
#define LOOP_H
static long systick_count = 0;
/**@brief fonction externe appellé directement par le microcontroleur à chaque mise à jour. C'est grace à cette fonction que des actions sont exécutés à intervalle régulier */
extern "C" void SysTick_Handler();
#endif // LOOP_H
......@@ -90,6 +90,7 @@
<Unit filename="include/asservissement/odometrie.h" />
<Unit filename="include/asservissement/pidFilterAngle.h" />
<Unit filename="include/asservissement/pidFilterDistance.h" />
<Unit filename="include/clock.h" />
<Unit filename="include/constantes.h" />
<Unit filename="include/distance.h" />
<Unit filename="include/hardware/analogSensor.h" />
......@@ -119,6 +120,7 @@
<Unit filename="include/position.h" />
<Unit filename="include/positionPlusAngle.h" />
<Unit filename="include/strategie/actionGoTo.h" />
<Unit filename="include/strategie/benne.h" />
<Unit filename="include/strategie/cabine.h" />
<Unit filename="include/strategie/clap.h" />
<Unit filename="include/strategie/deposerGobelet.h" />
......@@ -164,6 +166,7 @@
<Unit filename="src/asservissement/odometrie.cpp" />
<Unit filename="src/asservissement/pidFilterAngle.cpp" />
<Unit filename="src/asservissement/pidFilterDistance.cpp" />
<Unit filename="src/clock.cpp" />
<Unit filename="src/debug.cpp" />
<Unit filename="src/distance.cpp" />
<Unit filename="src/hardware/analogSensor.cpp" />
......@@ -195,6 +198,7 @@
<Unit filename="src/strategie/actionGoTo.cpp" />
<Unit filename="src/strategie/anciens_fichiers/feuKrabi (copie).cpp.victor" />
<Unit filename="src/strategie/anciens_fichiers/feukrabilateral.cpp.limitVitesseVictor" />
<Unit filename="src/strategie/benne.cpp" />
<Unit filename="src/strategie/cabine.cpp" />
<Unit filename="src/strategie/clap.cpp" />
<Unit filename="src/strategie/deposerGobelet.cpp" />
......
......@@ -108,6 +108,7 @@
<Unit filename="include/asservissement/odometrie.h" />
<Unit filename="include/asservissement/pidFilterAngle.h" />
<Unit filename="include/asservissement/pidFilterDistance.h" />
<Unit filename="include/clock.h" />
<Unit filename="include/constantes.h" />
<Unit filename="include/debug.h" />
<Unit filename="include/hardware/analogSensor.h" />
......@@ -130,7 +131,6 @@
<Unit filename="include/initKrabiJunior.h" />
<Unit filename="include/initialisation.h" />
<Unit filename="include/interfaceServosNumeriques.h" />
<Unit filename="include/loop.h" />
<Unit filename="include/memory.h" />
<Unit filename="include/strategie/strategieV2.h" />
<Unit filename="include/strategie/strategiev3.h" />
......@@ -153,6 +153,7 @@
<Unit filename="src/asservissement/odometrie.cpp" />
<Unit filename="src/asservissement/pidFilterAngle.cpp" />
<Unit filename="src/asservissement/pidFilterDistance.cpp" />
<Unit filename="src/clock.cpp" />
<Unit filename="src/debug.cpp" />
<Unit filename="src/distance.cpp" />
<Unit filename="src/hardware/analogSensor.cpp" />
......
#include "asservissement.h"
#include "strategieV2.h"
#include "ascenseur.h"
#include "ascenseur.h"
#include "clock.h"
#include "misc.h"
#include "capteurCouleur.h"
......@@ -47,7 +49,7 @@ Asservissement * Asservissement::asservissement = NULL; //Pour que nos variables
bool Asservissement::matchFini = false;
const uint16_t Asservissement::nb_ms_between_updates = MS_BETWEEN_UPDATE;
Asservissement::Asservissement(Odometrie* _odometrie) : testMod(false), testRunning(false), stopped(false), engineLimit(0.5f), testDataSent(0), testDataToSend(0)
Asservissement::Asservissement(Odometrie* _odometrie) : testMod(false), testRunning(false), stopped(false), testDataSent(0), testDataToSend(0), engineLimit(0.5f)
/*:
seuil_collision(SEUIL_COLISION),
......@@ -371,7 +373,7 @@ void Asservissement::update(void)
}
}
if (testMod && !testRunning && testDataSent < testDataToSend && (systick_count % 10 == 0))
if (testMod && !testRunning && testDataSent < testDataToSend && (Clock::getInstance()->elapsedSinceStartup() % (10*Clock::MS_PER_TICK) == 0))
{
// send data
#ifndef NO_REMOTE
......
#include "clock.h"
#include "asservissement/odometrie.h"
#include "asservissement/asservissement.h"
#include "hardware/tourelle.h"
#include "hardware/leds.h"
void Clock::everyTick()
{
}
void Clock::every5ms()
{
#ifndef STM32F40_41xxx
Odometrie::odometrie->update();
Asservissement::asservissement->update();
Tourelle::getSingleton()->update();
//StrategieV2::update();
#endif
}
void Clock::everySecond()
{
Led::toggle(0);
}
Clock* Clock::getInstance()
{
static Clock* instance = 0;
if(instance == 0)
instance = new Clock();
return instance;
}
Clock::Clock()
{
m_tickCount = 0;
m_last5msTick = 0;
m_matchStartTime = 0;
m_matchStarted = false;
}
void Clock::tick()
{
++m_tickCount;
everyTick();
if((m_tickCount - m_last5msTick) * Clock::MS_PER_TICK > 5)
{
every5ms();
m_last5msTick = m_tickCount;
}
if((m_tickCount - m_last5msTick) * Clock::MS_PER_TICK > 1000)
{
everySecond();
m_last1sTick = m_tickCount;
}
}
unsigned long Clock::elapsedSinceStartup() const
{
return m_tickCount * Clock::MS_PER_TICK;
}
void Clock::matchStart()
{
if(isMatchStarted())
return;
m_matchStarted = true;
m_matchStartTime = m_tickCount;
}
unsigned long Clock::elapsedSinceMatchStart() const
{
if(isMatchStarted())
return (m_tickCount - m_matchStartTime) * Clock::MS_PER_TICK;
return 0;
}
bool Clock::isMatchStarted() const
{
return m_matchStarted;
}
bool Clock::hasMatchEnded() const
{
return isMatchStarted() && (elapsedSinceMatchStart() >= Clock::MATCH_DURATION_MS);
}
extern "C" void SysTick_Handler()
{
Clock::getInstance()->tick();
}
......@@ -49,7 +49,7 @@ void InitKrabiJunior::initActionneurs()
ServosNumeriques::initUART(1000000);
ServosNumeriques::sendMode();
Sensors* sensors = Sensors::getSingleton();
/*Sensors* sensors = */Sensors::getSingleton();
ServosNumeriques::setLedState(1, 12);
#endif
}
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment