I am not familiar with imu but I guess you can get retrieve information about robot accelerations. Then you can process it to have to robot do what you want.
You will have to integrate the imu with the robot controller and do some programming to have the robot do what you want.
If you move only 2 joints you won t be have to cover all possible orientation. At least 3 joints are necessary.
emile_
thank you for yr answer
Is it possible to control UR5 end effector orientation with imu? changing only the wrist4 and wrist5 angles?