Trouble programming sensor reading #1744
-
I'm trying to get the accelerometer read by my custom code and right now, it is outputting bad, not-updated data despite looking like it should be updating. Here is the code static void dbgMessagerTask(void* parameters)
{
Axis3f acc;
while (true)
{
if (sensorsAreCalibrated())
{
// Read accelerometer values
sensorsReadAcc(&acc);
consolePrintf("Acc: (%f,%f,%f) \n",
(double) acc.x,
(double) acc.y,
(double) acc.z
);
sensorsResume();
}
//delay
vTaskDelay(50);
}
} What am I missing that will make it work? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Hi @PapercutSmothie ! Its looking like the queue where sensor data is stored might be empty when you fetch data from it. If so you could take several different approaches. I hope you got the clarification you needed to make this work! |
Beta Was this translation helpful? Give feedback.
Hi!
I think that the stabilizer task reads out the sensor data from the queue before your task. However I agree that sensorsWaitDataReady() should give you what you want.
What I do doubt is that this is a feasible use case. If you manage to read out the sensor data from the queue there is no data for the stabilizer task to read. I highly doubt the Crazyflie will be able to fly without this data.
If you are only looking to print, could you print in the stabilizer task? Or put in the data in another queue or variable in the stabilizer task, for the dbgMessagerTask to read from?