I have the following Thread.cpp:
while (1)
{
rplidar_response_measurement_node_t nodes[8192];
size_t count = _countof(nodes);
op_result = drv->grabScanData(nodes, count);
if (IS_OK(op_result))
{
drv->ascendScanData(nodes, count);
for (int pos = 0; pos < (int)count ; ++pos)
{
nodes[pos].sync_quality & RPLIDAR_RESP_MEASUREMENT_SYNCBIT;
nodes[pos].angle_q6_checkbit >> RPLIDAR_RESP_MEASUREMENT_ANGLE_SHIFT/64.0f;
nodes[pos].distance_q2/4.0f;
nodes[pos].sync_quality >> RPLIDAR_RESP_MEASUREMENT_QUALITY_SHIFT;
}
}
}
return ;
}
Motion Thread.cpp
void Motion::Synchronization(QString motiontype)
{
if(motiontype == START)
{
if(269<Thread::angle_q6_checkbit && Thread::angle_q6_checkbit <271)
{
if(Thread::distance_q2>1200)
{
dist_left=1200;
}
else
{
dist_left=Thread::distance_q2;
}
cout<<"Motion +Stuff+="<< endl;
}
}
}
This isn't my exact code, this is the part where I will get the data and storing data into the variable. distance_q2, angle_q6_checkbit
, etc. are NOT an atomic variable, so reading and writing them from a different thread is not consistent!! In the same thread, if I tried to print data I am getting the proper reading. The output is given below.
Now, I have tried to take the data for processing or other my stuff. Storing the distance, angle quality data like to Thread::sync_quality, Thread::angle_q6_checkbit, Thread::distance
Taking data from Laser data Thread.cpp
to motion.cpp
thread (cout data in motion thread):
cout << "distance "<< Thread::distance_q2 << endl;
cout << "angle "<< Thread::angle_q6_checkbit << endl;
cout << "quality level "<< int(Thread::sync_qualitylevel) << endl;
I am getting improper output (getting only 359 degrees, that also improper). I can't able to conclude. Now the output for the above is:
I've tried to declare then as atomic, but I can't see any improvement. Help would be greatly appreciated.