Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Position-controlled actuators #63

Closed
blandry opened this issue Mar 18, 2014 · 1 comment
Closed

Position-controlled actuators #63

blandry opened this issue Mar 18, 2014 · 1 comment

Comments

@blandry
Copy link
Contributor

blandry commented Mar 18, 2014

Drake should have a way of modeling actuators that take position as input (like servos) directly from URDFs. This would of course be an abstraction for the controller inside the servo but most people assume those controllers to be "ideal" anyway.

A temporary workaround I found is to build a PD controller around a RigidBodyManipulator yourself.

                        +-------+         +--------+
                        |       |         |        |
        u +--------+--->|    T  +-------->|   RBM  +---+-----> x
                   ^    +-------+         +--------+   |
                   |                                   |
                   |                                   |
                   |                                   |
                   |            +---------+            |
                   |            |         |            |
                   +------------+    LS   |<-----------+
                                |         |
                                +---------+

The T is the mechanicalReduction in your URDF (which is technically inside RBM but is easier to see that way), RBM is your RigidBodyManipulator and LS is a LinearSystem (the PD controller). Here is an example:

options.floating = true;
sys1 = RigidBodyManipulator('Sbach.urdf',options);

Kp = -500;
Kd = -400;
D = zeros(5,20);
D(1,7) = Kp; 
D(2,8) = Kp;
D(3,9) = Kp;
D(4,10) = Kp;
D(5,10) = 0; % thrust
D(1,17) = Kd;
D(2,18) = Kd;
D(3,19) = Kd;
D(4,20) = Kd;
D(5,20) = 0;
sys2 = LinearSystem([],[],[],[],[],D);

t_1out_2in = AffineTransform(sys1.getOutputFrame(),sys2.getInputFrame(),eye(20),zeros(20,1));
t_2out_1in = AffineTransform(sys2.getOutputFrame(),sys1.getInputFrame(),eye(5),zeros(5,1));
sys1.getOutputFrame().addTransform(t_1out_2in);
sys2.getOutputFrame().addTransform(t_2out_1in);

p = feedback(sys1,sys2);

x0 = [0 0 3 0 0 0 -.75 -.75 -.75 0 10 0 0 0 0 0 0 0 0 0]';
tf = .5;
pts = 10;
u0 = repmat([-.75 -.75 -.75 0  0]', 1, pts);
utraj = PPTrajectory(foh(linspace(0,tf,pts),u0));
utraj = setOutputFrame(utraj, p.getInputFrame);
pp = cascade(utraj,p);
xtraj = pp.simulate([0 tf], x0);

v = sys1.constructVisualizer();
v.playback(xtraj, struct('slider', true));

Things to take into consideration when tuning your PD controller:

  • P gain
  • D gain
  • Mechanical reduction in your URDF
  • Inertia matrix of the actuated joints
@RussTedrake
Copy link
Contributor

We actually have a pdcontrol function which implements this. :) Time stepping models also have an option to take position commands as input (adds additional constraints). I agree that we should have a tool for abstracting an arbitrarily stiff pd controller with a first order approximation, but then it is probably not strictly an rbm anymore... So we have to do it carefully.

madan-TRI pushed a commit to madan-TRI/drake that referenced this issue Jul 5, 2023
* update hopper cost function

* store vector of indices of unactuated DoFs

* compute equality constraint violations

* compute equality constraint jacobian

* constraint jacobian unit test with hopper

* draft dense KKT solve

* add merit linesearch

* add constraint violation to linesearch plots

* try drafting least squares lagrangian formulation

* fix bug in equality constraint jacobian

* drive equality constraints near zero with SQP linesearch

* isolate quadratic penalty bug

* add equality constriant penalty parameter

* isolate penalty function bug

* fix gradient bug

* quadratic underactuation penalty working

* try L1 norm penalty

* simple computation of constrained step in linesearch

* modified dogleg working with acrobot

* add equality constraint YAML parameter

* print constraint violation in trust region

