CS B659: Principles of Intelligent Robot Motion

Download Report

Transcript CS B659: Principles of Intelligent Robot Motion

I400/I590/B659:
Intelligent Robotics
Preliminaries: Vectors
Lab 1
1. Install Klamp’t python API
2. In Klampt/Python/demos folder: run python gltemplate.py
../../data/athlete_fractal_1.xml
3. Navigate with the mouse (hold Shift and Ctrl to pan and
zoom) to get a good screenshot of the robot
4. Press ‘s’ to start simulating
5. Take a screenshot, submit it in .jpg or .png format
• Due next Wednesday
• Ask your peers / myself for help installing
• Document installation problems, email to me
([email protected])
Agenda
• Vector algebra: Representing and manipulating points and
directions in 2D, 3D, and higher dimensions
Vectors
• Represent physical quantities that exist in some “space”
• Both direction and magnitude
• Represent ordered collections of related numbers
• In this class:
• 2D and 3D: Positions, velocities, accelerations, forces, pixel
positions…
• Higher D: RGBA colors, configurations, robot-environment system
states, torques…
Example #1
• Bob is standing at point A. He moves north one meter. He then
moves east 2 meters. How far is he now from point A?
A
Example #1
• Bob is standing at point A. He moves north one meter. He then
moves east 2 meters. How far is he now from point A?
A
Example #1
• Bob is standing at point A. He moves north one meter. He then
moves east 2 meters. How far is he now from point A?
B
A
Example #1
• Bob is standing at point A. He moves north one meter. He then
moves east 2 meters. How far is he now from point A?
(2,1)
B
(0,0)
A
Example #1
• Bob is standing at point A. He moves north one meter. He then
moves east 2 meters. How far is he now from point A?
(2,1)
B
A
The displacement vector from A to B is 𝐴𝐵 =
vertically for reasons to be discussed later)
2
(it is oriented
1
Notation
• A displacement vector starting at point A and ending at pint B
is denoted 𝐴𝐵
• Capitals
• Not used much in this class
• A plain vector will be denoted 𝑥
• Point of origin is either unspecified, assumed, or does not need to
be made explicit to be meaningful (e.g., velocity)
• Lowercase
• Eventually we’ll drop the arrow
Example #1
• Bob is standing at point A. He moves north one meter. He then
moves east 2 meters. How far is he now from point A?
?
(2,1)
B
A
2
is 22 + 12 = 5.
1
This is also known as the norm of the vector and is denoted 𝐴𝐵 .
The length of the vector 𝐴𝐵 =
Norms
𝑎
• Definition: If 𝑥 =
is a vector, then 𝑥 ≡ 𝑎2 + 𝑏 2
𝑏
• (Pythagorean theorem)
• [Subtle point: distance is not the same as distance traveled!
Bob traveled 3m, but ended up about 2.23m away from the
start]
Comment
• What about if Bob repeats the same procedure, arriving at
point C?
C
(2,1)
B
A
Comment
• What about if Bob repeats the same procedure, arriving at
point C?
(4,2)
C
(2,1)
B
A
Comment
• What about if Bob repeats the same procedure, arriving at
point C?
(4,2)
C
(2,1)
B
(0,0)
A
The displacement vector from A to B is?
The displacement vector from B to C is?
The displacement vector from A to C is?
2
1
Example #2: Multiplication
• Dan is standing at point A. He moves in the same direction
that Bob originally did, but goes 50% farther. Where does he
stand?
(2,1)
B
A
D
Example #2: Multiplication
• Dan is standing at point A. He moves in the same direction
that Bob originally did, but goes 50% farther. Where does he
stand?
(2,1)
D
B
A
Displacement vector from A to D is
𝐴𝐷 = 1 + 0.5 ∗ 𝐴𝐵 = 1.5 ∗
3
2
=
1.5
1
Scalar multiplication
• To differentiate it from a vector, a “regular number” is known
as a scalar
• Scalar-vector multiplication scales both elements of the vector
by the same amount. If a, b, and c are scalars, then:
𝑎
𝑐𝑎
=
𝑏
𝑐𝑏
• 𝑐
• It commutes:
• 𝑐
𝑎
𝑎
=
𝑐
𝑏
𝑏
• Scalar division is the same as multiplying by 1/c
•
𝑎
𝑎
/𝑐 =
𝑏
𝑏
1
𝑐
=
𝑎/𝑐
𝑏/𝑐
• [As usual, don’t divide by zero]
Scalar multiplication
• Scalar multiplication “passes through” the norm operation:
• 𝑐 𝑥 = |𝑐| 𝑥
• (Why?)
Points vs. Displacements
• A point X in space can be represented for the purposes of
calculations (out of the realm of pure thought) as a
displacement vector from some special reference point O,
called the origin
• The representation of a point P changes depending on the choice
of O
• When comparing or manipulating two points, their
representations as vectors must use the same origin!
• A displacement vector from point X to Y is the same regardless
of the choice of origin
• [Note: what about the orientation of the reference axes? More
later]
Example #3: Vector addition
• Suppose Bob is at B=(2,1). Bob then moves South 2 meters
and east 3 more meters, arriving at E. What are E’s
coordinates?
B
(2,1)
(3,-2)
A
E
Example #3: Vector addition
• Suppose Bob is at B=(2,1). Bob then moves South 2 meters
and east 3 more meters, arriving at E. What are E’s
coordinates?
𝐴𝐵 + 𝐵𝐸 = 𝐴𝐸
B
(2,1)
(3,-2)
A
𝐴𝐸 =
2
3
5
+
=
1
−2
−1
E
Vector addition 𝑧 = 𝑥 + 𝑦: produces a new vector in which 𝑧 ‘s first
element is equal to the sum of the first elements of 𝑥 and 𝑦, and its
second element is equal to the sum of the second elements.
Example #4: Vector
subtraction
• Dan is at back at D=(3,1.5). Along which vector would he have
to move in order to reach E=(5,-1)?
D
𝐴𝐷 + 𝐷𝐸 = 𝐴𝐸
(3,1.5)
𝐷𝐸 = 𝐴𝐸 − 𝐴𝐷
A
(5,-1)
E
𝐷𝐸 =
3
2
5
−
=
1.5
−2.5
−1
Vector subtraction 𝑧 = 𝑥 − 𝑦: produces a new vector in which 𝑧 ‘s first
element is equal to the first element of 𝑥 minus the first element of 𝑦,
and its second element is equal to the second element of 𝑥 minus the
first element of 𝑦.
Vector subtraction: another
view
• With normal numbers, 𝑥 − 𝑦 = 𝑥 + (−1 ∗ 𝑦)
• With vectors, 𝑥 − 𝑦 = 𝑥 + (−1 ∗ 𝑦)
• (Try it)
Distances
D
• How far is D from E?
(3,1.5)
A
• Step 1: calculate 𝐷𝐸 = 𝐴𝐸 − 𝐴𝐷
?
(5,-1)
E
• Step 2: calculate the norm 𝐷𝐸
• In other words, the distance between D and E is 𝐴𝐸 − 𝐴𝐷
Interpolation
• To go from D to E gradually, you can use linear interpolation
(3,1.5)
D
A
(5,-1)
E
𝑝 𝑢 = 𝐴𝐷 + 𝑢 ∗ (𝐴𝐸 − 𝐴𝐷) for u[0,1] a scalar parameter
Or… 𝑝 𝑢 = 𝐴𝐷 + 𝑢 ∗ 𝐷𝐸
Or… 𝑝 𝑢 = 1 − 𝑢 ∗ 𝐴𝐷 + 𝑢 ∗ 𝐴𝐸
Higher dimensions
• Everything is exactly the same, but the vectors contain more
elements
𝑎
• 3D: 𝑥 = 𝑏
𝑐
𝑎
𝑏
• 4D: 𝑥 =
𝑐
𝑑
• Etc…
• Scalar-vector multiplication, vector addition and subtraction
remain essentially the same
Norms in higher dimensions
𝑎
• 3D: if 𝑥 = 𝑏 , then 𝑥 = 𝑎2 + 𝑏 2 + 𝑐 2 (why?)
𝑐
𝑎
𝑏
• 4D: if 𝑥 =
, then 𝑥 = 𝑎2 + 𝑏 2 + 𝑐 2 + 𝑑 2
𝑐
𝑑
• Etc…
Standard vector spaces
•
•
•
•
Cartesian space
1D space: ℝ
2D space: ℝ2
Etc… ℝn
• It can be shown that any space of objects that transform like
vectors do, with scalar-vector multiplication and vector-vector
addition, is isomorphic to ℝn for some n*
*as long as it has finite dimension
Cheat sheet
• Notation for n-dimensional vectors:
• 𝑥 = 𝑥1 , … , 𝑥𝑛 , 𝑦 = 𝑦1 , … , 𝑦𝑛 , etc
• Space of n-dimensional vectors: ℝn (Cartesian space)
•
•
•
•
Norm: 𝑥 = 𝑥12 + ⋯ + 𝑥𝑛2
Scalar-vector multiplication: c𝑥 = 𝑐𝑥1 , … , 𝑐𝑥𝑛
Norms and scalar multiplications: 𝑐 𝑥 = |𝑐| 𝑥
Vector-vector addition:
• 𝑥 + 𝑦 = 𝑥1 + 𝑦1 , … , 𝑥𝑛 + 𝑦𝑛
• Vector-vector subtraction:
• 𝑥 − 𝑦 = 𝑥1 − 𝑦1 , … , 𝑥𝑛 − 𝑦𝑛
• No such thing as vector-vector multiplication, vector-scalar addition.
Implementation in Python
• Lists:
•
•
•
•
•
E.g., [2,1], or [0.5,-0.8]
Operators +, -, *, / do not work in the same way
Use klampt.vectorops.{add,sub,mul,div}
Norm: klampt.vectorops.norm
Distance: klampt.vectorops.distance
• Numpy arrays:
•
•
•
•
E.g., numpy.array([2,1]), or numpy.array([0.5,-0.8]),
Operators +, -, *, / work as desired
Norm: numpy.linalg.norm
Distance: numpy.linalg.norm(x-y)
Next time
• Matrix algebra, linear transformations (Principles A.E)
• No class on Monday