RobotLocomotion / drake

Model-based design and verification for robotics.
https://drake.mit.edu
Other
3.29k stars 1.26k forks source link

How to find utraj for Quadrotor2D example? #511

Closed MatthewPeterKelly closed 9 years ago

MatthewPeterKelly commented 9 years ago

I'm working with the Quadrotor2D example in drake. It runs a simulation of a feedback system, composed of a plant and LQR controller. I can get xtraj and ytraj out of the system, but I would also like to get utraj: the output of the controller (and input to the plant). I've found a hack that sort of works, but I imagine that there must be some built-in method. Please let me know if there is, or perhaps this can be a feature request if not.

plant = PlanarQuadPlant;
visualizer = PlanarQuadVisualizer(plant);

controller = hoverLQR(plant);
system = feedback(plant,controller);

tSpan = [0,4];
xtraj = simulate(system,tSpan);

% Want something like: `utraj = evalControl(system,xtraj)`
% I do the following as a hack:
t = linspace(tSpan(1),tSpan(2),1000);
X = eval(xtraj,t);
K = controller.D;  %Extract linear gains
U = -K*X;  %Proxy for eval(utraj,t);
RussTedrake commented 9 years ago

Your call to feedback creates a new system with the plant outputs as the outputs. you can use mimoFeedback to connect the blocks, and specify that you’d additionally like to have the controller output as an output of the resulting system.

On Oct 28, 2014, at 9:06 AM, MatthewPeterKelly notifications@github.com wrote:

I'm working with the Quadrotor2D example in drake. It runs a simulation of a feedback system, composed of a plant and LQR controller. I can get xtraj and ytraj out of the system, but I would also like to get utraj: the output of the controller (and input to the plant). I've found a hack that sort of works, but I imagine that there must be some built-in method. Please let me know if there is, or perhaps this can be a feature request if not.

plant = PlanarQuadPlant; visualizer = PlanarQuadVisualizer(plant);

controller = hoverLQR(plant); system = feedback(plant,controller);

tSpan = [0,4]; xtraj = simulate(system,tSpan);

% Want something like: utraj = evalControl(system,xtraj) % I do the following as a hack: t = linspace(tSpan(1),tSpan(2),1000); X = eval(xtraj,t); K = controller.D; %Extract linear gains U = -K*X; %Proxy for eval(utraj,t); — Reply to this email directly or view it on GitHub.

RussTedrake commented 9 years ago

let us know (reopen the bug) if you still have problems.