ros-pybullet / ros_pybullet_interface

ROS-PyBullet Interface.
https://ros-pybullet.github.io/ros_pybullet_interface/
BSD 3-Clause "New" or "Revised" License
77 stars 14 forks source link

Errors for velocity/torque control #7

Open cr139139 opened 1 year ago

cr139139 commented 1 year ago

Hi. I was testing your interface and found some errors. I hope this helps someone who is having trouble with velocity or torque control.

  1. Typo in "pybullet_robot_joints.py" : You have to change 'targetVelocity' to 'targetVelocities' in the "set target" function for the "Joints" class to make the velocity control work.
  2. Unlock motors for torque control : You first have to unlock the joint motors with position/velocity control before force control. Unless, it will not move. You can see this issue at this link. I know this is not a good way, but I used an additional flag and changed the code like below just for fast testing.
    def set_target(self, joint_state_msg):

        # Set target
        if self.control_mode == self.pb_obj.pb.POSITION_CONTROL:
            target = {'targetPositions': joint_state_msg.position}            
        elif self.control_mode == self.pb_obj.pb.VELOCITY_CONTROL:
            target = {'targetVelocities': joint_state_msg.velocity}
        elif self.control_mode == self.pb_obj.pb.TORQUE_CONTROL:
            target = {'forces': joint_state_msg.effort}
            if self.init_flag:
                self.pb_obj.pb.setJointMotorControlArray(
                    self.pb_obj.body_unique_id,
                    [i for i in range(self.num_joints)],
                    self.pb_obj.pb.VELOCITY_CONTROL,
                    forces=[0]*self.num_joints
                )
                self.init_flag = False
        else:
            raise ValueError("did not recognize control mode!")
anubhav-dogra commented 1 year ago

Thanks for the edit suggestions. It worked !

I am trying to perform TORQUE_CONTROL mode on a serial manipulator, added through ros_description. However, Im facing problem in this mode. It seems like effort commands are never applied on the robot, as the robot keep falling on the ground on the start of simulation. No matter how large torque value is given. Do I need to apply torques through force = [value] under the hood of velocity control ? rather than sending effort commands in torque control mode?

Can you please clarify?

Things are working well in POSITION/VELOCITY control mode by sending position/velocity commands.

Thanks :)

secilmiskisi commented 3 days ago

Hi, I am having the same issue, even after doing the fix mentioned here. I am sure I am giving correct inputs to the setJointMotorControlArray. I can even see the topic being published at joint_states/target. But when I echo joint_states topic, I see no effort and the robot keeps falling down as if there is no torque being applied to the joints.

Any help on the topic would be appreciated.

secilmiskisi commented 2 days ago

I have solved the problem. It is related to the method of controlling torques. Bullet sees torque control commands as external forces. When I looked deeply into the pybullet documentation, it is written:

Note that this method will only work when explicitly stepping the simulation using stepSimulation, in other words: setRealTimeSimulation(0). After each simulation step, the external forces are cleared to zero. If you are using 'setRealTimeSimulation(1), applyExternalForce/Torque will have undefined behavior (either 0, 1 or multiple force/torque applications).

So when I set step_pybullet_manually: True , the issue was solved.

Hope this helps others.