1.Is it possible to make drone automatically Arm, Take off and Resume to the last waypoint and continue the mission after every time the battery swapping? using drone kit running on raspberry pi.
2. Or I have to go for Lua script only to do this?
If you are willing to do a bit of programming you can get DroneKit or another API to help you out.
For dronekit, the mission upload/download and progress tracking should let you do what you want.
You didn’t specify how you are currently loading missions, but if you are already loading them via DroneKit, then you can monitor next waypoint (vehicle.commands.next, see last function in the link about how to calculate the distance, the waypoint is important, less so the distance), you should save this somewhere persistent whenever it changes.
At boot/reconnect your code can see if it thought it was already meant to be flying a mission, load that mission into the AP, and then perform the ARM, Take-off actions, then switch to Auto mode and jump to the target waypoint.
I highly recommend you have some external way of triggering this process to start (or at minimum, disable or delay it) to avoid accidentally arming/taking-off when someone is in close proximity to your drone.
Edit: Btw, if you consider ‘reconnect’ as reboot, then you can use SITL to test this out and stop/start the SITL to simulate replacing the battery.
I think you can do this by watching for mode changes.
When the mode changes to AUTO (or GUIDED), you can use the example code to capture and record the mission.
When the mode changes to RTL, you can capture the current position.
Make sure to record the last ‘next waypoint’ value.
Then, when the program starts, you can look to see if you have recorded a mission, if you do, you can use simple_goto() to return to the place that the failsafe occurred, and then reload the mission and jump to the waypoint you recorded as being the ‘next waypoint’.