He lost the fight against Kakashi as he himself said, staying there wouldnt have made sense as only death was awaiting him.
He obviously thought Madara would help him as Obito was the sole opportunity to be brought back to life.... without Obito Madara is doomed to be an Edo tensei.
Obito didnt expect Madara to have planted his own chakra stakes into him tho, which now turned him into a puppet.
So yeah Madara is currently controlling Obito through the rods in his body and is currently forming the Rennei Tensei seals.
Also remember (in case you're complaining about plot no jutsu from Madara) that Madara had planted these rods long ago.
When Obito went on a rampage to kill the Bloody mist minjas... the rods came out of his body... so while we did not understand the meaning of this back then now we know that it was Madara.
After all, Madara, when exlaining the gedo mazo and etc.... said that the rods were HIS materialisation of chakra/hated.