Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,7 @@ wheelhouse/

# Graphics files
examples/**/*.xml
*.ipe
*.ipe

# Matlab files
*.asv
Binary file not shown.
Binary file modified doc/manual/tuto/cp_robotics/img/CtcConstell_constell.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/manual/tuto/cp_robotics/img/datasso_solved.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/manual/tuto/cp_robotics/img/first_result.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/manual/tuto/cp_robotics/img/loc_robot_landmarks.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/manual/tuto/cp_robotics/img/loc_robot_landmarks_obs.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified doc/manual/tuto/cp_robotics/img/result_rangebearing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
60 changes: 60 additions & 0 deletions doc/manual/tuto/cp_robotics/lesson_a_static_range_and_bearing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,31 @@ where :math:`a,b,\dots,e` are intermediate variables used for the decomposition.
Interval d(4.5,5); // interval for y
ctc_g.contract(a,d,b);

.. code-tab:: matlab

import py.codac4matlab.*

% Symbolic variables:
y = ScalarVar();
[x,m] = deal(VectorVar(2),VectorVar(2));

% Analytic scalar function g(x,m,y) involved in the constraint:
g = AnalyticFunction({x,y,m}, sqrt(((x(1)-m(1))^2)+((x(2)-m(2))^2))-y);

% Contractor associated with the constraint g(x,m,y)\in[u], with [u]=[0,0]
ctc_g = CtcInverse(g, 0);

// Now ctc_g can be called with the .contract(..) method to contract all domains:
// Example:
a = IntervalVector(2); // box for x
b = IntervalVector({{2,3},{5,6.2}}); // box for m
d = Interval(4.5,5); // interval for y
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comments using "%" ?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oui... oops...


res = ctc_g.contract(cart_prod(a,d,b));
a = res.subvector(1,2);
b = res.subvector(3,4);
c = res(5);


Optimality of contractors
-------------------------
Expand Down Expand Up @@ -176,6 +201,17 @@ could be implemented by
// Contractor associated with the constraint g(x,m,y)\in[u] with [u]=[[0,0],[0,0]]
CtcInverse ctc_g(g, {0,0}) // {0,0} is equivalent to Vector::zero(2)

.. code-tab:: matlab

% Symbolic variables:
[x,m,y] = deal(VectorVar(3),VectorVar(2),VectorVar(2));

% Analytic vectorial function g(x,y,m) involved in the constraint:
g = AnalyticFunction({x,y,m}, vec(x(1)+y(1)*cos(x(3)+y(2))-m(1), x(2)+y(1)*sin(x(3)+y(2))-m(2)));

% Contractor associated with the constraint g(x,m,y)\in[u] with [u]=[[0,0],[0,0]]
ctc_g = CtcInverse(g, Vector([0,0])); % [0,0] is equivalent to Vector.zero(2)

However, this involves a multi-occurrence of variables which leads to pessimism. For instance, the sum :math:`(x_3+y_2)` appears twice in functions :math:`\cos` and :math:`\sin`, which is hardly handled by a classical decomposition.


Expand Down Expand Up @@ -266,6 +302,13 @@ A robot depicted by the state :math:`\mathbf{x}=\left(2,1,\pi/6\right)^\intercal

Vector x_truth = {2,1,PI/6}; // actual state vector (pose = position + bearing)

.. code-tab:: matlab

% We recall that you can use the Vector class for
% representing mathematical vectors. For instance:

x_truth = Vector([2,1,PI/6]); % actual state vector (pose = position + bearing)

.. container:: toggle, toggle-hidden

.. tabs::
Expand Down Expand Up @@ -309,6 +352,10 @@ A robot depicted by the state :math:`\mathbf{x}=\left(2,1,\pi/6\right)^\intercal

x[2] &= x_truth[2]; // the heading is assumed to be known

.. code-tab:: matlab

x(3).self_inter(x_truth(3)); % the heading is assumed to be known

.. container:: toggle, toggle-hidden

