add drive management

This commit is contained in:
2023-08-31 20:02:41 +02:00
parent 2ece901b08
commit a20667399b
8 changed files with 459 additions and 40 deletions

View File

@ -42,8 +42,8 @@ ALIVE* ALjoy(){
return &theFactory.ALjoy_;
}
ALIVE* ALdrive(){
return &theFactory.ALdrive_;
DRIVE* drive(){
return &theFactory.drive_;
}
@ -79,20 +79,7 @@ void Factory_init() {
ALIVE_setAliveTime(ALcontroller(), KART_CST.CONTROL_ALIVE_TIME);
ALIVE_init(ALjoy());
ALIVE_init(ALdrive());
}
void foo(void* p){
static int16_t speed = 0;
static bool up = true;
if(up) {
speed += 3;
if(speed >100) up = false;
} else {
speed -= 3;
if(speed < -100) up = true;
}
CM_DRIVE_POWER(&speed);
DRIVE_init(drive());
}
//connect objects if required
@ -110,31 +97,21 @@ void Factory_build() {
ALIVE_onBorn(ALjoy(), LED_on, l1());
ALIVE_onDead(ALjoy(), LED_off, l1());
ALIVE_onSetup(ALdrive(), CM_DRIVE_SETUP, NULL);
ALIVE_setAliveTime(ALdrive(), KART_CST.DRIVE_ALIVE_TIME);
ALIVE_onBorn(ALdrive(), LED_on, l2());
ALIVE_onDead(ALdrive(), LED_off, l2());
DRIVE_onRun(drive(), LED_on, l2());
DRIVE_onDead(drive(), LED_off, l2());
BLINKER_setTimeOn(b1(), (KART_CST.DRIVE_STOP_TIME*9)/2);
BLINKER_setTimeOff(b1(), (KART_CST.DRIVE_STOP_TIME*9)/2);
BLINKER_onOn(b1(), foo, NULL);
}
//start all state machines
void Factory_start() {
CAN_startBehaviour();
ALIVE_startBehaviourSender(ALcontroller());
ALIVE_startBehaviourChecker(ALjoy());
//ALIVE_startBehaviourSender(ALcontroller());
//ALIVE_startBehaviourChecker(ALjoy());
ALIVE_emitBorn(ALjoy(), 100, 0);
ALIVE_emitReady(ALjoy(), 200, 0);
ALIVE_startBehaviourChecker(ALdrive());
ALIVE_emitBorn(ALdrive(), 100, 0);
ALIVE_emitReady(ALdrive(), 200, 0);
BLINKER_startBehaviour(b1());
BLINKER_emitBlink(b1(), 300);
DRIVE_startBehaviour(drive());
}

View File

@ -15,6 +15,7 @@
#include "../car.h"
#include "../can_message.h"
#include "../eeprom.h"
#include "../drive.h"
#include "../../board/led/led.h"
#include "../../board/button/button.h"
#include "../../middleware/alive.h"
@ -36,7 +37,7 @@ typedef struct {
ALIVE ALcontroller_;
ALIVE ALjoy_;
ALIVE ALdrive_;
DRIVE drive_;
} Factory;
@ -59,7 +60,7 @@ BLINKER* b1();
ALIVE* ALcontroller();
ALIVE* ALjoy();
ALIVE* ALdrive();
DRIVE* drive();
#endif