我正在尝试使用 Matlab 使用编码器跟踪旋转物体。我有一个编码器,它可以给我物体的角位置,然后我将此信息传递给激光器,但是如何以与物体相同的速度移动激光器?因为现在激光比物体慢,而且跟不上!我写了这段代码,有人有什么建议吗?
Alpha=pi/2
Positions = [];
t0 = clock;
while etime(clock,t0)<20;
position = data.Position; %here I read the angular position from the encoder
Positions = [Positions position];
A = [floor(Positions/360)];
angPos = position-(floor(position/360))*360;
AngPos = [Positions - A*360];
angRad = angPos*pi/180;
AngRad = [AngPos*pi/180];
Angle = angRad+Alpha;
thetaX = atan(cos(Angle).*(r/d));
thetaY = atan(sin(Angle).*(r/d));
VoltX=-(5/20)*thetaX*180/pi;
VoltY=(5/20)*thetaY*180/pi;
VoltageLimit = 10;
if (max(abs(VoltX))>VoltageLimit) || (max(abs(VoltY))>VoltageLimit)
error('Voltages too large');
end
session.outputSingleScan([VoltX VoltY]); %here I send the laser the angular position obtained before
data = motorA.ReadFromNXT();
end
我知道我应该加上速度,所以我可以以与物体相同的速度移动激光,但我不知道如何给激光那个速度值!
sec = etime(clock,t0);
Sec = [Sec sec];
vel=(diff(Positions)/diff(Sec));
Vel = [Vel vel]; %(deg/s);
也许这是一个愚蠢的问题,但我在 Matlab 中很新!谢谢!!!