From d31544783c293b9b8ce7fdcc256f3ddf4f83eb0b Mon Sep 17 00:00:00 2001 From: Klagarge Date: Thu, 31 Aug 2023 17:02:23 +0200 Subject: [PATCH] test drive --- 306-controller_interface.X/app/can_message.c | 11 ++++++ .../app/factory/factory.c | 39 +++++++++++++++++-- .../app/factory/factory.h | 2 + .../middleware/eeprom.c | 8 ++-- 4 files changed, 52 insertions(+), 8 deletions(-) diff --git a/306-controller_interface.X/app/can_message.c b/306-controller_interface.X/app/can_message.c index 2075c90..763192a 100644 --- a/306-controller_interface.X/app/can_message.c +++ b/306-controller_interface.X/app/can_message.c @@ -208,6 +208,15 @@ void CM_processIncome(uint8_t idSender, uint8_t idMsg, uint32_t data){ if(idMsg == 0xF) { // DRIVE_ALIVE // 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 } @@ -324,6 +333,8 @@ void CM_DRIVE_POWER(void* p) { torque.full = *((int16_t*) p); tmpData.separate.byte0 = torque.separate.byte1; tmpData.separate.byte1 = torque.separate.byte0; + tmpData.separate.byte2 = 0; + tmpData.separate.byte3 = 0; CAN_Send(4, 1, tmpData.full); } diff --git a/306-controller_interface.X/app/factory/factory.c b/306-controller_interface.X/app/factory/factory.c index c3d018b..a2905fa 100644 --- a/306-controller_interface.X/app/factory/factory.c +++ b/306-controller_interface.X/app/factory/factory.c @@ -42,6 +42,10 @@ ALIVE* ALjoy(){ return &theFactory.ALjoy_; } +ALIVE* ALdrive(){ + return &theFactory.ALdrive_; +} + //initialize all objects void Factory_init() { @@ -75,6 +79,20 @@ 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); } //connect objects if required @@ -84,26 +102,39 @@ void Factory_build() { ALIVE_onAlive(ALcontroller(), CM_CONTROLLER_ALIVE, NULL); - BLINKER_onOn(b1(), LED_on, l6()); - BLINKER_onOff(b1(), LED_off, l6()); + //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_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 void Factory_start() { CAN_startBehaviour(); - BLINKER_startBehaviour(b1()); - BLINKER_emitBlink(b1(), 0); 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); + } diff --git a/306-controller_interface.X/app/factory/factory.h b/306-controller_interface.X/app/factory/factory.h index 9835497..80a6acb 100644 --- a/306-controller_interface.X/app/factory/factory.h +++ b/306-controller_interface.X/app/factory/factory.h @@ -36,6 +36,7 @@ typedef struct { ALIVE ALcontroller_; ALIVE ALjoy_; + ALIVE ALdrive_; } Factory; @@ -58,6 +59,7 @@ BLINKER* b1(); ALIVE* ALcontroller(); ALIVE* ALjoy(); +ALIVE* ALdrive(); #endif \ No newline at end of file diff --git a/306-controller_interface.X/middleware/eeprom.c b/306-controller_interface.X/middleware/eeprom.c index 874f425..77708e7 100644 --- a/306-controller_interface.X/middleware/eeprom.c +++ b/306-controller_interface.X/middleware/eeprom.c @@ -35,11 +35,11 @@ void MEM_init(){ KART_CST.JOYSTICK_PARAM2 = 1; KART_CST.JOYSTICK_ALIVE_TIME = 25; - KART_CST.DISPLAY_ALIVE_TIME = 100; + KART_CST.DISPLAY_ALIVE_TIME = 100; - KART_CST.DRIVE_SPEED_TIME = 5; - KART_CST.DRIVE_STOP_TIME = 20; - KART_CST.DRIVE_ALIVE_TIME = 10; + KART_CST.DRIVE_SPEED_TIME = 20; + KART_CST.DRIVE_STOP_TIME = 10; + KART_CST.DRIVE_ALIVE_TIME = 25; KART_CST.STEERING_ALIVE_TIME = 100;