test drive

This commit is contained in:
Rémi Heredero 2023-08-31 17:02:23 +02:00
parent dc6e4ec65a
commit d31544783c
4 changed files with 52 additions and 8 deletions

View File

@ -208,6 +208,15 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){
if(idMsg == 0xF) { // DRIVE_ALIVE if(idMsg == 0xF) { // DRIVE_ALIVE
// statusH statusL - - // statusH statusL - -
ALIVE_ISALIVE(ALdrive());
if(ALdrive()->state == STAL_DEAD){
KART_CST.DRIVE_SPEED_TIME = MEM_read_1_byte(MEMADD_DRIVE_SPEED_TIME);
KART_CST.DRIVE_STOP_TIME = MEM_read_1_byte(MEMADD_DRIVE_STOP_TIME);
KART_CST.DRIVE_ALIVE_TIME = MEM_read_1_byte(MEMADD_DRIVE_ALIVE_TIME);
ALIVE_setAliveTime(ALdrive(), KART_CST.DRIVE_ALIVE_TIME);
ALIVE_emitBorn(ALdrive(), 0, 0);
ALIVE_emitReady(ALdrive(), 100, 0);
}
// TODO drive say ALIVE // TODO drive say ALIVE
} }
@ -324,6 +333,8 @@ void CM_DRIVE_POWER(void* p) {
torque.full = *((int16_t*) p); torque.full = *((int16_t*) p);
tmpData.separate.byte0 = torque.separate.byte1; tmpData.separate.byte0 = torque.separate.byte1;
tmpData.separate.byte1 = torque.separate.byte0; tmpData.separate.byte1 = torque.separate.byte0;
tmpData.separate.byte2 = 0;
tmpData.separate.byte3 = 0;
CAN_Send(4, 1, tmpData.full); CAN_Send(4, 1, tmpData.full);
} }

View File

@ -42,6 +42,10 @@ ALIVE* ALjoy(){
return &theFactory.ALjoy_; return &theFactory.ALjoy_;
} }
ALIVE* ALdrive(){
return &theFactory.ALdrive_;
}
//initialize all objects //initialize all objects
void Factory_init() { void Factory_init() {
@ -75,6 +79,20 @@ void Factory_init() {
ALIVE_setAliveTime(ALcontroller(), KART_CST.CONTROL_ALIVE_TIME); ALIVE_setAliveTime(ALcontroller(), KART_CST.CONTROL_ALIVE_TIME);
ALIVE_init(ALjoy()); 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);
} }
//connect objects if required //connect objects if required
@ -84,26 +102,39 @@ void Factory_build() {
ALIVE_onAlive(ALcontroller(), CM_CONTROLLER_ALIVE, NULL); ALIVE_onAlive(ALcontroller(), CM_CONTROLLER_ALIVE, NULL);
BLINKER_onOn(b1(), LED_on, l6()); //BLINKER_onOn(b1(), LED_on, l6());
BLINKER_onOff(b1(), LED_off, l6()); //BLINKER_onOff(b1(), LED_off, l6());
ALIVE_onSetup(ALjoy(), CM_JOY_SETUP, NULL); ALIVE_onSetup(ALjoy(), CM_JOY_SETUP, NULL);
ALIVE_setAliveTime(ALjoy(), KART_CST.JOYSTICK_ALIVE_TIME); ALIVE_setAliveTime(ALjoy(), KART_CST.JOYSTICK_ALIVE_TIME);
ALIVE_onBorn(ALjoy(), LED_on, l1()); ALIVE_onBorn(ALjoy(), LED_on, l1());
ALIVE_onDead(ALjoy(), LED_off, 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());
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 //start all state machines
void Factory_start() { void Factory_start() {
CAN_startBehaviour(); CAN_startBehaviour();
BLINKER_startBehaviour(b1());
BLINKER_emitBlink(b1(), 0);
ALIVE_startBehaviourSender(ALcontroller()); ALIVE_startBehaviourSender(ALcontroller());
ALIVE_startBehaviourChecker(ALjoy()); ALIVE_startBehaviourChecker(ALjoy());
ALIVE_emitBorn(ALjoy(), 100, 0); ALIVE_emitBorn(ALjoy(), 100, 0);
ALIVE_emitReady(ALjoy(), 200, 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);
} }

View File

@ -36,6 +36,7 @@ typedef struct {
ALIVE ALcontroller_; ALIVE ALcontroller_;
ALIVE ALjoy_; ALIVE ALjoy_;
ALIVE ALdrive_;
} Factory; } Factory;
@ -58,6 +59,7 @@ BLINKER* b1();
ALIVE* ALcontroller(); ALIVE* ALcontroller();
ALIVE* ALjoy(); ALIVE* ALjoy();
ALIVE* ALdrive();
#endif #endif

View File

@ -37,9 +37,9 @@ void MEM_init(){
KART_CST.DISPLAY_ALIVE_TIME = 100; KART_CST.DISPLAY_ALIVE_TIME = 100;
KART_CST.DRIVE_SPEED_TIME = 5; KART_CST.DRIVE_SPEED_TIME = 20;
KART_CST.DRIVE_STOP_TIME = 20; KART_CST.DRIVE_STOP_TIME = 10;
KART_CST.DRIVE_ALIVE_TIME = 10; KART_CST.DRIVE_ALIVE_TIME = 25;
KART_CST.STEERING_ALIVE_TIME = 100; KART_CST.STEERING_ALIVE_TIME = 100;