vi[t_]=Sin[t];
vr[t_]=Abs[vi[t]]//PiecewiseExpand[#,t∈Reals]&;
Plot[{vi[t],vr[t]},{t,0,16}]

system={vo'[t]==charging[t]vr'[t]-(1-charging[t])vo[t]/(r c),vo[0]==0};
control={charging[0]==1,WhenEvent[vr'[t]<0,charging[t]->0],WhenEvent[And[vo[t]<vr[t],charging[t]==0,vr'[t]>0],charging[t]->1]};

pars={r->0.1,c->1000};
sol=NDSolve[{system,control}/.pars,vo,{t, 0,16},DiscreteVariables->charging∈{0,1}];

Plot[{vo[t]/.sol,vr[t]},{t,0,16}]