* record and plot equality constraint violation

* equality constraints help moderately with spinner

* augmented cost decreases every iteration for acrobot

* change merit used in trust ratio calculation

* finger moves closer to spinner even without force at a distance

* even simpler spinner example where actuated torques should be zero but aren't

* isolate bug in equality constraint jacobian

* isolate equality constraint jacobian bug in unit test

* fix equality constraint jacobian bug for contact-less spinner

* new unit tests for equality constraint jacobian

* log and plot merit function

* use a (slightly) better merit function by fixing lagrange multipliers

* much stronger spinner example

* equality constraints working with all examples up to hopper

* set up caching for lagrange multipliers

* allocate Hinv*J' in the workspace

* fix gradient caching bug

* update comparison script

* add the merit function to the cache

* cache the gradient of the merit function

* print and log the gradient of the merit function instead of the gradient of the cost

* choose better linesearch parameters

* use trust region for spinner example

* remove old plotting script

* rough draft of combining scaling and equality constraints

* example of scaling and equality constraints working well together

* scaling + equality constraints: improves airhockey, same with spinner, makes hopper worse

* revert to non-adaptive sqrt type scaling

* correct descent direction sanity check

* add initial and maximum trust region radius as yaml parameters

* add scaling method yaml parameter

* don't compute inverse dynamics partials for q0

* use scaled trust ratio with dense algebra

* add unit test for combining scaling and equality constraints

* fix bug in trust ratio computation

* airhockey example works with all permutations of constraints and scaling

* cleanup

* don't assume particular scaling scheme in docs

* further cleanup
madan-TRI pushed a commit to madan-TRI/drake that referenced this issue Aug 9, 2023
* update hopper cost function

* store vector of indices of unactuated DoFs

* compute equality constraint violations

* compute equality constraint jacobian

* constraint jacobian unit test with hopper

* draft dense KKT solve

* add merit linesearch

* add constraint violation to linesearch plots

* try drafting least squares lagrangian formulation

* fix bug in equality constraint jacobian

* drive equality constraints near zero with SQP linesearch

* isolate quadratic penalty bug

* add equality constriant penalty parameter

* isolate penalty function bug

* fix gradient bug

* quadratic underactuation penalty working

* try L1 norm penalty

* simple computation of constrained step in linesearch

* modified dogleg working with acrobot

* add equality constraint YAML parameter

* print constraint violation in trust region

* record and plot equality constraint violation

* equality constraints help moderately with spinner

* augmented cost decreases every iteration for acrobot

* change merit used in trust ratio calculation

* finger moves closer to spinner even without force at a distance

* even simpler spinner example where actuated torques should be zero but aren't

* isolate bug in equality constraint jacobian

* isolate equality constraint jacobian bug in unit test

* fix equality constraint jacobian bug for contact-less spinner

* new unit tests for equality constraint jacobian

* log and plot merit function

* use a (slightly) better merit function by fixing lagrange multipliers

* much stronger spinner example

* equality constraints working with all examples up to hopper

* set up caching for lagrange multipliers

* allocate Hinv*J' in the workspace

* fix gradient caching bug

* update comparison script

* add the merit function to the cache

* cache the gradient of the merit function

* print and log the gradient of the merit function instead of the gradient of the cost

* choose better linesearch parameters

* use trust region for spinner example

* remove old plotting script

* rough draft of combining scaling and equality constraints

* example of scaling and equality constraints working well together

* scaling + equality constraints: improves airhockey, same with spinner, makes hopper worse

* revert to non-adaptive sqrt type scaling

* correct descent direction sanity check

* add initial and maximum trust region radius as yaml parameters

* add scaling method yaml parameter

* don't compute inverse dynamics partials for q0

* use scaled trust ratio with dense algebra

* add unit test for combining scaling and equality constraints

* fix bug in trust ratio computation

* airhockey example works with all permutations of constraints and scaling

* cleanup

* don't assume particular scaling scheme in docs

* further cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants