Commit afeba5a2 authored by erwan's avatar erwan
Browse files

Doc: add a missing file

parent 59651322
Pipeline #45497 passed with stages
in 5 minutes and 38 seconds
% Automatically generated by utils/lus2tex
% from file /home/jahier/github/lustre-examples/verimag-v6/examples//speed.lus scriptsize
% the jeudi 11 juin 2020, 08:39:55 (UTC+0200)
\begin{minipage}{\textwidth}
\begin{scriptsize}
\begin{alltt}
\coment{-- Time-stamp: <modified the 11/06/2020 (at 08:39) by Erwan Jahier> }
\coment{-- Computes the speed (of some vehicle \kwdd{with} wheels) out of 2 sampled inputs:}
\coment{-- + Rot, \kwdd{true} iff the wheel has performed a comp\kwd{let}e rotation}
\coment{-- + Tic, \kwdd{true} iff some external clock has emitted a signal indicating that }
\coment{-- some \kwd{const}ant amount of time elapsed (e.g., 100 ms) }
\coment{--}
\coment{-- This example was inspired from a \kwdd{real} program in a train regulating system}
\kwd{const} period = 0.1; \coment{-- in seconds}
\kwd{const} wheel_girth = 1.4; \coment{-- in meter}
\kwd{const} size = 20; \coment{-- size of the sliding window used to compute the speed}
\kwd{node} compute_speed(Rot, Tic: \kwdd{bool}) \kwd{returns} (Speed:\kwdd{real});
var d,t,dx,tx:\kwdd{real};
\kwd{let}
dx = \kwdd{if} Rot \kwdd{then} wheel_girth \kwdd{else} 0.0;
tx = \kwdd{if} Tic \kwdd{then} period \kwdd{else} 0.0;
d = sum<<size,0.0>>(dx);
t = sum<<size,period>>(tx);
\coment{-- the speed is actually the average speed during the last "size*period" seconds }
Speed = (d/t);
\coment{-- nb : yes there can be some division by zero! For instance \kwdd{if} the vehicle}
\coment{-- overtakes the speed of size*wheel_girth/period}
\coment{-- (i.e., \kwdd{with} size=20, period=0.1, wheel_girth=1.4, \kwdd{if} the speed is > 1008km/h)}
\coment{-- This means that for high-speed vehicle, one \kwddd{needs} to increase "size".}
\kwd{tel}
\coment{-- The idea is to call the \kwd{node} that do the computation only \kwd{when} needed, i.e.,}
\coment{-- \kwd{when} Tic \kwdd{or} Rot is \kwdd{true}. }
\kwd{node} speed(Rot, Tic: \kwdd{bool}) \kwd{returns} (Speed:\kwdd{real});
var
TicOrRot : \kwdd{bool};
NewSpeed : \kwdd{real} \kwd{when} TicOrRot;
\kwd{let}
TicOrRot = Tic \kwdd{or} Rot;
NewSpeed = compute_speed(Rot \kwd{when} TicOrRot, Tic \kwd{when} TicOrRot);
Speed = current(NewSpeed);
\kwd{tel}
\coment{-- computes the sum of the last d values taken by s}
\kwd{node} sum<<\kwd{const} d: \kwdd{int}; const init:\kwdd{real}>>(s: \kwdd{real}) \kwd{returns} (res:\kwdd{real});
var
a,pre_a: \kwdd{real}^d; \coment{-- circular array}
i: \kwdd{int};
\kwd{let}
i = 0 fby i + 1;
pre_a = (init^d) fby a;
a = assign<<d>>(s, i mod d, pre_a);
res =red<<+; d>>(0.0, a);
\kwd{tel}
\coment{-- assign the jth element of an array to a value. v.(j) <- i}
\kwd{type} update_acc = \{ i: \kwdd{int}; j: \kwdd{int}; v: \kwdd{real} \};
\kwd{function} update_cell_do<<\kwd{const} d: \kwdd{int}>>(acc: update_acc; cell: \kwdd{real})
\kwd{returns} (nacc: update_acc; ncell: \kwdd{real});
\kwd{let}
ncell = \kwdd{if} acc.i = acc.j \kwdd{then} acc.v \kwdd{else} cell;
nacc = update_acc \{ i = acc.i+1; j = acc.j ; v = acc.v \};
\kwd{tel}
\kwd{function} assign<<\kwd{const} d: \kwdd{int}>>(v: \kwdd{real}; jv: \kwdd{int}; t: \kwdd{real}^d) \kwd{returns} (nt: \kwdd{real}^d)
var
dummy: update_acc;
\kwd{let}
dummy, nt=fillred<<update_cell_do<<d>>; d>>( update_acc \{ i=0 ; j=jv ; v=v \}, t);
\kwd{tel}
\end{alltt}
\end{scriptsize}
\end{minipage}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment