A Study of Direct Sensitivity Method Solving Optimal Control Problems with Single and Multiple Time Grids with an Application in An Experimental Hybrid System