add blinker debug

This commit is contained in:
Rémi Heredero 2023-09-05 08:52:27 +02:00
parent 6edca8bb82
commit 32f1bd73b4
6 changed files with 34 additions and 71 deletions

View File

@ -13,7 +13,7 @@
void DRIVE_init(DRIVE* me){
me->state = STDR_INIT;
ALIVE_init(&me->myChecker);
ALIVE_init(&me->myChecker, 2);
ALIVE_onSetup(&me->myChecker, CM_DRIVE_SETUP, &ALWAYSTRUE);
ALIVE_onWait(&me->myChecker, DRIVE_emitStart, me);
ALIVE_onDead(&me->myChecker, DRIVE_emitStop, me);

View File

@ -5,24 +5,6 @@
static Factory theFactory;
//all the getters
LED* l1() {
return &theFactory.l1_;
}
LED* l2() {
return &theFactory.l2_;
}
LED* l3() {
return &theFactory.l3_;
}
LED* l4() {
return &theFactory.l4_;
}
LED* l5() {
return &theFactory.l5_;
}
LED* l6() {
return &theFactory.l6_;
}
LED* l7() {
return &theFactory.l7_;
}
@ -30,10 +12,6 @@ LED* l8() {
return &theFactory.l8_;
}
BLINKER* b1() {
return &theFactory.b1_;
}
ALIVE* ALcontroller(){
return &theFactory.ALcontroller_;
}
@ -53,36 +31,20 @@ STEERING* steering(){
//initialize all objects
void Factory_init() {
LED_init(l1(), 1);
LED_init(l2(), 2);
LED_init(l3(), 3);
LED_init(l4(), 4);
LED_init(l5(), 5);
LED_init(l6(), 6);
LED_init(l7(), 7);
LED_init(l8(), 8);
LED_initHW(l1());
LED_initHW(l2());
LED_initHW(l3());
LED_initHW(l4());
LED_initHW(l5());
LED_initHW(l6());
LED_initHW(l7());
LED_initHW(l8());
BLINKER_init(b1());
CAN_init();
CAN_setSender(1);
LED_off(l1());
MEM_init();
ALIVE_init(ALcontroller());
ALIVE_init(ALcontroller(), 6);
ALIVE_setAliveTime(ALcontroller(), KART_CST.CONTROL_ALIVE_TIME);
ALIVE_init(ALjoy());
ALIVE_init(ALjoy(), 1);
DRIVE_init(drive());
STEERING_init(steering());
}
@ -94,19 +56,16 @@ void Factory_build() {
ALIVE_onAlive(ALcontroller(), CM_CONTROLLER_ALIVE, NULL);
//BLINKER_onOn(b1(), LED_on, l6());
//BLINKER_onOff(b1(), LED_off, l6());
ALIVE_onSetup(ALjoy(), CM_JOY_SETUP, NULL);
ALIVE_setAliveTime(ALjoy(), KART_CST.JOYSTICK_ALIVE_TIME);
ALIVE_onBorn(ALjoy(), LED_on, l1());
ALIVE_onDead(ALjoy(), LED_off, l1());
//ALIVE_onBorn(ALjoy(), LED_on, l1());
//ALIVE_onDead(ALjoy(), LED_off, l1());
DRIVE_onRun(drive(), LED_on, l2());
DRIVE_onDead(drive(), LED_off, l2());
//DRIVE_onRun(drive(), LED_on, l2());
//DRIVE_onDead(drive(), LED_off, l2());
STEERING_onRun(steering(), LED_on, l3());
STEERING_onDead(steering(), LED_off, l3());
//STEERING_onRun(steering(), LED_on, l3());
//STEERING_onDead(steering(), LED_off, l3());
}

View File

@ -25,17 +25,9 @@
typedef struct {
LED l1_;
LED l2_;
LED l3_;
LED l4_;
LED l5_;
LED l6_;
LED l7_;
LED l8_;
BLINKER b1_;
ALIVE ALcontroller_;
ALIVE ALjoy_;
DRIVE drive_;
@ -49,17 +41,9 @@ void Factory_build();
void Factory_start();
//these are global getters for our objects
LED* l1();
LED* l2();
LED* l3();
LED* l4();
LED* l5();
LED* l6();
LED* l7();
LED* l8();
BLINKER* b1();
ALIVE* ALcontroller();
ALIVE* ALjoy();
DRIVE* drive();

View File

@ -12,7 +12,7 @@
void STEERING_init(STEERING* me){
me->state = STST_INIT;
ALIVE_init(&me->myChecker);
ALIVE_init(&me->myChecker, 3);
ALIVE_onSetup(&me->myChecker, CM_STEERING_SETUP, &ALWAYSFALSE);
ALIVE_onWait(&me->myChecker, STEERING_emitStart, me);
ALIVE_onDead(&me->myChecker, STEERING_emitStop, me);

View File

@ -7,7 +7,7 @@
#include "alive.h"
void ALIVE_init(ALIVE* me){
void ALIVE_init(ALIVE* me, uint8_t led){
me->state = STAL_INIT;
me->isAlive = false;
me->checker = false;
@ -20,14 +20,23 @@ void ALIVE_init(ALIVE* me){
me->dead.f = NULL;
me->alive.f = NULL;
me->break_cb.f = NULL;
LED_init(&me->debugLed, led);
LED_initHW(&me->debugLed);
BLINKER_init(&me->debugBlinker);
BLINKER_setTimeOn(&me->debugBlinker, 50);
BLINKER_setTimeOff(&me->debugBlinker, 50);
BLINKER_onOn(&me->debugBlinker, LED_on, &me->debugLed);
BLINKER_onOff(&me->debugBlinker, LED_off, &me->debugLed);
}
void ALIVE_startBehaviourChecker(ALIVE* me){
POST(me, &ALIVE_processEvent, evALinitChecker, 0, 0);
BLINKER_startBehaviour(&me->debugBlinker);
POST(me, &ALIVE_processEvent, evALinitChecker, 10, 0);
}
void ALIVE_startBehaviourSender(ALIVE* me){
POST(me, &ALIVE_processEvent, evALinitSender, 0, 0);
BLINKER_startBehaviour(&me->debugBlinker);
POST(me, &ALIVE_processEvent, evALinitSender, 10, 0);
}
bool ALIVE_processEvent(Event* ev) {
@ -39,6 +48,7 @@ bool ALIVE_processEvent(Event* ev) {
switch (me->state) { // onState
case STAL_INIT:
LED_on(&me->debugLed);
if (ev->id == evALinitChecker) {
me->state = STAL_SETUP;
}
@ -125,12 +135,14 @@ bool ALIVE_processEvent(Event* ev) {
break;
case STAL_WAIT:
BLINKER_endBlink(&me->debugBlinker);
break;
case STAL_DEAD:
break;
case STAL_ALIVE:
BLINKER_endBlink(&me->debugBlinker);
break;
case STAL_BREAK:
@ -155,6 +167,8 @@ bool ALIVE_processEvent(Event* ev) {
break;
case STAL_WAIT:
LED_off(&me->debugLed);
BLINKER_emitBlink(&me->debugBlinker, 0);
if (me->wait.f != NULL) {
me->wait.f(me->wait.p);
}
@ -167,6 +181,8 @@ bool ALIVE_processEvent(Event* ev) {
break;
case STAL_ALIVE:
LED_off(&me->debugLed);
BLINKER_emitBlink(&me->debugBlinker, 0);
me->sender = true;
break;

View File

@ -8,6 +8,8 @@
#define ALIVE_H
#include "../xf/xf.h"
#include "../board/led/led.h"
#include "../middleware/blinker.h"
typedef enum {
STAL_INIT = 20,
@ -37,6 +39,8 @@ typedef struct {
typedef struct {
ALIVE_STATES state;
LED debugLed;
BLINKER debugBlinker;
bool isAlive;
bool checker;
bool sender;
@ -54,7 +58,7 @@ typedef struct {
* Initialize the ALIVE
* @param me the ALIVE itself
*/
void ALIVE_init(ALIVE* me);
void ALIVE_init(ALIVE* me, uint8_t led);
/**
* Start the ALIVE state machine for checker part