-
Notifications
You must be signed in to change notification settings - Fork 1
/
drawBike.m
141 lines (91 loc) · 2.72 KB
/
drawBike.m
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
function [COG_hand,SH_hand,CPfw_hand,CPrw_hand]=drawBike(x,y,z,yaw,roll,steer,p)
%function taken directly from Kate's animation code, based on Diego's
%animation code--meant to accurately draw the bicycle in the animation
%simulation, based on bicycle and motor parameters
%% Bicycle Constants
roll=-roll; %why?? into the board vs. out of the board
CONST=BikeAndMotorConstants;
w = p.l;
c = p.c;
% w=CONST.w; %Wheelbase (m)
% c=CONST.c; %Trail (m)
% tilt=CONST.tilt; %tile (rad) ? What is tilt?
%Rear Wheel R
r_R=0.1905; %radius (m)
%Rear Body and Frame Assembly B
% x_B=CONST.x_B;
% z_B=CONST.z_B; %Position of center of mass (m)
%Front Handlebar and Fork Assembly H
% x_H=CONST.x_H;
% z_H=CONST.z_H; %Position of center of mass (m)
%Front Wheel F
r_F=r_R; %radius (m)
%Whole Bike
% center of mass
x_T = CONST.x_T; %Total center of mass
z_T = CONST.z_T; %(wrt contact point P)
% Bike Constants
Handh=0.5;
HandW=0.3;
%% Dynamic Variables
% x=2;
% y=0;
% z=0;
% yaw=0;
%
% roll=pi/8;
% steer=-pi/4;
% Coordinate Transformation Matrices
A_OP=[cos(yaw),-sin(yaw),0,x;...
sin(yaw),cos(yaw),0,y;...
0,0,1,z;...
0,0,0,1];
A_PG=[1,0,0,x_T;...
0,cos(roll),-sin(roll),-abs(z_T)*sin(roll);...
0,sin(roll),cos(roll),abs(z_T)*cos(roll);...
0,0,0,1];
A_GWF=[cos(steer),-sin(steer),0,(-x_T+w);...
sin(steer),cos(steer),0,0;...
0,0,1,(-abs(z_T)+r_F);...
0,0,0,1]...
*...
[1,0,0,0;...
0,cos(pi/2),-sin(pi/2),0;...
0,sin(pi/2),cos(pi/2),0;...
0,0,0,1];
A_WFS=[1,0,0,0;...
0,cos(pi/2),-sin(pi/2),Handh;...
0,sin(pi/2),cos(pi/2),0;...
0,0,0,1];
A_GWR=[1,0,0,-x_T;...
0,cos((pi/2)),-sin((pi/2)),0;...
0,sin((pi/2)),cos((pi/2)),-abs(z_T)+r_R;...
0,0,0,1];
%% Plot Bicycle Parts
%Draw Center of Gravity
COG_G=[0;0;0;1];
COG_P=A_PG*COG_G;
COG_O=A_OP*COG_P;
COG_hand=plot3(COG_O(1),COG_O(2),COG_O(3),'*b');
%Draw Steering Wheel
SH_S=[[0;(HandW/2);0;1],[0;(-HandW/2);0;1]];
SH_WF=A_WFS*SH_S;
SH_G=A_GWF*SH_WF;
SH_P=A_PG*SH_G;
SH_O=A_OP*SH_P;
SH_hand=plot3(SH_O(1,:),SH_O(2,:),SH_O(3,:),'k');
%Draw Front Wheel [WF coordinate]
CPfw=CircleAboutZ(r_F);
CPfw=[CPfw;ones(size(CPfw(1,:)))];
CPfw_G=A_GWF*CPfw;
CPfw_P=A_PG*CPfw_G;
CPfw_O=A_OP*CPfw_P;
CPfw_hand=plot3(CPfw_O(1,:),CPfw_O(2,:),CPfw_O(3,:),'k');
%Draw Back Wheel [WR coordinate]
CPrw=CircleAboutZ(r_R);
CPrw=[CPrw;ones(size(CPrw(1,:)))];
CPrw_G=A_GWR*CPrw;
CPrw_P=A_PG*CPrw_G;
CPrw_O=A_OP*CPrw_P;
CPrw_hand=plot3(CPrw_O(1,:),CPrw_O(2,:),CPrw_O(3,:),'k');
end