.. tabs::
Expand Down Expand Up @@ -351,6 +398,11 @@ A robot depicted by the state :math:`\mathbf{x}=\left(2,1,\pi/6\right)^\intercal
DefaultFigure::draw_tank(x_truth, 1, {Color::black(),Color::yellow()}); // robot's size is 1
DefaultFigure::draw_box(m, Color::red());

.. code-tab:: matlab

DefaultFigure().draw_tank(x_truth, 1, StyleProperties({Color().black(),Color().yellow()}));
DefaultFigure().draw_box(m,Color().red());

**A.5.** Display the range-and-bearing measurement with its uncertainties. For this, we will use the function ``.draw_pie(<c>, <[rho]>, <[theta]>)`` to display a portion of a ring :math:`[\rho]\times[\theta]` centered on :math:`(x,y)^\intercal`. Here, we must add in :math:`[\theta]` the robot heading :math:`x_3` and the bounded bearing :math:`[y_2]`.

You should obtain this figure:
Expand All @@ -370,6 +422,10 @@ A robot depicted by the state :math:`\mathbf{x}=\left(2,1,\pi/6\right)^\intercal

DefaultFigure::draw_pie({<x>, <y>}, <[rho]> | 0, <[theta]>, Color::light_gray()); // with: <[rho]> | 0

.. code-tab:: matlab

DefaultFigure().draw_pie(Vector([<x>, <y>]), <[rho]>.union(0), <[theta]>, Color().light_gray()); % with: <[rho]> | 0

.. container:: toggle, toggle-hidden

.. tabs::
Expand Down Expand Up @@ -499,6 +555,10 @@ The following code illustrates how to implement such fixpoint:
etc.
}, <domains related to c1,c2,..>);

.. code-tab:: matlab

% Not supported yet

The ``fixpoint`` function will execute the content of the function ``contractors_list`` until there are no more contractions on the sets listed in ``<domains related to c1,c2,..>``.

.. admonition:: Exercise
Expand Down
117 changes: 117 additions & 0 deletions doc/manual/tuto/cp_robotics/lesson_b_data_association.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,25 @@ where :math:`\bigsqcup`, called *squared union*, returns the smallest box enclos
const std::vector<IntervalVector> _M;
};

.. code-tab:: matlab

classdef MyCtc < handle

properties
M
end

methods
function obj = MyCtc(M_)
obj.M = M_;
end

function a = contract(obj, a)
% Insert contraction formula here
end
end
end

| Note that:

* ``M`` represents the set :math:`\mathbb{M}`, made of 2d ``IntervalVector`` objects;
Expand Down Expand Up @@ -169,6 +188,14 @@ where :math:`\bigsqcup`, called *squared union*, returns the smallest box enclos
:end-before: [B-q2-end]
:dedent: 2

.. group-tab:: Matlab

.. literalinclude:: src/MyCtc.m
:language: matlab
:start-after: [B-q2-beg]
:end-before: [B-q2-end]
:dedent: 0

**B.3.** Test your contractor with:

* a set :math:`\mathbb{M}=\big\{(1.5,2.5)^\intercal,(3,1)^\intercal,(2,2)^\intercal,(2.5,3)^\intercal,(3.5,2)^\intercal,(4,1)^\intercal,(1.5,0.5)^\intercal\big\}`, all boxes inflated by :math:`[-0.05,0.05]`;
Expand Down Expand Up @@ -214,6 +241,24 @@ where :math:`\bigsqcup`, called *squared union*, returns the smallest box enclos
ctc_constell.contract(a2);
ctc_constell.contract(a3);

.. code-tab:: matlab

M = {IntervalVector([...]),IntervalVector([...]),...

for i = 1:numel(M)
M{i}.inflate(0.05);
end

a1 = IntervalVector({...
a2 = IntervalVector({...
a3 = IntervalVector({...

ctc_constell = MyCtc(M);

a1 = ctc_constell.contract(a1)
a2 = ctc_constell.contract(a2)
a3 = ctc_constell.contract(a3)

.. container:: toggle, toggle-hidden

.. tabs::
Expand All @@ -234,6 +279,14 @@ where :math:`\bigsqcup`, called *squared union*, returns the smallest box enclos
:end-before: [B-q3-end]
:dedent: 2

.. group-tab:: Matlab

.. literalinclude:: src/lesson_B.m
:language: matlab
:start-after: [B-q3-beg]
:end-before: [B-q3-end]
:dedent: 0

.. figure:: img/CtcConstell_constell.png
:width: 600px

Expand Down Expand Up @@ -280,6 +333,14 @@ We will localize the robot in the map :math:`\mathbb{M}` created in Question **B
:end-before: [B-q4-end]
:dedent: 2

.. group-tab:: Matlab

.. literalinclude:: src/lesson_B.m
:language: matlab
:start-after: [B-q4-beg]
:end-before: [B-q4-end]
:dedent: 0

**B.5.** Display the robot and the landmarks in a graphical view with:

.. tabs::
Expand All @@ -300,6 +361,14 @@ We will localize the robot in the map :math:`\mathbb{M}` created in Question **B
:end-before: [B-q5-end]
:dedent: 2

.. group-tab:: Matlab

.. literalinclude:: src/lesson_B.m
:language: matlab
:start-after: [B-q5-beg]
:end-before: [B-q5-end]
:dedent: 0

You should obtain this result.

.. figure:: img/loc_robot_landmarks.png
Expand All @@ -325,6 +394,14 @@ We will localize the robot in the map :math:`\mathbb{M}` created in Question **B
:end-before: [B-q6-end]
:dedent: 0

.. group-tab:: Matlab

.. literalinclude:: src/lesson_B.m
:language: matlab
:start-after: [B-q6-beg]
:end-before: [B-q6-end]
:dedent: 0

The returned value is a vector of [range]×[bearing] interval values.

Compute and display the measurements in the view with ``.draw_pie()``, as we did in the previous lesson.
Expand All @@ -348,6 +425,14 @@ We will localize the robot in the map :math:`\mathbb{M}` created in Question **B
:end-before: [B-q7-end]
:dedent: 2

.. group-tab:: Matlab

.. literalinclude:: src/lesson_B.m
:language: matlab
:start-after: [B-q7-beg]
:end-before: [B-q7-end]
:dedent: 0

You should obtain a figure similar to this one:

.. figure:: img/loc_robot_landmarks_obs.png
Expand Down Expand Up @@ -391,6 +476,14 @@ We will first reuse the fixpoint method of the previous Lesson, and apply it on
:start-after: [B-q7b-beg]
:end-before: [B-q7b-end]
:dedent: 2

.. group-tab:: Matlab

.. literalinclude:: src/lesson_B.m
:language: matlab
:start-after: [B-q7b-beg]
:end-before: [B-q7b-end]
:dedent: 0

**B.8.** Display the resulted contracted box :math:`[\mathbf{x}]` with:

Expand All @@ -414,6 +507,14 @@ We will first reuse the fixpoint method of the previous Lesson, and apply it on
:end-before: [B-q8-end]
:dedent: 2

.. group-tab:: Matlab

.. literalinclude:: src/lesson_B.m
:language: matlab
:start-after: [B-q8-beg]
:end-before: [B-q8-end]
:dedent: 0

You should obtain this result in black (considering uncertainties proposed in Question **B.6**):

.. figure:: img/loc_robot_landmarks_obs_box.png
Expand Down Expand Up @@ -453,6 +554,14 @@ We now assume that the identities of the landmarks are not known. This means tha
:end-before: [B-q9-end]
:dedent: 2

.. group-tab:: Matlab

.. literalinclude:: src/lesson_B.m
:language: matlab
:start-after: [B-q9-beg]
:end-before: [B-q9-end]
:dedent: 0


**B.11.** *Same result* means that the data association worked: each measurement has been automatically associated to the correct landmark without ambiguity.

Expand Down Expand Up @@ -480,6 +589,14 @@ We now assume that the identities of the landmarks are not known. This means tha
:end-before: [B-q10-end]
:dedent: 2

.. group-tab:: Matlab

.. literalinclude:: src/lesson_B.m
:language: matlab
:start-after: [B-q10-beg]
:end-before: [B-q10-end]
:dedent: 4

Expected result:

.. figure:: img/loc_robot_landmarks_obs_box_id.png
Expand Down
Loading