Creating a new class of Drone system UGV+UAV

Hello Folks,
I am trying to create new vehicle class system. It is combination of Rover and Quadcopter which will switch its ability to drive and fly whenever an obstacle is detected. I know that I have to build an airframe and burn it on the firmware but I am unable to understand where i can code the switching of rover motor and drone motor? If someone can help me with that I’ll be grateful