Here's an idea suggesting that you can get a reading at short intervals, and that yaw can be zeroed at a specific starting point. This is different from another answer that detects full circles from a continuously adapted starting point.
In this approach, we continue to compare the current jerk with the previous yaw, asking if the control point passed 180 degrees or PI . Initially, the checkpoint flag cp_pi is NO , and transmitting it in any direction switches its state. Note that yaw changes sign in two places, at zero point and again on PI to -PI .
Assuming your object has two properties that are persistent between the tick detector, BOOL cp_pi; and float prev_yaw; , we think d_yaw less than PI for crossing 0 and greater than PI for crossing at the opposite end of your circle. When crossing the opposite end, we switch cp_pi . When cp_pi is YES at the intersection 0, we are guaranteed to go through the full circle, since otherwise cp_pi would be switched to NO :
-(void)tick { float yaw = [self zeroedYaw]; if ((fabs(yaw) == PI) || (yaw == 0.0f)) return; if (yaw * prev_yaw < 0) { float d_yaw = fabs(yaw - prev_yaw); if (d_yaw > PI) { cp_pi = ! cp_pi; } else if (cp_pi) {
Please note that to make our life easier, we completely skip the detector function if yaw sits directly on one of the control points.
source share