When I ran the code for a drivetrain and opened serial monitor it was working, but when I powered on Arduino via dc Jack and ran the code. It was not working, because code is needed to restart after connection. I want to know that how can I solve this problem of PS2 communication and run my drivetrain without restart or starting serial monitor.
Code that I uploaded was given in this instructable http://www.instructables.com/id/Control-anything-with-ps2-controller-and-Arduino-/
I got my answer by experimenting a lot. First thing is that you have to either restart your arduino or configure your pin after connection of ps2 to arduino. This can be done by 2 ways : 1) Restart arduino after connection by code or 2) configure again after connection
1 option you know well, i am discussing 2nd i.e configure :
as you know that you have already configured pins by function ps2x.config_gamepad(); Now you have to reconfigure it after connection of ps2 to arduino, you can use a function called reconfig_gamepad(); after read_gamepad(); in void loop.
my code for holonomic drive train is below find out comments // there are total four commented lines in code. good luck. Hope this will solve your problem also.