How can I debug this communication issue to ensure ControlTask always reads the latest data?

@Middleware & OS I'm working on a robotic arm controlled by FreeRTOS with two tasks; SensorTask which continuously reads joint angles and stores them in a shared variable (a global array), and ControlTask which retrieves sensor data and calculates motor commands every 10ms. ControlTask sometimes reads outdated data, causing jittery movements. I've verified SensorTask updates the variable correctly. Error Message:
Error: ControlTask - Inconsistency detected between expected and actual sensor value
Error: ControlTask - Inconsistency detected between expected and actual sensor value
How can I debug this communication issue to ensure ControlTask always reads the latest data?
Solution:
If you must use a global variable try a semaphore to protect the shared variable during access. The sensor task acquires the semaphore before updating the variable , and the control task acquires it before reading the variable all these are so you can make only one task access the variable at a time. @Marvee Amasi
Jump to solution
3 Replies
UC GEE
UC GEE6mo ago
Do you know how to use queue ? Instead of using global variable. @Marvee Amasi
Marvee Amasi
Marvee Amasi6mo ago
@UC GEE okay I do in a way , but it's just what I am working with
Solution
UC GEE
UC GEE6mo ago
If you must use a global variable try a semaphore to protect the shared variable during access. The sensor task acquires the semaphore before updating the variable , and the control task acquires it before reading the variable all these are so you can make only one task access the variable at a time. @Marvee Amasi
Want results from more Discord servers?
Add your server