For your second line:
[position,velocity,current] = motor.input(5,10);
If you want input() to accept values for the voltage and time, you can define it like so:
function [angle,velocity,current] = input(self, voltage, time)
J = 2e-05;
b = 1e-06;
K = 0.034;
R = 8.4;
L = 0.018;
A = [0 1 0;
0 -b/J K/J;
0 -K/L -R/L];
B = [0;
0;
1/L];
C = eye(3);
D = zeros(3,1);
sys = ss(A,B,C,D);
t = 0:0.01:time;
volt = voltage*ones(1,length(t));
y = lsim(sys,volt,t);
angle = y(:,1);
velocity = y(:,2);
current = y(:,3);
self.voltage = voltage;
self.time = time;
self.angle = angle;
self.velocity = velocity;
self.current = current;
end
However, note that MATLAB classes are value classes by default. I believe, to have properties of your motor object updated by a call to input(), then the function input() needs to return self, and you need to store that output into motor (thereby replacing the old motor object with the new, updated object). Something like this: function [angle,velocity,current,self] = input(self, voltage, time)
...
end
and then
[position,velocity,current,motor] = motor.input(5,10);
Alternatively, you could work with a handle class:
classdef VirtualMotor < handle
...
end
Then, when you pass your object into a function like input(), it's properties will be updated with no requirement to explicitly pass the object back out of the function into the calling workspace.
0 Comments
Sign in to comment.