Skip to content

Commit b47fef6

Browse files
committed
fix bugs
1 parent ac1acc5 commit b47fef6

File tree

12 files changed

+45
-17
lines changed

12 files changed

+45
-17
lines changed

ECU/ECU.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@ void ECU::statemachine()
6565
tx_data = packet.build_control_packet(THS_ID, ECU_ID, REQUEST);
6666
state = REQUEST_TH_POS;
6767
}
68+
else if(state == RECEIVE_TH_POS && t > timeout_s) {
69+
state = START;
70+
}
6871
else if(state == CALC_MOTOR_PAR && t > 0) {
6972
motor_par = throttle_pos;
7073
tx_data = packet.build_data_packet(MCU_ID, motor_par);
@@ -74,22 +77,25 @@ void ECU::statemachine()
7477
state = WAIT_FOR_MCU_ACK;
7578
}
7679
else if(state == WAIT_FOR_MCU_ACK && t > 0 && packet.validate_control_packet(ECU_ID, MCU_ID, ACKNOWLEDGE, rx_data)) {
80+
attempt = 1;
81+
tx_data = packet.build_control_packet(THS_ID, ECU_ID, REQUEST);
7782
state = REQUEST_TH_POS;
7883
}
7984
else if(state == WAIT_FOR_MCU_ACK && t > timeout_s && attempt < 4) {
8085
attempt++;
8186
tx_data = packet.build_data_packet(MCU_ID, throttle_pos);
8287
state = SEND_MOTOR_PAR;
8388
}
89+
else if(state == WAIT_FOR_MCU_ACK && t > timeout_s) {
90+
state = START;
91+
}
8492
// else;
8593
} while(state != m_state);
8694

8795
/*** output process image ***/
8896
if(!ini_ok);
89-
else if(state == REQUEST_TH_POS) {
90-
uart->putc(tx_data); }
91-
else if(state == SEND_MOTOR_PAR) {
92-
uart->putc(tx_data); }
97+
else if(state == REQUEST_TH_POS) { uart->putc(tx_data); }
98+
else if(state == SEND_MOTOR_PAR) { uart->putc(tx_data); }
9399
// else;
94100

95101
ini_ok = 1;

ECU/keil_stm32f103/ecu_stm32f103.uvoptx

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,31 @@
148148
<Name>-U-O206 -O206 -SF4000 -C0 -A0 -I0 -HNlocalhost -HP7184 -P1 -N00("ARM CoreSight SW-DP") -D00(1BA01477) -L00(0) -TO18 -TC10000000 -TP21 -TDS8007 -TDT0 -TDC1F -TIEFFFFFFFF -TIP8 -FO7 -FD20000000 -FC1000 -FN1 -FF0STM32F10x_128.FLM -FS08000000 -FL020000 -FP0($$Device:STM32F103RB$Flash\STM32F10x_128.FLM)</Name>
149149
</SetRegEntry>
150150
</TargetDriverDllRegistry>
151-
<Breakpoint/>
151+
<Breakpoint>
152+
<Bp>
153+
<Number>0</Number>
154+
<Type>0</Type>
155+
<LineNumber>36</LineNumber>
156+
<EnabledFlag>1</EnabledFlag>
157+
<Address>134229568</Address>
158+
<ByteObject>0</ByteObject>
159+
<HtxType>0</HtxType>
160+
<ManyObjects>0</ManyObjects>
161+
<SizeOfObject>0</SizeOfObject>
162+
<BreakByAccess>0</BreakByAccess>
163+
<BreakIfRCount>1</BreakIfRCount>
164+
<Filename>..\ECU.cpp</Filename>
165+
<ExecCommand></ExecCommand>
166+
<Expression>\\STM32F103RB\../ECU.cpp\36</Expression>
167+
</Bp>
168+
</Breakpoint>
169+
<WatchWindow1>
170+
<Ww>
171+
<count>0</count>
172+
<WinNumber>1</WinNumber>
173+
<ItemText>state</ItemText>
174+
</Ww>
175+
</WatchWindow1>
152176
<Tracepoint>
153177
<THDelay>0</THDelay>
154178
</Tracepoint>

