system={x''[t]==u[t],x'[0]==x[0]==0,u[0]==1};
control=WhenEvent[Mod[t,τ],u[t]->kp(xref-x[t]-td x'[t])];
params={kp->1,td->1,τ->1,xref->1};

sol=NDSolve[{system,control}/.params,{x,u},{t,0,12}, DiscreteVariables->u];

Plot[Evaluate[{xref/.params,x[t],u[t]}/.sol],{t,0,12},PlotLegends->{"xref", "x(t)","u(t)"}]