Error "Error using + Matrix dimensions must agree."

This is the programme:
function [ u ] = 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
kv = 100;
kp = 100;
Z2=diff(s_des,2);
e = (s_des - s);
Y=diff(e);
u = params.mass*(Z2+kp*e+kv*Y+params.gravity);
% FILL IN YOUR CODE HERE
end
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
This is the run command
close all;
clear;
% Hover
z_des =1 ;
% Step
% z_des = 1;
% Given trajectory generator
trajhandle = @(t) fixed_set_point(t, z_des);
% This is your controller
controlhandle = @controller;
% Run simulation with given trajectory generator and controller
[t, z] = height_control(trajhandle, controlhandle);
% % Sample code to get more info on the response
% sim_info = lsiminfo(z, t, z_des);
% disp(['Settling time [s]: ', num2str(sim_info.SettlingTime)]);
% disp(['Overshoot [%]: ', num2str(max(0,(sim_info.Max-z_des)*100))]);

답변 (2개)

James Tursa
James Tursa 2016년 7월 2일

0 개 추천

Type the following at the MATLAB command line:
dbstop if error
Then run your code. It will pause at the line with the error. Examine all of the variables in that line for size to determine the cause of the error.
Walter Roberson
Walter Roberson 2016년 7월 2일
편집: Walter Roberson 2016년 7월 2일

0 개 추천

You have
Z2=diff(s_des,2);
where s_des has been documented to be 2 x 1. diff(s_des,2) is diff(diff(s_des)) and with s_des being length 2, the result is going to be empty. When you later use the result, Z2, in
u = params.mass*(Z2+kp*e+kv*Y+params.gravity)
that is going to lead to an error because you are trying to add an empty array and a non-empty item.

카테고리

도움말 센터File Exchange에서 Control System Toolbox에 대해 자세히 알아보기

태그

질문:

2016년 7월 2일

편집:

2016년 7월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by