ECU/keil_stm32f103/ecu_stm32f103.uvprojx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@
312312
</ArmAdsMisc>
313313
<Cads>
314314
<interw>0</interw>
315-
<Optim>3</Optim>
315+
<Optim>4</Optim>
316316
<oTime>0</oTime>
317317
<SplitLS>0</SplitLS>
318318
<OneElfS>1</OneElfS>

ECU/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
/*******************************************************************/
3333
Serial uart(UART_TX, UART_RX, 9600);
34-
ECU ecu(&uart, 0.1, 1.0);
34+
ECU ecu(&uart, 2e-3, 0.02);
3535

3636
int main (void)
3737
{

Engine/Engine.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "Engine.h"
22

3-
Engine::Engine(Serial* uart, DigitalOut* engine, double t_period_s, double timeout_s) : uart(uart), engine(engine), t_period_s(t_period_s), timeout_s(timeout_s) {
3+
Engine::Engine(Serial* uart, DigitalOut* engine, double t_period_s) : uart(uart), engine(engine), t_period_s(t_period_s) {
44
ini_ok = 0;
55
timer = new RtosTimer(callback(this, &Engine::statemachine), osTimerPeriodic);
66
}

Engine/Engine.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ typedef enum state_e
1414

1515
class Engine {
1616
public:
17-
Engine(Serial* uart, DigitalOut* engine, double t_period_s, double timeout_s);
17+
Engine(Serial* uart, DigitalOut* engine, double t_period_s);
1818
~Engine();
1919
void start();
2020
void stop();
@@ -34,7 +34,6 @@ class Engine {
3434
uint8_t tx_data;
3535
uint8_t motor_param;
3636
double t_period_s;
37-
double timeout_s;
3837
};
3938

4039
#endif // __ENGINE_H

Engine/keil_stm32f072/engine_stm32f072.uvprojx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@
312312
</ArmAdsMisc>
313313
<Cads>
314314
<interw>0</interw>
315-
<Optim>4</Optim>
315+
<Optim>3</Optim>
316316
<oTime>0</oTime>
317317
<SplitLS>0</SplitLS>
318318
<OneElfS>1</OneElfS>

Engine/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
/*******************************************************************/
3434
Serial uart(UART_TX, UART_RX, 9600);
3535
DigitalOut engine_pp(ENGINE_PP, 0);
36-
Engine engine(&uart, &engine_pp, 0.1, 1.0);
36+
Engine engine(&uart, &engine_pp, 2e-3);
3737

3838
int main (void)
3939
{

Throttle/Throttle.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include "Throttle.h"
22

3-
Throttle::Throttle(Serial* uart, DigitalIn* i_throttle, double t_period_s, double timeout_s) : uart(uart), i_throttle(i_throttle), t_period_s(t_period_s), timeout_s(timeout_s) {
3+
Throttle::Throttle(Serial* uart, DigitalIn* i_throttle, double t_period_s) : uart(uart), i_throttle(i_throttle), t_period_s(t_period_s) {
44
ini_ok = 0;
55
timer = new RtosTimer(callback(this, &Throttle::statemachine), osTimerPeriodic);
66
}

Throttle/Throttle.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ typedef enum state_e
1414

1515
class Throttle {
1616
public:
17-
Throttle(Serial* uart, DigitalIn* i_throttle, double t_period_s, double timeout_s);
17+
Throttle(Serial* uart, DigitalIn* i_throttle, double t_period_s);
1818
~Throttle();
1919
void start();
2020
void stop();
@@ -33,7 +33,6 @@ class Throttle {
3333
double t;
3434
uint8_t tx_data;
3535
double t_period_s;
36-
double timeout_s;
3736
};
3837

3938
#endif // __THROTTLE_H

0 commit comments

Comments
 (0)