Position control for robot base?

Official Python bindings with a focus on reinforcement learning and robotics.
Post Reply
victoriax
Posts: 2
Joined: Mon Jun 04, 2018 6:50 pm

Position control for robot base?

Post by victoriax » Mon Jun 04, 2018 7:16 pm

Hi, new user trying to get started with pyBullet here. What's the best way to move a robot's base to a specified target location?

For context, I have a "floating" robot (I'm only modeling the hand, as I want a simple example that doesn't involve inverse kinematics) and I want to move this robot hand to a specified location via a direct trajectory, possibly pushing other objects out of the way as it moves.

I found a few viable approaches from the pyBullet GitHub examples, but I have reservations about each of them:
  • VR examples, such as vrhand.py (https://github.com/bulletphysics/bullet ... /vrhand.py), move floating hands around with changeConstraint(), but if I understand correctly this is to account for receiving input in frames, and not the intended way to simulate continuous motion.
  • Non-VR examples of robot motion, such as robotcontrol.py (https://github.com/bulletphysics/bullet ... control.py), use setJointMotorControl2() and velocity control to move robots/vehicles around, but I'd really like position control instead. While setJointMotorControl2() has an option for position control instead of velocity control, it seems to control joint position relative to the robot base, rather than moving the robot base itself.
  • Other examples use applyExternalForce() to move the robot base, as in externalTorqueControlledSphere.py (https://github.com/bulletphysics/bullet ... dSphere.py), but I really prefer position control to force control, as I worry that implementing my own PID controller (or a similar controller) will be finicky.
Which of these three approaches is preferred? Is there some other approach I'm not aware of? Thanks in advance!

keithmgould
Posts: 12
Joined: Thu May 31, 2018 5:21 pm

Re: Position control for robot base?

Post by keithmgould » Tue Jun 05, 2018 7:49 pm

I'm also new.

I _think_ what you want is just resetBasePositionAndOrientation(). Find more detail in the quick-start guide:

https://docs.google.com/document/d/10sX ... og8ua34um1

victoriax
Posts: 2
Joined: Mon Jun 04, 2018 6:50 pm

Re: Position control for robot base?

Post by victoriax » Wed Jun 06, 2018 2:09 pm

keithmgould wrote:
Tue Jun 05, 2018 7:49 pm

I _think_ what you want is just resetBasePositionAndOrientation(). Find more detail in the quick-start guide:

https://docs.google.com/document/d/10sX ... og8ua34um1
The guide says resetBasePositionAndOrientation() "will override the effect of all physics simulation" which means it cannot be used as part of a simulation where the object being moved around is able to push other objects out of the way -- or at least that's the behavior I'm observing. Am I missing something?

User avatar
Erwin Coumans
Site Admin
Posts: 4189
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Position control for robot base?

Post by Erwin Coumans » Wed Jun 06, 2018 3:49 pm

Indeed, you should not call resetBasePositionAndOrientation during the simulation, since it is an abrupt change that ignore and violates all dynamics, and likely give bad simulations and artifacts. If you reset the simulation (right after loading the URDF file or when teleporting a robot back to its original location, to start a new experiment), you can call resetBasePositionAndOrientation.

Using the changeConstraint (as in vrHand) is likely the best to move the hand, and then animate the constraint target.

Just call the changeConstraint with the desired position/orientation right before you call 'stepSimulation' . There will be a small delay to reach the actual position/orientation, but this is a good way to avoid discontinuities inside the physics engine.

Good luck!
Erwin

keithmgould
Posts: 12
Joined: Thu May 31, 2018 5:21 pm

Re: Position control for robot base?

Post by keithmgould » Fri Jun 08, 2018 4:51 pm

Ah, I missed that it was happening *during* the simulation. Sorry for the bad advice! Hope you have it all sorted now :)

arpastrana
Posts: 4
Joined: Wed Feb 27, 2019 4:56 pm

Re: Position control for robot base?

Post by arpastrana » Wed Feb 27, 2019 5:10 pm

Hi everyone, I wanted to reactivate the discussion since I'm looking for a way to move a robot's base during simulation by specifying velocities instead of positions.

So far, the proposed way to go via changeConstraint() currently takes in frame positions and orientations, but not linear or angular velocities. On the other hand, as victoriax pointed out, setJointMotorControl2() has an option for velocity control, but it seems to control joint position relative to the robot base, rather than moving the robot base itself.

The way I've temporarily got around this issue is by calling resetBaseVelocity(), although I'm aware that as Erwin stated, these reset commands will override the effects of the physics simulation.

Is there another alternative from your experience to move the robot base with velocities (linear, angular) while keeping the coherency of the simulation? Thanks in advance!

richardbloemenkamp
Posts: 14
Joined: Tue Sep 18, 2018 7:50 pm

Re: Position control for robot base?

Post by richardbloemenkamp » Wed Mar 06, 2019 5:33 pm

If you want to give velocities and angular velocities instead of position and orientation, then I think you can calculate the position and orientation in the next time step from your velocities and angular velocities and the time step duration (delta_t) . e.g.:
x_new = x_current + delta_t* x_velocity
y_new = y_current + delta_t* y_velocity
theta_new = theta_current + delta_t* theta_velocity
etc.
Once calculated you can set these values as position and orientation. If you do it each time step then it should result in the object moving with the desired velocity and angular velocity.
There are library functions for the conversion between Quaternions and Euler-angles back and forth and the order of angles is sometimes important but I think not if the time steps and/or the angular velocities remain small. Also the current position and orientation can be obtained with library functions.

User avatar
Erwin Coumans
Site Admin
Posts: 4189
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: Position control for robot base?

Post by Erwin Coumans » Sat Mar 09, 2019 1:24 am

You can attach the base to the (fixed) world frame with a couple of degrees of freedom. Then you can apply setJointMotorContro2 in POSITION_CONTROL mode, or VELOCITY_CONTROL mode to those degrees of freedom to move the base.

arpastrana
Posts: 4
Joined: Wed Feb 27, 2019 4:56 pm

Re: Position control for robot base?

Post by arpastrana » Tue May 07, 2019 8:00 am

Erwin Coumans wrote:
Sat Mar 09, 2019 1:24 am
You can attach the base to the (fixed) world frame with a couple of degrees of freedom. Then you can apply setJointMotorContro2 in POSITION_CONTROL mode, or VELOCITY_CONTROL mode to those degrees of freedom to move the base.
We are having a look at applying setJointMotorControl2 in VELOCITY_CONTROL model. How could we implement attaching the base with a couple few degrees of freedom? Would this imply loading a custom urdf with "virtual" joints per degree of freedom, assembling a multiBody, or creating a constraint?

steven
Posts: 65
Joined: Mon Nov 05, 2018 8:16 am
Location: China

Re: Position control for robot base?

Post by steven » Wed May 08, 2019 7:56 am

arpastrana wrote:
Wed Feb 27, 2019 5:10 pm
The way I've temporarily got around this issue is by calling resetBaseVelocity(), although I'm aware that as Erwin stated, these reset commands will override the effects of the physics simulation.
hi arpastrana,

i understand calling the resetBasePositionAndOrientation() will ignore the dynamic of the simulation, but why the resetBaseVelocity() also "override
the effects of the physics simulation". it only change the base velocity. i think the resetBaseVelocity() should can meet your requirement. is it right? thanks.

arpastrana
Posts: 4
Joined: Wed Feb 27, 2019 4:56 pm

Re: Position control for robot base?

Post by arpastrana » Wed May 08, 2019 10:02 am

steven wrote:
Wed May 08, 2019 7:56 am
hi arpastrana,
i understand calling the resetBasePositionAndOrientation() will ignore the dynamic of the simulation, but why the resetBaseVelocity() also "override
the effects of the physics simulation". it only change the base velocity. i think the resetBaseVelocity() should can meet your requirement. is it right? thanks.
Hi steven. resetBaseVelocity() did move our base nicely, but the problem was that when checking i.e. force-torque sensor readings when colliding our object onto something, these values were very very small. Moreover, the fact that resetBaseVelocity overrides was confirmed by erwin coumans here: https://github.com/bulletphysics/bullet ... -463617025

On the other hand, we have tried using p.CreateConstraint() at the base to move it around. That worked as well to move the base, and provided with more reasonable force-torque readings, though we had to transform velocities to position and orientations to change the constraint at the base via p.ChangeConstraint() as pointed out earlier in this thread.
richardbloemenkamp wrote:
Wed Mar 06, 2019 5:33 pm
If you want to give velocities and angular velocities instead of position and orientation, then I think you can calculate the position and orientation in the next time step from your velocities and angular velocities and the time step duration (delta_t) . e.g.:
x_new = x_current + delta_t* x_velocity
y_new = y_current + delta_t* y_velocity
theta_new = theta_current + delta_t* theta_velocity
However, when comparing read vs. sent velocities at the base, they were constantly downscaled by a factor of 5, and rotations around x and y had to be multiplied by -1 to make them comply with the right-hand-rule.

We are now looking into setJointMotorControl2 because we think it is more elegant to send directly velocities to joints (either linear or angular), but we're having a hard time to set this up properly. Any thoughts? Thanks in advance!

steven
Posts: 65
Joined: Mon Nov 05, 2018 8:16 am
Location: China

Re: Position control for robot base?

Post by steven » Wed May 08, 2019 1:33 pm

arpastrana wrote:
Wed May 08, 2019 10:02 am
Moreover, the fact that resetBaseVelocity overrides was confirmed by erwin coumans here: https://github.com/bulletphysics/bullet ... -463617025
my understanding is that we shouldn't use the resetBaseVelocity () during a running simulation, but can be used freely before stepsimulation.

i still think it is weird that we use a constraint to control the velocity, this should be the basic function for a physic engine.

richardbloemenkamp
Posts: 14
Joined: Tue Sep 18, 2018 7:50 pm

Re: Position control for robot base?

Post by richardbloemenkamp » Thu May 09, 2019 5:29 pm

arpastrana wrote:
Wed May 08, 2019 10:02 am
"However, when comparing read vs. sent velocities at the base, they were constantly downscaled by a factor of 5, and rotations around x and y had to be multiplied by -1 to make them comply with the right-hand-rule."
Maybe you can add a small piece of code with the strange behavior you see. Preferably code without dependencies on other files that we can try directly. There could be a problems with the delta_t or maybe with some friction or too-small force or secondary contraints or other. The right-hand-rule-issue may be related to the other two angles of your object and the order in which the rotations are applied or something else. So far I have not seen these kinds of issues myself but if there are indeed issues then I'm sure that there is motivation to solve them.

arpastrana
Posts: 4
Joined: Wed Feb 27, 2019 4:56 pm

Re: Position control for robot base?

Post by arpastrana » Tue May 14, 2019 6:39 pm

richardbloemenkamp wrote:
Thu May 09, 2019 5:29 pm
Maybe you can add a small piece of code with the strange behavior you see. Preferably code without dependencies on other files that we can try directly. There could be a problems with the delta_t or maybe with some friction or too-small force or secondary contraints or other.
I have attached a folder with some code that replicates the behaviour. If you run base_constraint.py, the script will print out in different colours the sent velocity, the read velocity at the robot base, as well as the division of the two, which is around 5.0 for all the 6 velocity degrees of freedom (linear xyz, angular xyz).

Basically, the environment consists of a shortened cylinder which can be moved around via userDebugParameters. The commanded velocity is then transformed into deltas, added up to the robot base position/orientation, and then used to change the constraint at the base via p.changeConstraint.
Attachments
robotless_base_constraint.zip
(14.09 KiB) Downloaded 40 times

Post Reply