根据Matlab x,y,z坐标进行伺服电机布线

时间:2019-05-26 13:29:13

标签: matlab arduino-uno servo

我致力于导弹的路由。我没有计算导弹的飞行x,y,z坐标。我有关于导弹x,y,z坐标的数据集。我的目标是根据x,y,z坐标移动伺服电机。

我的输入是3维(x,y,z)。我想在两个维度上进行模拟。为此,我使用矢量计算。伺服电机的取值范围为0-1。但是结果大于1。当结果以相同的速率减少时,结果小于0。但是我仍然得到错误

  

类型为'matlab.graphics.chart.primitive.Surface'的输入参数的未定义函数'writePosition'。

如果您能帮助我,我将不胜感激。

我的数据示例:

missile_x = 0.015
missile_y = 0.054 
missile_z = 0.254  
missile_flight = 0.00018794

我的航班轮换代码:

missile_x = vpa(Xval{id}(k)/10,5)
missile_y = vpa(Yval{id}(k)/10,5)
missile_z = vpa(Zval{id}(k)/10,5)

missile_flight = vpa(0.00555556*(missile_x^2+missile_y^2+missile_z^2)^1/2,5)

writePosition(s, missile_flight);
current_pos = readPosition(s);
current_pos = current_pos*missile_flight;
fprintf('Current motor position is %d degrees\n', current_pos);

pause(2);

X,Y,Z导弹的计算代码:

dt = 0.005; %time step
g = 9.81; %gravity
ro = 1.2; %air density
A = pi*(0.2)^2; % reference area

Vmag = 0; % missile velocity vectoral value [m/sn]
t = 0;
T(1) = t; 
U(1) = 0;  %the missile is initially at rest at t = 0; So the velocity is 0
V(1) = 0;
W(1) = 0;
X(1) = X0;
Y(1) = Y0;
Z(1) = Z0;

n = 1;
h = interp2(x_terrain, y_terrain, h_terrain,X(1), Y(1));
while (Z(n) >= h)     
 [Thx, Thy, Thz] = thrust(t, Thmag0, theta, phi, Tburn, U(n), V(n), W(n)); 
 Vmag = (U(n)^2 + V(n)^2 + W(n)^2)^(1/2);
 Thmag = (Thx^2 + Thy^2 + Thz^2)^(1/2);
 m = mass(t, m0, mf, Tburn); 
 [rho,sound_speed] = atmosphere(Z(n));
 Cd = drag_coeff(Vmag,sound_speed);
 U(n+1) = U(n) + (Thx/m - (Cd*rho*A/(2*m))*(U(n)*(U(n)^2+V(n)^2+W(n)^2)^(1/2)))*dt;
 V(n+1) = V(n) + (Thy/m - (Cd*rho*A/(2*m)*(V(n)*(U(n)^2+V(n)^2+W(n)^2)^(1/2))))*dt;
 W(n+1) = W(n) + (Thz/m - (Cd*rho*A/(2*m))*(W(n)*(U(n)^2+V(n)^2+W(n)^2)^(1/2)) - g)*dt;
 X(n+1) = X(n) + U(n+1)*dt;
 Y(n+1) = Y(n) + V(n+1)*dt;
 Z(n+1) = Z(n) + W(n+1)*dt;
 h = interp2(x_terrain, y_terrain, h_terrain, ...
 X(end), Y(end));

 t = t + dt;
 T(n+1) = t; 
 n = n+1  ;

end
  Tval = T;
  Xval = X;
  Yval = Y;
  Zval = Z;

0 个答案:

没有答案