A novel onboard trajectory planning methodology is proposed for lunar crater exploration. For the first time the flight trajectory is divided in to 5 phases: the vertical rise, the single axis rotation, the unpowered gliding, the approach and the vertical descent. According to different characters in these phases, transfer conditions and control modes are designed. Then a new method for state updating is developed in analytical and numerical ways. After that, 3 optimization parameters and 2 optimization objects are chosen. Considering the constraints, the reference trajectory is finally generated by the particle swarm optimization. Different from other planning, the guidance law is introduced during the unpowered gliding and the approach phase to improve optimization efficiency. Numerical simulations show that the methodology proposed is good real-time and the planned trajectory can meet all the requirements, which can improve the autonomous survivability of the explorer and is suitable for the lunar crater exploration.