We have proposed a real-time self-collision avoidance control method for the robot which is used for human-robot cooperation. In this method, we represent the body of the robot by using elastic elements referred to as "RoBE (Representation of Body by Elastic elements)". The self-collision avoidance motion could be realized based on a reaction force generated by the contacts between the elastic elements before the actual self-collision of the robot. In this paper, especially, we consider task constraints and environmental constraints during the self-collision avoidance motion, and propose two priority functions for robots to realize the several kinds of tasks in an environment based on the force/moment applied by a human. By using this control algorithm, we could apply the proposed control algorithm to any robot systems used for human-robot cooperation. The proposed motion control algorithm is implemented in a human-friendly robot, referred to as "MR Helper", and experiments are done for illustrating the validity of the proposed self-collision avoidance motion.