How to deal with dimensions of matrices being concatenated not consistent.

2 ビュー (過去 30 日間)
Antoine Compagnie
Antoine Compagnie 2016 年 6 月 20 日
コメント済み: John D'Errico 2016 年 8 月 14 日
I am trying to create a Proportional Derivative controller with the following equation:
I need to first implement a PD controller for height control of the quadrotor. Then, tune the proportional gain (K p ) and derivative gain (K v ) in a file controller.m until the quadrotor converges quickly and smoothly to a step response input.
With e and dot e which can be calculated from the current and desired states (z, z des , z, ̇ z ̇ des ).
I tried:
function [ u ] = pd_controller(~, s, s_des, params)
%PD_CONTROLLER PD controller for the height
%
% s: 2x1 vector containing the current state [z; v_z]
% s_des: 2x1 vector containing desired state [z; v_z]
% params: robot parameters
u = 0;
e1=s_des*[1 0]-s*[1 0];
e2= s_des*[0 1]-s*[0 1];
% FILL IN YOUR CODE HERE
K = [500 1];
% z(t) = dsolve(diff(z,t) == t*z)
u =params.mass*(([0 1]*s_des*-[0 1]*s)/(0.9)+e1*(K*[0 ;1])-e2*(K*[0;1])+params.gravity);
%u = params.mass*(params.gravity);
end
Yet, it gives
>> runsim
Initializing figures...
Simulation Running....
20 e1=s_des*[1 0]-s*[1 0];
Error using vertcat
Dimensions of matrices being concatenated are not consistent.
Error in sys_eom (line 9)
sdot = [s(2);
Error in height_control>@(t,s)sys_eom(t,s,controlhandle,trajhandle,params)
Error in odearguments (line 87)
f0 = feval(ode,t0,y0,args{:}); % ODE15I sets args{1} to yp0.
Error in ode45 (line 115)
odearguments(FcnHandlesUsed, solver_name, ode, tspan, y0, options, varargin);
Error in height_control (line 80)
[tsave, xsave] = ode45(@(t,s) sys_eom(t, s, controlhandle, trajhandle, params), timeint, x);
Error in runsim (line 17)
[t, z] = height_control(trajhandle, controlhandle);
Here is the sys_eom.m file:
function [ sdot ] = sys_eom(t, s, controlhandle, trajhandle, params)
% sys_eom Differential equation for the height control system
s_des = trajhandle(t);
u_des = controlhandle(t, s, s_des, params);
u_clamped = min(max(params.u_min, u_des), params.u_max);
sdot = [s(2);
u_clamped/params.mass - params.gravity];
end
  2 件のコメント
Are Mjaavatten
Are Mjaavatten 2016 年 8 月 14 日
It is not possible to diagnose your problem from the information you have provided.
You should be able to sort out the problem yourself by using the debugger:
Select "Stop on error" under Breakpoints in the editor toolstrip. Then examine the sizes of the arrays being concatenated when execution stops in line 9 of sys_eom.
John D'Errico
John D'Errico 2016 年 8 月 14 日
Exactly. You can simply use the debugger to see the variables at the point this error arises. What shape and size are they? Think about why that happened. Why were they the sizes they were? What needs to happen?

サインインしてコメントする。

回答 (0 件)

カテゴリ

Help Center および File ExchangeVerification, Validation, and Test についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by