【发布时间】:2019-02-10 19:52:17
【问题描述】:
我正在尝试使用 ode45 确定差动驱动机器人的位姿 (x,y,theta)。我下面的代码解决了 x 位置,但我遇到了初始条件的问题。我将它设置为 0,因为在时间 0 机器人被假定在原点,但我得到一个错误。如何设置 ode45 的初始条件以获得预期的输出?
我试图通过将初始条件设置为 41x1 零矩阵来制作与 dxdt 长度相同的初始条件向量,但我不理解输出,我不相信我做得正确。
% Given conditions for a differential drive robot:
B = 20; % (cm) distance along axle between centers of two wheels
r = 10; % (cm) diameter of both wheels
w_l = 5*sin(3*t); % (rad/s) angular rate of left wheel
w_r = 5*sin(3*t); % (rad/s) angular rate of right wheel
v_l = r*w_l; % (cm/s) velocity of left wheel
v_r = r*w_r; % (cm/s) velocity of right wheel
v = (v_r+v_l)/B; % (cm/s) velocity of robot
theta = 90; % constant orientation of robot since trajectory is straight
% Solve differential equation for x:
dxdt = v*cos(theta); % diff equaition for x
tspan = [0 20]; % time period to integrate over
x0 = 0; % initial condition since robot begins at origin
[t,x] = ode45(@(t,y) dxdt, tspan, x0);
我想在初始条件为0 的情况下求解0 到20 秒的微分方程dxdt。我希望输出给我一个从0 到20 的时间向量和一个x 的数组。我认为问题在于初始条件。 MATLAB 在实时编辑器中给我一个错误,告诉我“@(t,y)dxdt returns a vector of length 69, but the length of initial conditions vector is 1. The vector returned by @(t,y)dxdt and the initial conditions vector must have the same number of elements.”
【问题讨论】: