找到一个圆的任何电弧的长度 - confrim限值是所要求的圆弧电弧、圆弧、长度、限值

2023-09-11 07:25:19 作者:蓝莓格格巫

此问题上遵循从发现任何弧的长度在一个圆圈

这是这个问题:

我有磁性连接codeR返回从0轴的位置,以4095

I have a magnetic encoder that returns the position of the shaft from 0 to 4095.

伺服有两个逻辑终点,称它们为MAX和MIN并将其设置在软件,并且可以在任何时间改变,并且该轴必须旋转(即行程)上的最大和最小位置之间的一个弧。例如,在图像的蓝色电弧是有效的,但红色不是之间的所有旅行和包括MIN和MAX

The servo has two logical end points, call them MAX and MIN which are set in software and can be changed at any time, and the shaft must rotate (i.e. travel) on one arc between the MAX and MIN positions. For example in the picture the blue arc is valid but the red is not for all travel between and including MIN and MAX.

我试图找出一个简单的算法来验证,其中行程允许在我的圈子里的蓝方,A和B是蓝色圆弧既不是上冲弧,而相反的地方,如果行程允许的弧线为红色,则A和B都上冲弧?

I am trying to work out a simple algorithm to validate that where travel is allowed on the BLUE side of my circle, that A and B are on the BLUE arc and neither are on the RED arc, and the opposite where if the allowed arc of travel is RED, then A and B are both on the RED arc?

注:A和B是通过调用程序设置的,总是在不断变化

Note: A and B are set by the calling program and are always changing.

推荐答案

类似我的回答对您的其他问题:

Similar to my answer on your other question:

if (MIN > MAX)
    // swap MIN and MAX
if (A < MIN)
    A += 4096;
if (B < MIN)
    B += 4096;
if (min(A, B) < MAX && max(A, B) > MAX)
    // error!

首先,你强迫这两点是在最小的同一侧,那么你测试,看看他们是在MAX的两侧。

First you force both points to be on the same side of MIN, then you test to see if they're on opposite sides of MAX.