mirror of
https://github.com/yoboujon/dumber.git
synced 2025-06-08 13:50:49 +02:00
Fonction moteur marche a peu pres correctement. Asservissement a revoir cependant
This commit is contained in:
parent
149a56fbac
commit
7d9e38f3ef
4 changed files with 257 additions and 144 deletions
|
@ -327,16 +327,15 @@
|
||||||
<outputType id="org.eclipse.cdt.managedbuilder.ui.rcbs.outputtype.1151842665.1610208999" name="Resource Custom Build Step Output Type"/>
|
<outputType id="org.eclipse.cdt.managedbuilder.ui.rcbs.outputtype.1151842665.1610208999" name="Resource Custom Build Step Output Type"/>
|
||||||
</tool>
|
</tool>
|
||||||
</fileInfo>
|
</fileInfo>
|
||||||
<fileInfo id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.1504381080.727722516.1512822849" name="moteurs.c" rcbsApplicability="disable" resourcePath="Application/moteurs.c" toolsToInvoke="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.1017015985.772184159">
|
<fileInfo id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.1504381080.727722516.584766423" name="moteurs.c" rcbsApplicability="disable" resourcePath="Application/moteurs.c" toolsToInvoke="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.1017015985.1839636316">
|
||||||
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.1017015985.772184159" name="MCU GCC Compiler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.1017015985">
|
<tool id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.1017015985.1839636316" name="MCU GCC Compiler" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.1017015985">
|
||||||
<option id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.1561927129" name="Optimization level" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level" value="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.option.optimization.level.value.o0" valueType="enumerated"/>
|
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.422540263" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c"/>
|
||||||
<inputType id="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c.786982597" superClass="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.input.c"/>
|
|
||||||
</tool>
|
</tool>
|
||||||
<tool customBuildStep="true" id="org.eclipse.cdt.managedbuilder.ui.rcbs.1151549896" name="Resource Custom Build Step">
|
<tool customBuildStep="true" id="org.eclipse.cdt.managedbuilder.ui.rcbs.1811836732" name="Resource Custom Build Step">
|
||||||
<inputType id="org.eclipse.cdt.managedbuilder.ui.rcbs.inputtype.1295176218" name="Resource Custom Build Step Input Type">
|
<inputType id="org.eclipse.cdt.managedbuilder.ui.rcbs.inputtype.1316072342" name="Resource Custom Build Step Input Type">
|
||||||
<additionalInput kind="additionalinputdependency" paths=""/>
|
<additionalInput kind="additionalinputdependency"/>
|
||||||
</inputType>
|
</inputType>
|
||||||
<outputType id="org.eclipse.cdt.managedbuilder.ui.rcbs.outputtype.1189979175" name="Resource Custom Build Step Output Type"/>
|
<outputType id="org.eclipse.cdt.managedbuilder.ui.rcbs.outputtype.861774528" name="Resource Custom Build Step Output Type"/>
|
||||||
</tool>
|
</tool>
|
||||||
</fileInfo>
|
</fileInfo>
|
||||||
<fileInfo id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.1504381080.727722516.Application/application.c" name="application.c" rcbsApplicability="disable" resourcePath="Application/application.c" toolsToInvoke="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.983087978">
|
<fileInfo id="com.st.stm32cube.ide.mcu.gnu.managedbuild.config.exe.debug.1504381080.727722516.Application/application.c" name="application.c" rcbsApplicability="disable" resourcePath="Application/application.c" toolsToInvoke="com.st.stm32cube.ide.mcu.gnu.managedbuild.tool.c.compiler.983087978">
|
||||||
|
|
|
@ -40,8 +40,8 @@ typedef struct {
|
||||||
uint8_t type;
|
uint8_t type;
|
||||||
int16_t commande;
|
int16_t commande;
|
||||||
int16_t consigne;
|
int16_t consigne;
|
||||||
uint32_t distance;
|
int32_t distance;
|
||||||
uint32_t tours;
|
int32_t tours;
|
||||||
} MOTEURS_EtatDiff;
|
} MOTEURS_EtatDiff;
|
||||||
|
|
||||||
MOTEURS_EtatMoteur MOTEURS_EtatMoteurGauche, MOTEURS_EtatMoteurDroit = { 0 };
|
MOTEURS_EtatMoteur MOTEURS_EtatMoteurGauche, MOTEURS_EtatMoteurDroit = { 0 };
|
||||||
|
@ -69,6 +69,53 @@ void MOTEURS_DesactiveAlim(void);
|
||||||
void MOTEURS_ActiveAlim(void);
|
void MOTEURS_ActiveAlim(void);
|
||||||
int16_t MOTEURS_CorrectionEncodeur(MOTEURS_EtatMoteur etat);
|
int16_t MOTEURS_CorrectionEncodeur(MOTEURS_EtatMoteur etat);
|
||||||
|
|
||||||
|
#ifdef TESTS
|
||||||
|
TIM_HandleTypeDef htim7;
|
||||||
|
|
||||||
|
volatile uint32_t DEBUG_startTime = 0;
|
||||||
|
volatile uint32_t DEBUG_endTime = 0;
|
||||||
|
volatile uint32_t DEBUG_duration = 0;
|
||||||
|
volatile uint32_t DEBUG_worstCase = 0;
|
||||||
|
|
||||||
|
void Init_Systick(void) {
|
||||||
|
// TIM_ClockConfigTypeDef sClockSourceConfig = { 0 };
|
||||||
|
//
|
||||||
|
// __HAL_RCC_TIM7_CLK_ENABLE();
|
||||||
|
//
|
||||||
|
// htim7.Instance = TIM2;
|
||||||
|
// htim7.Init.Prescaler = 0;
|
||||||
|
// htim7.Init.CounterMode = TIM_COUNTERMODE_UP;
|
||||||
|
// htim7.Init.Period = 65535;
|
||||||
|
// htim7.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
|
||||||
|
// htim7.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
|
||||||
|
// if (HAL_TIM_Base_Init(&htim7) != HAL_OK) {
|
||||||
|
// Error_Handler();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
|
||||||
|
// if (HAL_TIM_ConfigClockSource(&htim7, &sClockSourceConfig) != HAL_OK) {
|
||||||
|
// Error_Handler();
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// LL_TIM_EnableCounter(TIM7);
|
||||||
|
}
|
||||||
|
|
||||||
|
void StartMeasure(void) {
|
||||||
|
// DEBUG_startTime = LL_TIM_GetCounter(TIM7);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndMeasure(void) {
|
||||||
|
// DEBUG_endTime = LL_TIM_GetCounter(TIM7);
|
||||||
|
//
|
||||||
|
// if (DEBUG_startTime >= DEBUG_endTime)
|
||||||
|
// DEBUG_duration = 65533 - DEBUG_startTime + DEBUG_endTime;
|
||||||
|
// else
|
||||||
|
// DEBUG_duration = DEBUG_endTime - DEBUG_startTime;
|
||||||
|
//
|
||||||
|
// if (DEBUG_duration > DEBUG_worstCase)
|
||||||
|
// DEBUG_worstCase = DEBUG_duration;
|
||||||
|
}
|
||||||
|
#endif /* TESTS */
|
||||||
/**
|
/**
|
||||||
* @brief Fonction d'initialisation des moteurs
|
* @brief Fonction d'initialisation des moteurs
|
||||||
*
|
*
|
||||||
|
@ -78,8 +125,7 @@ void MOTEURS_Init(void) {
|
||||||
MOTEURS_DesactiveAlim();
|
MOTEURS_DesactiveAlim();
|
||||||
|
|
||||||
/* Create the task without using any dynamic memory allocation. */
|
/* Create the task without using any dynamic memory allocation. */
|
||||||
xHandleMoteurs = xTaskCreateStatic(
|
xHandleMoteurs = xTaskCreateStatic(MOTEURS_TachePrincipale, /* Function that implements the task. */
|
||||||
MOTEURS_TachePrincipale, /* Function that implements the task. */
|
|
||||||
"MOTEURS Principale", /* Text name for the task. */
|
"MOTEURS Principale", /* Text name for the task. */
|
||||||
STACK_SIZE, /* Number of indexes in the xStack array. */
|
STACK_SIZE, /* Number of indexes in the xStack array. */
|
||||||
NULL, /* Parameter passed into the task. */
|
NULL, /* Parameter passed into the task. */
|
||||||
|
@ -100,33 +146,42 @@ void MOTEURS_Init(void) {
|
||||||
vTaskSuspend(xHandleMoteursAsservissement); // On ne lance la tache d'asservissement que lorsque'une commande moteur arrive
|
vTaskSuspend(xHandleMoteursAsservissement); // On ne lance la tache d'asservissement que lorsque'une commande moteur arrive
|
||||||
|
|
||||||
MOTEURS_DesactiveAlim();
|
MOTEURS_DesactiveAlim();
|
||||||
|
|
||||||
|
#ifdef TESTS
|
||||||
|
Init_Systick();
|
||||||
|
#endif /* TESTS */
|
||||||
}
|
}
|
||||||
|
|
||||||
void MOTEURS_Avance(uint32_t distance) {
|
void MOTEURS_Avance(int32_t distance) {
|
||||||
static uint32_t dist;
|
static int32_t dist;
|
||||||
|
|
||||||
if (distance) {
|
dist = distance*15;
|
||||||
dist = distance;
|
|
||||||
|
if (dist) {
|
||||||
MOTEURS_ActiveAlim();
|
MOTEURS_ActiveAlim();
|
||||||
MESSAGE_SendMailbox(MOTEURS_Mailbox, MSG_ID_MOTEURS_MOVE, APPLICATION_Mailbox, (void*)&dist);
|
MESSAGE_SendMailbox(MOTEURS_Mailbox, MSG_ID_MOTEURS_MOVE,
|
||||||
|
APPLICATION_Mailbox, (void*) &dist);
|
||||||
} else
|
} else
|
||||||
MOTEURS_Stop();
|
MOTEURS_Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MOTEURS_Tourne(uint32_t tours) {
|
void MOTEURS_Tourne(int32_t tours) {
|
||||||
static uint32_t turns;
|
static int32_t turns;
|
||||||
|
|
||||||
if (tours) {
|
|
||||||
turns = tours;
|
turns = tours;
|
||||||
|
|
||||||
|
if (turns) {
|
||||||
MOTEURS_ActiveAlim();
|
MOTEURS_ActiveAlim();
|
||||||
MESSAGE_SendMailbox(MOTEURS_Mailbox, MSG_ID_MOTEURS_TURN, APPLICATION_Mailbox, (void*)&turns);
|
MESSAGE_SendMailbox(MOTEURS_Mailbox, MSG_ID_MOTEURS_TURN,
|
||||||
|
APPLICATION_Mailbox, (void*) &turns);
|
||||||
} else
|
} else
|
||||||
MOTEURS_Stop();
|
MOTEURS_Stop();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MOTEURS_Stop(void) {
|
void MOTEURS_Stop(void) {
|
||||||
MOTEURS_DesactiveAlim();
|
MOTEURS_DesactiveAlim();
|
||||||
MESSAGE_SendMailbox(MOTEURS_Mailbox, MSG_ID_MOTEURS_STOP, APPLICATION_Mailbox, (void*)NULL);
|
MESSAGE_SendMailbox(MOTEURS_Mailbox, MSG_ID_MOTEURS_STOP,
|
||||||
|
APPLICATION_Mailbox, (void*) NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -136,41 +191,52 @@ void MOTEURS_Stop(void) {
|
||||||
*/
|
*/
|
||||||
void MOTEURS_TachePrincipale(void *params) {
|
void MOTEURS_TachePrincipale(void *params) {
|
||||||
MESSAGE_Typedef msg;
|
MESSAGE_Typedef msg;
|
||||||
uint32_t distance, tours;
|
int32_t distance, tours;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
msg = MESSAGE_ReadMailbox(MOTEURS_Mailbox);
|
msg = MESSAGE_ReadMailbox(MOTEURS_Mailbox);
|
||||||
|
|
||||||
switch (msg.id) {
|
switch (msg.id) {
|
||||||
case MSG_ID_MOTEURS_MOVE:
|
case MSG_ID_MOTEURS_MOVE:
|
||||||
distance = *((uint32_t*)msg.data);
|
distance = *((int32_t*) msg.data);
|
||||||
MOTEURS_EtatDifferentiel.distance = distance;
|
MOTEURS_EtatDifferentiel.distance = distance;
|
||||||
MOTEURS_EtatDifferentiel.tours = 0;
|
MOTEURS_EtatDifferentiel.tours = 0;
|
||||||
|
|
||||||
|
if (distance > 0) {
|
||||||
MOTEURS_EtatMoteurGauche.consigne = 50;
|
MOTEURS_EtatMoteurGauche.consigne = 50;
|
||||||
MOTEURS_EtatMoteurDroit.consigne = 50;
|
MOTEURS_EtatMoteurDroit.consigne = 50;
|
||||||
|
} else {
|
||||||
|
MOTEURS_EtatMoteurGauche.consigne = -50;
|
||||||
|
MOTEURS_EtatMoteurDroit.consigne = -50;
|
||||||
|
}
|
||||||
|
|
||||||
vTaskResume(xHandleMoteursAsservissement);
|
vTaskResume(xHandleMoteursAsservissement);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MSG_ID_MOTEURS_TURN:
|
case MSG_ID_MOTEURS_TURN:
|
||||||
tours = *((uint32_t*)msg.data);
|
tours = *((int32_t*) msg.data);
|
||||||
MOTEURS_EtatDifferentiel.distance = 0;
|
MOTEURS_EtatDifferentiel.distance = 0;
|
||||||
MOTEURS_EtatDifferentiel.tours = tours;
|
MOTEURS_EtatDifferentiel.tours = tours;
|
||||||
|
|
||||||
MOTEURS_EtatMoteurGauche.consigne=50;
|
if (tours > 0) {
|
||||||
|
MOTEURS_EtatMoteurGauche.consigne = -50;
|
||||||
MOTEURS_EtatMoteurDroit.consigne = 50;
|
MOTEURS_EtatMoteurDroit.consigne = 50;
|
||||||
|
} else {
|
||||||
|
MOTEURS_EtatMoteurGauche.consigne = 50;
|
||||||
|
MOTEURS_EtatMoteurDroit.consigne = -50;
|
||||||
|
}
|
||||||
|
|
||||||
vTaskResume(xHandleMoteursAsservissement);
|
vTaskResume(xHandleMoteursAsservissement);
|
||||||
break;
|
break;
|
||||||
case MSG_ID_MOTEURS_STOP:
|
|
||||||
|
|
||||||
|
case MSG_ID_MOTEURS_STOP:
|
||||||
MOTEURS_EtatDifferentiel.distance = 0;
|
MOTEURS_EtatDifferentiel.distance = 0;
|
||||||
MOTEURS_EtatDifferentiel.tours = 0;
|
MOTEURS_EtatDifferentiel.tours = 0;
|
||||||
|
|
||||||
MOTEURS_EtatMoteurGauche.consigne = 0;
|
MOTEURS_EtatMoteurGauche.consigne = 0;
|
||||||
MOTEURS_EtatMoteurDroit.consigne = 0;
|
MOTEURS_EtatMoteurDroit.consigne = 0;
|
||||||
if ((MOTEURS_CorrectionEncodeur(MOTEURS_EtatMoteurGauche) ==0) &&
|
if ((MOTEURS_CorrectionEncodeur(MOTEURS_EtatMoteurGauche) == 0)
|
||||||
(MOTEURS_CorrectionEncodeur(MOTEURS_EtatMoteurDroit) ==0))
|
&& (MOTEURS_CorrectionEncodeur(MOTEURS_EtatMoteurDroit) == 0))
|
||||||
// Les moteurs sont déjà arrêtés
|
// Les moteurs sont déjà arrêtés
|
||||||
vTaskSuspend(xHandleMoteursAsservissement);
|
vTaskSuspend(xHandleMoteursAsservissement);
|
||||||
else
|
else
|
||||||
|
@ -199,7 +265,12 @@ void MOTEURS_TacheAsservissement( void* params ) {
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
// Wait for the next cycle.
|
// Wait for the next cycle.
|
||||||
vTaskDelayUntil( &xLastWakeTime, pdMS_TO_TICKS(MOTEURS_PERIODE_ASSERVISSEMENT));
|
vTaskDelayUntil(&xLastWakeTime,
|
||||||
|
pdMS_TO_TICKS(MOTEURS_PERIODE_ASSERVISSEMENT));
|
||||||
|
|
||||||
|
#ifdef TESTS
|
||||||
|
//StartMeasure();
|
||||||
|
#endif /* TESTS */
|
||||||
|
|
||||||
encodeurGauche = MOTEURS_CorrectionEncodeur(MOTEURS_EtatMoteurGauche);
|
encodeurGauche = MOTEURS_CorrectionEncodeur(MOTEURS_EtatMoteurGauche);
|
||||||
encodeurDroit = MOTEURS_CorrectionEncodeur(MOTEURS_EtatMoteurDroit);
|
encodeurDroit = MOTEURS_CorrectionEncodeur(MOTEURS_EtatMoteurDroit);
|
||||||
|
@ -213,8 +284,9 @@ void MOTEURS_TacheAsservissement( void* params ) {
|
||||||
erreurG = MOTEURS_EtatMoteurGauche.consigne - encodeurGauche;
|
erreurG = MOTEURS_EtatMoteurGauche.consigne - encodeurGauche;
|
||||||
erreurD = MOTEURS_EtatMoteurDroit.consigne - encodeurDroit;
|
erreurD = MOTEURS_EtatMoteurDroit.consigne - encodeurDroit;
|
||||||
|
|
||||||
if (((MOTEURS_EtatMoteurDroit.consigne ==0) && (MOTEURS_EtatMoteurGauche.consigne ==0)) &&
|
if (((MOTEURS_EtatMoteurDroit.consigne == 0)
|
||||||
((erreurD==0) && (erreurG==0))) {
|
&& (MOTEURS_EtatMoteurGauche.consigne == 0))
|
||||||
|
&& ((erreurD == 0) && (erreurG == 0))) {
|
||||||
|
|
||||||
MOTEURS_DesactiveAlim();
|
MOTEURS_DesactiveAlim();
|
||||||
vTaskSuspend(xHandleMoteursAsservissement);
|
vTaskSuspend(xHandleMoteursAsservissement);
|
||||||
|
@ -228,13 +300,19 @@ void MOTEURS_TacheAsservissement( void* params ) {
|
||||||
locCmdG = ((int32_t) MOTEUR_Kp * (int32_t) erreurG) / 100;
|
locCmdG = ((int32_t) MOTEUR_Kp * (int32_t) erreurG) / 100;
|
||||||
|
|
||||||
if (MOTEURS_EtatMoteurGauche.consigne >= 0) {
|
if (MOTEURS_EtatMoteurGauche.consigne >= 0) {
|
||||||
if (locCmdG<0) MOTEURS_EtatMoteurGauche.commande=0;
|
if (locCmdG < 0)
|
||||||
else if (locCmdG>SHRT_MAX) MOTEURS_EtatMoteurGauche.commande=SHRT_MAX;
|
MOTEURS_EtatMoteurGauche.commande = 0;
|
||||||
else MOTEURS_EtatMoteurGauche.commande=(int16_t)locCmdG;
|
else if (locCmdG > SHRT_MAX)
|
||||||
|
MOTEURS_EtatMoteurGauche.commande = SHRT_MAX;
|
||||||
|
else
|
||||||
|
MOTEURS_EtatMoteurGauche.commande = (int16_t) locCmdG;
|
||||||
} else {
|
} else {
|
||||||
if (locCmdG>0) MOTEURS_EtatMoteurGauche.commande=0;
|
if (locCmdG > 0)
|
||||||
else if (locCmdG<SHRT_MIN) MOTEURS_EtatMoteurGauche.commande=SHRT_MIN;
|
MOTEURS_EtatMoteurGauche.commande = 0;
|
||||||
else MOTEURS_EtatMoteurGauche.commande=(int16_t)locCmdG;
|
else if (locCmdG < SHRT_MIN)
|
||||||
|
MOTEURS_EtatMoteurGauche.commande = SHRT_MIN;
|
||||||
|
else
|
||||||
|
MOTEURS_EtatMoteurGauche.commande = (int16_t) locCmdG;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -247,19 +325,30 @@ void MOTEURS_TacheAsservissement( void* params ) {
|
||||||
locCmdD = ((int32_t) MOTEUR_Kp * (int32_t) erreurD) / 100;
|
locCmdD = ((int32_t) MOTEUR_Kp * (int32_t) erreurD) / 100;
|
||||||
|
|
||||||
if (MOTEURS_EtatMoteurDroit.consigne >= 0) {
|
if (MOTEURS_EtatMoteurDroit.consigne >= 0) {
|
||||||
if (locCmdD<0) MOTEURS_EtatMoteurDroit.commande=0;
|
if (locCmdD < 0)
|
||||||
else if (locCmdD>SHRT_MAX) MOTEURS_EtatMoteurDroit.commande=SHRT_MAX;
|
MOTEURS_EtatMoteurDroit.commande = 0;
|
||||||
else MOTEURS_EtatMoteurDroit.commande=(int16_t)locCmdD;
|
else if (locCmdD > SHRT_MAX)
|
||||||
|
MOTEURS_EtatMoteurDroit.commande = SHRT_MAX;
|
||||||
|
else
|
||||||
|
MOTEURS_EtatMoteurDroit.commande = (int16_t) locCmdD;
|
||||||
} else {
|
} else {
|
||||||
if (locCmdD>0) MOTEURS_EtatMoteurDroit.commande=0;
|
if (locCmdD > 0)
|
||||||
else if (locCmdD<SHRT_MIN) MOTEURS_EtatMoteurDroit.commande=SHRT_MIN;
|
MOTEURS_EtatMoteurDroit.commande = 0;
|
||||||
else MOTEURS_EtatMoteurDroit.commande=(int16_t)locCmdD;
|
else if (locCmdD < SHRT_MIN)
|
||||||
|
MOTEURS_EtatMoteurDroit.commande = SHRT_MIN;
|
||||||
|
else
|
||||||
|
MOTEURS_EtatMoteurDroit.commande = (int16_t) locCmdD;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Finalement, on applique les commandes aux moteurs */
|
/* Finalement, on applique les commandes aux moteurs */
|
||||||
MOTEURS_Set(MOTEURS_EtatMoteurGauche.commande, MOTEURS_EtatMoteurDroit.commande);
|
MOTEURS_Set(MOTEURS_EtatMoteurGauche.commande,
|
||||||
|
MOTEURS_EtatMoteurDroit.commande);
|
||||||
|
|
||||||
|
#ifdef TESTS
|
||||||
|
//EndMeasure();
|
||||||
|
#endif /* TESTS */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -271,23 +360,12 @@ typedef struct {
|
||||||
#define MOTEURS_MAX_CORRECTION_POINTS 16
|
#define MOTEURS_MAX_CORRECTION_POINTS 16
|
||||||
|
|
||||||
const MOTEURS_CorrectionPoint MOTEURS_CorrectionPoints[MOTEURS_MAX_CORRECTION_POINTS] =
|
const MOTEURS_CorrectionPoint MOTEURS_CorrectionPoints[MOTEURS_MAX_CORRECTION_POINTS] =
|
||||||
{
|
{ { MOTEURS_MAX_ENCODEUR - 1, 1 }, { 42000, 100 }, { 22000, 2500 }, {
|
||||||
{MOTEURS_MAX_ENCODEUR-1, 1},
|
18000, 5000 }, { 16500, 7500 }, { 15500, 10000 },
|
||||||
{42000, 100},
|
{ 14500, 12500 }, { 13000, 15000 }, { 12500, 17500 }, { 12200,
|
||||||
{22000, 2500},
|
20000 }, { 11500, 22500 }, { 11100, 25000 }, { 11000,
|
||||||
{18000, 5000},
|
27500 }, { 10900, 29000 }, { 10850, 30500 }, { 10800,
|
||||||
{16500, 7500},
|
SHRT_MAX } // 32767
|
||||||
{15500, 10000},
|
|
||||||
{14500, 12500},
|
|
||||||
{13000, 15000},
|
|
||||||
{12500, 17500},
|
|
||||||
{12200, 20000},
|
|
||||||
{11500, 22500},
|
|
||||||
{11100, 25000},
|
|
||||||
{11000, 27500},
|
|
||||||
{10900, 29000},
|
|
||||||
{10850, 30500},
|
|
||||||
{10800, SHRT_MAX} // 32767
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -306,7 +384,8 @@ int16_t MOTEURS_CorrectionEncodeur(MOTEURS_EtatMoteur etat) {
|
||||||
correction = 0;
|
correction = 0;
|
||||||
else { // recherche par dichotomie de l'intervale
|
else { // recherche par dichotomie de l'intervale
|
||||||
while (index < MOTEURS_MAX_CORRECTION_POINTS) {
|
while (index < MOTEURS_MAX_CORRECTION_POINTS) {
|
||||||
if ((MOTEURS_CorrectionPoints[index].encodeur>=encodeur) && (MOTEURS_CorrectionPoints[index+1].encodeur<encodeur)) {
|
if ((MOTEURS_CorrectionPoints[index].encodeur >= encodeur)
|
||||||
|
&& (MOTEURS_CorrectionPoints[index + 1].encodeur < encodeur)) {
|
||||||
// valeur trouvée, on sort
|
// valeur trouvée, on sort
|
||||||
break;
|
break;
|
||||||
} else
|
} else
|
||||||
|
@ -317,10 +396,14 @@ int16_t MOTEURS_CorrectionEncodeur(MOTEURS_EtatMoteur etat) {
|
||||||
correction = SHRT_MAX;
|
correction = SHRT_MAX;
|
||||||
else {
|
else {
|
||||||
A = encodeur - MOTEURS_CorrectionPoints[index + 1].encodeur;
|
A = encodeur - MOTEURS_CorrectionPoints[index + 1].encodeur;
|
||||||
B = MOTEURS_CorrectionPoints[index+1].correction-MOTEURS_CorrectionPoints[index].correction;
|
B = MOTEURS_CorrectionPoints[index + 1].correction
|
||||||
C = MOTEURS_CorrectionPoints[index].encodeur-MOTEURS_CorrectionPoints[index+1].encodeur;
|
- MOTEURS_CorrectionPoints[index].correction;
|
||||||
|
C = MOTEURS_CorrectionPoints[index].encodeur
|
||||||
|
- MOTEURS_CorrectionPoints[index + 1].encodeur;
|
||||||
|
|
||||||
correction = (int16_t)(MOTEURS_CorrectionPoints[index+1].correction - (uint16_t)((A*B)/C));
|
correction =
|
||||||
|
(int16_t) (MOTEURS_CorrectionPoints[index + 1].correction
|
||||||
|
- (uint16_t) ((A * B) / C));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -341,7 +424,9 @@ void MOTEURS_DesactiveAlim(void) {
|
||||||
LL_TIM_DisableCounter(TIM2);
|
LL_TIM_DisableCounter(TIM2);
|
||||||
LL_TIM_DisableCounter(TIM21);
|
LL_TIM_DisableCounter(TIM21);
|
||||||
|
|
||||||
LL_TIM_CC_DisableChannel(TIM3, LL_TIM_CHANNEL_CH1|LL_TIM_CHANNEL_CH2|LL_TIM_CHANNEL_CH3|LL_TIM_CHANNEL_CH4);
|
LL_TIM_CC_DisableChannel(TIM3,
|
||||||
|
LL_TIM_CHANNEL_CH1 | LL_TIM_CHANNEL_CH2 | LL_TIM_CHANNEL_CH3
|
||||||
|
| LL_TIM_CHANNEL_CH4);
|
||||||
|
|
||||||
LL_TIM_CC_DisableChannel(TIM2, LL_TIM_CHANNEL_CH1 | LL_TIM_CHANNEL_CH2);
|
LL_TIM_CC_DisableChannel(TIM2, LL_TIM_CHANNEL_CH1 | LL_TIM_CHANNEL_CH2);
|
||||||
LL_TIM_CC_DisableChannel(TIM21, LL_TIM_CHANNEL_CH1 | LL_TIM_CHANNEL_CH2);
|
LL_TIM_CC_DisableChannel(TIM21, LL_TIM_CHANNEL_CH1 | LL_TIM_CHANNEL_CH2);
|
||||||
|
@ -363,7 +448,9 @@ void MOTEURS_ActiveAlim(void) {
|
||||||
LL_TIM_EnableCounter(TIM2);
|
LL_TIM_EnableCounter(TIM2);
|
||||||
LL_TIM_EnableCounter(TIM21);
|
LL_TIM_EnableCounter(TIM21);
|
||||||
|
|
||||||
LL_TIM_CC_EnableChannel(TIM3, LL_TIM_CHANNEL_CH1|LL_TIM_CHANNEL_CH2|LL_TIM_CHANNEL_CH3|LL_TIM_CHANNEL_CH4);
|
LL_TIM_CC_EnableChannel(TIM3,
|
||||||
|
LL_TIM_CHANNEL_CH1 | LL_TIM_CHANNEL_CH2 | LL_TIM_CHANNEL_CH3
|
||||||
|
| LL_TIM_CHANNEL_CH4);
|
||||||
|
|
||||||
LL_TIM_CC_EnableChannel(TIM2, LL_TIM_CHANNEL_CH1 | LL_TIM_CHANNEL_CH2);
|
LL_TIM_CC_EnableChannel(TIM2, LL_TIM_CHANNEL_CH1 | LL_TIM_CHANNEL_CH2);
|
||||||
LL_TIM_CC_EnableChannel(TIM21, LL_TIM_CHANNEL_CH1 | LL_TIM_CHANNEL_CH2);
|
LL_TIM_CC_EnableChannel(TIM21, LL_TIM_CHANNEL_CH1 | LL_TIM_CHANNEL_CH2);
|
||||||
|
@ -389,8 +476,10 @@ void MOTEURS_ActiveAlim(void) {
|
||||||
void MOTEURS_Set(int16_t cmdGauche, int16_t cmdDroit) {
|
void MOTEURS_Set(int16_t cmdGauche, int16_t cmdDroit) {
|
||||||
int32_t locValGauche, locValDroit;
|
int32_t locValGauche, locValDroit;
|
||||||
|
|
||||||
locValGauche = (int32_t)(((int32_t)cmdGauche * (int32_t)SHRT_MAX)/((int32_t)MOTEURS_MAX_COMMANDE));
|
locValGauche = (int32_t) (((int32_t) cmdGauche * (int32_t) SHRT_MAX)
|
||||||
locValDroit = (int32_t)(((int32_t)cmdDroit * (int32_t)SHRT_MAX)/((int32_t)MOTEURS_MAX_COMMANDE));
|
/ ((int32_t) MOTEURS_MAX_COMMANDE));
|
||||||
|
locValDroit = (int32_t) (((int32_t) cmdDroit * (int32_t) SHRT_MAX)
|
||||||
|
/ ((int32_t) MOTEURS_MAX_COMMANDE));
|
||||||
|
|
||||||
if (LL_GPIO_IsOutputPinSet(GPIOB, SHUTDOWN_5V_Pin) == GPIO_PIN_RESET)
|
if (LL_GPIO_IsOutputPinSet(GPIOB, SHUTDOWN_5V_Pin) == GPIO_PIN_RESET)
|
||||||
MOTEURS_ActiveAlim();
|
MOTEURS_ActiveAlim();
|
||||||
|
@ -426,14 +515,37 @@ void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) {
|
||||||
MOTEURS_EtatMoteurGauche.encodeur = MOTEURS_MAX_ENCODEUR;
|
MOTEURS_EtatMoteurGauche.encodeur = MOTEURS_MAX_ENCODEUR;
|
||||||
MOTEURS_EtatMoteurGauche.encodeurFront = MOTEURS_MAX_ENCODEUR;
|
MOTEURS_EtatMoteurGauche.encodeurFront = MOTEURS_MAX_ENCODEUR;
|
||||||
} else {
|
} else {
|
||||||
MOTEURS_EtatMoteurGauche.encodeur = (uint16_t)LL_TIM_IC_GetCaptureCH1(TIM21);
|
MOTEURS_EtatMoteurGauche.encodeur =
|
||||||
MOTEURS_EtatMoteurGauche.encodeurFront = (uint16_t)LL_TIM_IC_GetCaptureCH2(TIM21);
|
(uint16_t) LL_TIM_IC_GetCaptureCH1(TIM21);
|
||||||
|
MOTEURS_EtatMoteurGauche.encodeurFront =
|
||||||
|
(uint16_t) LL_TIM_IC_GetCaptureCH2(TIM21);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LL_TIM_IsActiveFlag_UPDATE(TIM21))
|
if (LL_TIM_IsActiveFlag_UPDATE(TIM21))
|
||||||
LL_TIM_ClearFlag_UPDATE(TIM21);
|
LL_TIM_ClearFlag_UPDATE(TIM21);
|
||||||
|
|
||||||
MOTEURS_EtatMoteurGauche.moteurLent = 0;
|
MOTEURS_EtatMoteurGauche.moteurLent = 0;
|
||||||
|
|
||||||
|
if (MOTEURS_EtatDifferentiel.distance) {
|
||||||
|
if (MOTEURS_EtatDifferentiel.distance>0) MOTEURS_EtatDifferentiel.distance--;
|
||||||
|
else MOTEURS_EtatDifferentiel.distance++;
|
||||||
|
|
||||||
|
if (MOTEURS_EtatDifferentiel.distance==0) {
|
||||||
|
MOTEURS_EtatMoteurGauche.consigne=0;
|
||||||
|
MOTEURS_EtatMoteurDroit.consigne=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (MOTEURS_EtatDifferentiel.tours) {
|
||||||
|
if (MOTEURS_EtatDifferentiel.tours>0) MOTEURS_EtatDifferentiel.tours--;
|
||||||
|
else MOTEURS_EtatDifferentiel.tours++;
|
||||||
|
|
||||||
|
if (MOTEURS_EtatDifferentiel.tours==0) {
|
||||||
|
MOTEURS_EtatMoteurGauche.consigne=0;
|
||||||
|
MOTEURS_EtatMoteurDroit.consigne=0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
} else { /* moteur droit */
|
} else { /* moteur droit */
|
||||||
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1) {
|
if (htim->Channel == HAL_TIM_ACTIVE_CHANNEL_1) {
|
||||||
|
@ -441,8 +553,10 @@ void HAL_TIM_IC_CaptureCallback(TIM_HandleTypeDef *htim) {
|
||||||
MOTEURS_EtatMoteurDroit.encodeur = MOTEURS_MAX_ENCODEUR;
|
MOTEURS_EtatMoteurDroit.encodeur = MOTEURS_MAX_ENCODEUR;
|
||||||
MOTEURS_EtatMoteurDroit.encodeurFront = MOTEURS_MAX_ENCODEUR;
|
MOTEURS_EtatMoteurDroit.encodeurFront = MOTEURS_MAX_ENCODEUR;
|
||||||
} else {
|
} else {
|
||||||
MOTEURS_EtatMoteurDroit.encodeur = (uint16_t)LL_TIM_IC_GetCaptureCH1(TIM2);
|
MOTEURS_EtatMoteurDroit.encodeur =
|
||||||
MOTEURS_EtatMoteurDroit.encodeurFront = (uint16_t)LL_TIM_IC_GetCaptureCH2(TIM2);
|
(uint16_t) LL_TIM_IC_GetCaptureCH1(TIM2);
|
||||||
|
MOTEURS_EtatMoteurDroit.encodeurFront =
|
||||||
|
(uint16_t) LL_TIM_IC_GetCaptureCH2(TIM2);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LL_TIM_IsActiveFlag_UPDATE(TIM2))
|
if (LL_TIM_IsActiveFlag_UPDATE(TIM2))
|
||||||
|
|
|
@ -13,8 +13,8 @@
|
||||||
void MOTEURS_Init(void);
|
void MOTEURS_Init(void);
|
||||||
//void MOTEURS_Set(uint8_t mot, int16_t val);
|
//void MOTEURS_Set(uint8_t mot, int16_t val);
|
||||||
//void MOTEURS_Test (void);
|
//void MOTEURS_Test (void);
|
||||||
void MOTEURS_Avance(uint32_t distance);
|
void MOTEURS_Avance(int32_t distance);
|
||||||
void MOTEURS_Tourne(uint32_t tours);
|
void MOTEURS_Tourne(int32_t tours);
|
||||||
void MOTEURS_Stop(void);
|
void MOTEURS_Stop(void);
|
||||||
|
|
||||||
void MOTEURS_TimerEncodeurUpdate (TIM_HandleTypeDef *htim);
|
void MOTEURS_TimerEncodeurUpdate (TIM_HandleTypeDef *htim);
|
||||||
|
|
|
@ -181,7 +181,7 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart)
|
||||||
HAL_NVIC_SetPriority(LPUART1_IRQn, 3, 0);
|
HAL_NVIC_SetPriority(LPUART1_IRQn, 3, 0);
|
||||||
HAL_NVIC_EnableIRQ(LPUART1_IRQn);
|
HAL_NVIC_EnableIRQ(LPUART1_IRQn);
|
||||||
/* USER CODE BEGIN LPUART1_MspInit 1 */
|
/* USER CODE BEGIN LPUART1_MspInit 1 */
|
||||||
//HAL_NVIC_SetPriority(LPUART1_IRQn, 2, 0);
|
HAL_NVIC_SetPriority(LPUART1_IRQn, 2, 0);
|
||||||
/* USER CODE END LPUART1_MspInit 1 */
|
/* USER CODE END LPUART1_MspInit 1 */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue