-
|
I have a program for a train that has 2 main functions: In order to work this properly I need to read from sensor roughly every 20ms but the 1 function (data gathering via bluetooth) takes to run roughly 100ms. For this reason I tried to use multitasking to run the train independently from the data gathering. However while trying to multitask I am getting memory allocation error even when I stripped code to minimum just to test it out after couple of runs. My question is then - am I trying to multitask incorrectly or do I need to do some manual memory cleanup each run ? When I try to run program without multitasking it runs just fine the only problem is that train is not able to pick up the action colors because the whole routine takes too long (due to data processing via bluetooth observing). When I try to print out memory allocation there it is showing that free memory is decreasing each run but then it is freed up somehow when it is too low and I never get the allocation error. This is the simplified code: This is the output (removed the first initial 53 runs that run fine): It is failing on the line when I try to read from the color sensor - actual_color = train_sensor.color(). |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
Seems like putting await in front of train_sensor.color() fixed it :-)
|
Beta Was this translation helpful? Give feedback.
Seems like putting await in front of train_sensor.color() fixed it :-)
actual_color = await train_sensor.color()