Manipulation Trajectory Optimization with Online Grasp Synthesis and Selection