Skip to content

Commit 76d4a82

Browse files
committed
2 parents 043e721 + 8bf09b9 commit 76d4a82

28 files changed

+4119
-7
lines changed

README.md

+9-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Robotics, Vision & Control: 3rd edition in MATLAB (2023)
22

3+
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/petercorke/RVC3-MATLAB/graphs/commit-activity)
4+
[![Build Status](https://github.com/petercorke/RVC3-MATLAB/actions/workflows/run_toolbox_tests.yml/badge.svg)](https://github.com/petercorke/RVC3-MATLAB/actions?query=workflow%3Abuild)
35
[![codecov](https://codecov.io/gh/petercorke/RVC3-MATLAB/branch/main/graph/badge.svg?token=68OAE87GM2)](https://codecov.io/gh/petercorke/RVC3-MATLAB)
46
[![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](https://choosealicense.com/licenses/mit/)
5-
[![Maintenance](https://img.shields.io/badge/Maintained%3F-yes-green.svg)](https://GitHub.com/petercorke/RVC3-MATLAB/graphs/commit-activity)
67
[![GitHub stars](https://img.shields.io/github/stars/petercorke/RVC3-MATLAB.svg?style=social&label=Star&maxAge=2592000)](https://GitHub.com/petercorke/RVC3-MATLAB/stargazers/)
78

89
<table style="border:0px">
@@ -37,7 +38,7 @@ This repo contains MATLAB code resources that support the book:
3738

3839
There are two ways to do this.
3940

40-
## Open in MATLAB Online™
41+
## 1. Open in MATLAB Online™
4142

4243
This is the zero-install option, and requires that you have a MATLAB Online licence.
4344
MATLAB Online can work on a tablet, but not a phone.
@@ -54,10 +55,10 @@ and then do one of the following:
5455
This will clone the repository into your MATLAB Drive and open the chapter LiveScript
5556
in a browser tab.
5657

57-
## Open in desktop MATLAB session
58+
## 2. Open in desktop MATLAB session
5859

59-
You need to have MATLAB installed and the required Toolboxes. Install the extra
60-
resources
60+
You need to have MATLAB installed as well as the required Toolboxes. Install the extra
61+
book-specific resources
6162
```shell
6263
git clone [email protected]:petercorke/RVC3-MATLAB.git
6364
```
@@ -97,14 +98,14 @@ For Parts IV and Chap. 15
9798
- Deep Learning Toolbox™
9899
- Statistics and Machine Learning Toolbox™
99100

100-
101101
For Chap. 16 only:
102102
- ROS Toolbox
103103
- Model Predictive Control Toolbox™
104104
- Automated Driving Toolbox™
105105

106106
Those shown in bold are sufficient to run a large subset
107107
of the code examples.
108+
108109
## Apps
109110

110111
This package provides additional interactive tools including:
@@ -122,7 +123,8 @@ in Simulink by:
122123
# Additional book resources
123124

124125
This GitHub repo provides additional resources for readers including:
125-
- The code to produce every MATLAB figure in the book, see the [`book/figures`](book/figures) folder
126+
- The code to produce every MATLAB figure in the book, see the [`book/figures/code`](book/figures/code) folder
127+
- Many of the line drawings that appears as figures in the book, see the [`book/figures/line-drawings`](book/figures/line-drawings) folder
126128
- All example scripts, see the [`toolbox/examples`](toolbox/examples) folder.
127129
- To run the visual odometry example in Sect. 14.8.3 you need to download two image sequence, each over 100MB:
128130
```

book/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# book
2+
3+
This folder contains online resources related to the book
4+
5+
* [`code`](./code) MATLAB Live Scripts (.mlx format) that contain all the code snippets for each chapter
6+
* [`code_m`](./code_m) MATLAB Live Scripts (.m plain text format) that contain all the code snippets for each chapter
7+
* [`figures`](./figures) most figures from the book: line drawings, and source codee for MATLAB-generated figures

book/code/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
MATLAB Live Scripts in `.mlx` format for each chapter of the book. These contain all the code snippets and examples for the chapter.
2+
3+
These are the scripts that are run on MATLAB Online using the QR-code/short-URL at the start of each chapter.

book/code_m/README.md

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
MATLAB Live Scripts in `.m` "plain text" format for each chapter of the book. These contain all the code snippets and examples for the chapter.

book/code_m/appendices.m

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
%[text] %[text:anchor:F4CCA683] # Robotics, Vision & Control 3e: for MATLAB
2+
%[text] %[text:anchor:874DADDE] # Appendices
3+
%[text:tableOfContents]{"heading":"Table of Contents"}
4+
%[text] %[text:anchor:H_FD45E4DF] Copyright 2022\-2023 Peter Corke, Witold Jachimczyk, Remo Pillat
5+
%[text] %[text:anchor:F954A5D5] ## Appendix C: Geometry
6+
%[text] %[text:anchor:BAEBF2AC] ### C.1 Euclidean Geometry
7+
%[text] %[text:anchor:E4239FA6] #### C.1\.2 Lines
8+
%[text] %[text:anchor:E7791A79] #### C.1\.2\.2 Lines in 3D and Plücker Coordinates
9+
P = [2 3 4]; Q = [3 5 7];
10+
L = Plucker(P,Q)
11+
L.v
12+
L.w
13+
L.skew
14+
axis([-5 5 -5 5 -5 5]);
15+
L.plot("b");
16+
L.point([0 1 2])
17+
[x,d] = L.closest([1 2 3]) %#ok<*ASGLU>
18+
L.intersect_plane([0 0 1 0])
19+
%%
20+
%[text] %[text:anchor:B107E972] #### C.1\.4 Ellipses and Ellipsoids
21+
E = [1 1;1 2];
22+
clf; plotellipse(E); hold on
23+
[x,e] = eig(E)
24+
r = 1./sqrt(diag(e))
25+
p = x(:,1)*r(1); quiver(0,0,p(1),p(2),0,"r");
26+
p = x(:,2)*r(2); quiver(0,0,p(1),p(2),0,"r");
27+
atan2d(x(2,1),x(1,1))
28+
%%
29+
%[text] %[text:anchor:81891655] #### C.1\.4\.1 Drawing an Ellipse
30+
E = [1 1; 1 2];
31+
th = linspace(0,2*pi,50);
32+
y = [cos(th);sin(th)];
33+
x = inv(sqrtm(E))*y;
34+
clf; plot(x(1,:),x(2,:));
35+
clf; plotellipse(E)
36+
%%
37+
%[text] %[text:anchor:A199F180] #### C.1\.4\.2 Fitting an Ellipse to Data
38+
rng(0); % reset random number generator
39+
x = []; % empty point set
40+
while size(x,2) < 500
41+
p = (rand(2,1)-0.5)*4;
42+
if norm(p'*E*p) <= 1
43+
x = [x p];
44+
end
45+
end
46+
plot(x(1,:),x(2,:),".")
47+
% compute the moments
48+
m00 = mpq_point(x,0,0);
49+
m10 = mpq_point(x,1,0);
50+
m01 = mpq_point(x,0,1);
51+
xc = m10/m00; yc = m01/m00;
52+
% compute second moments relative to centroid
53+
x0 = x - [xc; yc];
54+
m20 = mpq_point(x0,2,0);
55+
m02 = mpq_point(x0,0,2);
56+
m11 = mpq_point(x0,1,1);
57+
% compute the moments and ellipse matrix
58+
J = [m20 m11;m11 m02];
59+
E_est = m00*inv(J)/4;
60+
E_est
61+
plotellipse(E_est,"r")
62+
%%
63+
%[text] %[text:anchor:22C91717] ### C.2 Homogeneous Coordinates
64+
%[text] %[text:anchor:A2EF233A] #### C.2\.1 Two Dimensions
65+
%[text] %[text:anchor:25F2AFB3] #### C.2\.1\.1 Points and Lines
66+
l1 = [1 -1 0];
67+
l2 = [1 -1 -1];
68+
plothomline(l1,"b")
69+
plothomline(l2,"r")
70+
cross(l1, l2)
71+
%[text] %[text:anchor:82267EC7] ##
72+
%[text] %[text:anchor:29028678] ## Appendix E: Linearization, Jacobians, and Hessians
73+
%[text] %[text:anchor:05136303] ### E.4 Deriving Jacobians
74+
zrange = @(xi,xv,w) ...
75+
[sqrt((xi(1)-xv(1))^2 + (xi(2)-xv(2))^2) + w(1);
76+
atan((xi(2)-xv(2))/(xi(1)-xv(1)))-xv(3) + w(2)];
77+
xv = [1 2 pi/3]; xi = [10 8]; w= [0,0];
78+
h0 = zrange(xi,xv,w)
79+
d = 0.001;
80+
J = [zrange(xi,xv+[1 0 0]*d,w)-h0 ...
81+
zrange(xi,xv+[0 1 0]*d,w)-h0 ...
82+
zrange(xi,xv+[0 0 1]*d,w)-h0]/d
83+
syms xi yi xv yv thetav wr wb
84+
z = zrange([xi yi],[xv yv thetav],[wr wb])
85+
J = jacobian(z,[xv yv thetav])
86+
whos J
87+
Jf = matlabFunction(J);
88+
xv = [1 2 pi/3]; xi = [10 8]; w = [0 0];
89+
Jf(xi(1),xv(1),xi(2),xv(2))
90+
%%
91+
%[text] %[text:anchor:99DE1C25] ##
92+
%%
93+
%[text] %[text:anchor:980876A6] ## Appendix G: Gaussian Random Variables
94+
x = linspace(-6,6,500);
95+
plot(x,gaussfunc(0,1,x),"r")
96+
hold on
97+
plot(x,gaussfunc(0,2^2,x),"b--")
98+
sigma = 1; mu = 0;
99+
g = sigma*randn(100,1) + mu;
100+
[x,y] = meshgrid(-5:0.1:5,-5:0.1:5);
101+
P = diag([1 2]).^2;
102+
surfc(x,y,gaussfunc([0 0],P,x,y))
103+
s = chi2inv(0.5,2)
104+
%%
105+
%[text] %[text:anchor:DD77BE42] ## Appendix H: Kalman Filter
106+
%[text] %[text:anchor:72ADDA8C] ### H.2 Nonlinear Systems \-\- Extended Kalman Filter
107+
x = 2*randn(1000000,1) + 5;
108+
y = (x+2).^2/4;
109+
clf; histogram(y, Normalization="pdf");
110+
%%
111+
%[text] %[text:anchor:1A4CC05A] ## Appendix I: Graphs
112+
g = UGraph()
113+
rng(10)
114+
for i = 1:5
115+
g.add_node(rand(2,1));
116+
end
117+
g.add_edge(1,2);
118+
g.add_edge(1,3);
119+
g.add_edge(1,4);
120+
g.add_edge(2,3);
121+
g.add_edge(2,4);
122+
g.add_edge(4,5);
123+
g
124+
clf; g.plot(labels=true);
125+
g.neighbors(2)
126+
e = g.edges(2)
127+
g.cost(e)
128+
g.nodes(5)' % transpose for display
129+
[n,c] = g.neighbors(2)
130+
g.about(1)
131+
g.closest([0.5 0.5])
132+
g.path_Astar(3, 5)
133+
%%
134+
%[text] %[text:anchor:8633A41B] ## Appendix J: Peak finding
135+
%[text] %[text:anchor:794CD871] ### J.1 1D Signal
136+
load peakfit1
137+
clf; plot(y,"-o")
138+
[ypk,k] = max(y)
139+
[ypk,k] = findpeaks(y,SortStr="descend");
140+
ypk' % transpose for display
141+
k' % transpose for display
142+
ypk(2)/ypk(1)
143+
range=k(1)-1:k(1)+1
144+
p = polyfit(range,y(range),2) % fit second-order polynomial
145+
pd = polyder(p) % derivative of fitted polynomial
146+
roots(pd) % zero value of the derivative
147+
ypk = findpeaks(y,MinPeakDistance=5)' % transpose for display
148+
%%
149+
%[text] %[text:anchor:A82CA7F7] ### J.2 2D Signal
150+
z
151+
[zmax,i] = max(z(:))
152+
[y,x] = ind2sub(size(z),i)
153+
LMaxFinder = vision.LocalMaximaFinder(MaximumNumLocalMaxima=3, ...
154+
NeighborhoodSize=[3 3],Threshold=0);
155+
LMaxFinder(z)
156+
%[text]
157+
%[text] Suppress syntax warnings in this file
158+
%#ok<*NASGU>
159+
%#ok<*AGROW>
160+
%#ok<*MINV>
161+
162+
%[appendix]
163+
%---
164+
%[metadata:view]
165+
% data: {"layout":"inline","rightPanelPercent":40}
166+
%---

0 commit comments

Comments
 (0)