Kinematic car model

The configuration vector: (((x,y,ϕ,θ))^T)
The controls: ((((Subscript[u, 1]),(Subscript[u, 2])))^T)

params={bl->1,al->0.5};    (* kinematic car parameters: body length, axle length *)

eqns={                                                                        (* motion equations *)
x'[t]==Cos[θ[t]]Cos[ϕ[t]]u1,
y'[t]==Cos[θ[t]]Sin[ϕ[t]]u1,
ϕ'[t]==Sin[θ[t]]/bl u1,
θ'[t]==u2};

rearaxle[t_]:={x[t],y[t]}                                                             (* rear axle mid point position *)
frontaxle[t_]:={x[t]+bl Cos[ϕ[t]],y[t]+bl Sin[ϕ[t]]}   (* front axle mid point position *)
rwl[t_]:={x[t]-al Sin[ϕ[t]],y[t]+al Cos[ϕ[t]]}                            (* rear wheels mid points *)
rwr[t_]:={x[t]+al Sin[ϕ[t]],y[t]-al Cos[ϕ[t]]}
fwl[t_]:=frontaxle[t]+{-al Sin[ϕ[t]+θ[t]],al Cos[ϕ[t]+θ[t]]}  (* front wheels mid points *)
fwr[t_]:=frontaxle[t]-{-al Sin[ϕ[t]+θ[t]],al Cos[ϕ[t]+θ[t]]}

Solution

pics={x[0]==0,y[0]==0,ϕ[0]==0,θ[0]==0};   (* initial conditions *)
contr={u1->1,u2->1} ;                                                 (* controls *)
tmax=20;
psol=NDSolve[{eqns,pics}/.params/.contr,{x,y,ϕ,θ},{t,0,tmax}]   (* solution *)

(* some plots *)
Plot[Evaluate[{x[t],y[t]}/.psol[[1]]],{t,0,tmax},PlotLegends->{"x","y"}]
ParametricPlot[Evaluate[{x[t],y[t]}/.psol[[1]]],{t,0,tmax}]

(* the animation *)
car[t_]:={Line[{rwl[t],rwr[t]}],Line[{rearaxle[t],frontaxle[t]}],{Red,Line[{fwl[t],fwr[t]}]}}/.psol[[1]]/.params
trace[t_]:={Green,Line[Map[Function[Evaluate[{x[#],y[#]} /.psol[[1]]]],Range[0,t,0.025]]]}
Animate[Graphics[{car[t],trace[t]},PlotRange->{{-1,8},{-5,1}}, Axes->True,Ticks->False,ImageSize->500],{t,0,tmax,.025},AnimationRate->1/2, AnimationRunning->False]

(* the picewise controls *)inputFun[t_,t0_,lov_,which_]:=Piecewise@@{Table[{lov[[i,which]],Mod[t,t0 Length[lov]]<t0 i},{i,Length[lov]}]}
vvcontr[t_,which_]:=Module[{scheme=values},Piecewise@@{Table[{scheme[[i,which]],Mod[t,t0 Length[scheme]]<t0 i},{i,Length[scheme]}]}]
values1={{1,0},{0,1},{1,0},{0,-1}};
values2={{1,0},{0,1},{0,-1},{1,0}};
values3={{1,0},{0,1},{-1,0},{0,-1}};
values4={{1,1},{1,-1},{-1,-1},{-1,1}};
values5={{0,1},{1,0},{0,-2},{1,0},
{0,2},{-1,0},{0,-2},{-1,0},{0,1}};

pics={x[0]==0,y[0]==0,ϕ[0]==0,θ[0]==0};                       (* initial conditions *)
t0=1;
values=values5;
contrrules[t_]:={u1->inputFun[t,t0,values,1],u2->inputFun[t,t0,values,2]}  (* controls *)
tmax=40;
psol=NDSolve[{eqns,pics}/.params/.contrrules[t],{x,y,ϕ,θ},{t,0,tmax}];   (* solution *)

(* some plots *)
Plot[Evaluate[{x[t],y[t]}/.psol[[1]]],{t,0,tmax},PlotLegends->{"x","y"}]
ParametricPlot[Evaluate[{x[t],y[t]}/.psol[[1]]],{t,0,tmax}]

(* the animation *)
Animate[Graphics[{car[t],trace[t]},PlotRange->{{-2,3},{-2,4}}, Axes->True,Ticks->False,ImageSize->500],{t,0,tmax,.025},AnimationRate->1/2, AnimationRunning->False]

(* exporting to external file (in Wolfram Cloud the animation stutters) *)
plot=Table[Graphics[{car[t],trace[t]},PlotRange->{{-2,3},{-2,4}}, Axes->True,Ticks->False,ImageSize->500],{t,0,tmax,.025}];
Export["car_paralel.avi",plot]
(* Huge file - convert with ffmpeg -i car_paralel.avi -c:v mpeg4 car_paralel.mp4 *)

(* the periodic controls *)

contrrules[t_]:={u1->a1 Sin[ω1 t+ω10],u2->a2 Sin[ω2 t+ω20]}  (* controls *)
pics={x[0]==0,y[0]==0,ϕ[0]==0,θ[0]==0};                       (* initial conditions *)
contparams1={a1->1,a2->1,ω1->1,ω2->1,ω10->0,ω20->0};          (* back and forth *)
contparams2={a1->1,a2->1,ω1->1,ω2->1,ω10->0,ω20->Pi/2}; (* asterix *)
contparams3={a1->1,a2->1,ω1->2,ω2->1,ω10->0,ω20->Pi/2}; (* up and down *)
contparams4={a1->1,a2->1,ω1->1,ω2->2,ω10->0,ω20->Pi/2}; (* parallel parking *)
contparams=contparams4
tmax=40;
psol=NDSolve[{eqns,pics}/.params/.contrrules[t]/.contparams,{x,y,ϕ,θ},{t,0,tmax}]; (* solution *)

(* some plots *)
Plot[Evaluate[{x[t],y[t]}/.psol[[1]]],{t,0,tmax},PlotLegends->{"x","y"}]
ParametricPlot[Evaluate[{x[t],y[t]}/.psol[[1]]],{t,0,tmax}]

(* the animation *)
plot=Animate[Graphics[{car[t],trace[t]},PlotRange->{{-2,3},{-2,4}}, Axes->True,Ticks->False,ImageSize->500],{t,0,tmax,.025},AnimationRate->1/2, AnimationRunning->False]