-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvelocity_function.m
More file actions
50 lines (41 loc) · 1.48 KB
/
velocity_function.m
File metadata and controls
50 lines (41 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
function averagespeed=velocity_function(frequency)
%quad dynamics, one body, one leg
%design variables
quad.leg=5.64/1000; %mm - leg length, straight line
quad.height=5.5/1000; %mm - body height
world.g=9.81; %mm s^-2 - gravity acceleration
quad.mass=1.5/1000; %g - body weight
magnet.torque=10/1000/1000; %mN-mm - magnetic torque applied to leg
world.time=[0:0.001:1]'; %s - time
magnet.frequency=frequency; %Hz - frequency of actuation
force.body=zeros(length(world.time),3);
%limits
theta.ground.one=asin((quad.height/2)/quad.leg);
theta.ground.two=pi-theta.ground.one*2;
%Theta creation
theta.leg=zeros(length(world.time),1);
theta.time=magnet.frequency*2*pi*world.time;
for i=1:length(world.time)
if floor(theta.time(i)/(2*pi)) >= 1
theta.leg(i,1)=((theta.time(i)-floor(theta.time(i)/(2*pi))*2*pi));
else
theta.leg(i,1)=theta.time(i);
end
end
for j=1:length(world.time)
force.body(j,:)=([-sin(theta.leg(j,1)) cos(theta.leg(j,1));...
0 0;...
-cos(theta.leg(j,1)) sin(theta.leg(j,1))]*...
[0; magnet.torque/quad.leg])';
end
figure(1)
plot(world.time,force.body(:,1),world.time,force.body(:,2),world.time,force.body(:,3))
%options=odeset('RelTol',1e-6,'AbsTol',1e-10);
int=zeros(2,1);
quad_vars={quad world magnet theta};
[t,xy]=ode113(@(t,xy) quad_EOM(t,xy,quad_vars),...
world.time,int);
figure(2)
plot(t,xy(:,1))%,t,xy(:,3))
averagespeed=xy(end,1);
end