forked from peterkty/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
resolves bug 1153 - bouncing ball code needs frame specifications
minor fixes in export to movie code. git-svn-id: https://svn.csail.mit.edu/locomotion/robotlib/trunk@3746 c9849af7-e679-4ec6-a44e-fc146a885bd3
- Loading branch information
russt
committed
Sep 8, 2012
1 parent
a5f5ab8
commit 71a67c6
Showing
6 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
classdef MassSpringDamperPlant < SecondOrderSystem | ||
% Defines the dynamics for the Pendulum. | ||
|
||
properties | ||
m = 1; % kg | ||
b = .5; | ||
k = 20; | ||
end | ||
|
||
methods | ||
function obj = MassSpringDamperPlant() | ||
% Construct a new PendulumPlant | ||
obj = obj@SecondOrderSystem(1,1,true); | ||
obj = setOutputFrame(obj,obj.getStateFrame); | ||
end | ||
|
||
function qdd = sodynamics(obj,t,q,qd,u) | ||
% Implement the second-order dynamics | ||
qdd = (u - obj.k*q - obj.b*qd)/obj.m; | ||
end | ||
|
||
function x = getInitialState(obj) | ||
% Start me anywhere! | ||
x = randn(2,1); | ||
end | ||
end | ||
|
||
end |
48 changes: 48 additions & 0 deletions
48
examples/dev/mass_spring_damper/MassSpringDamperVisualizer.m
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
classdef MassSpringDamperVisualizer < Visualizer | ||
% Implements the draw function for the Pendulum | ||
|
||
% todo: use correct pendulum parameters (possibly acquire them via a | ||
% constructor?) | ||
|
||
methods | ||
function obj = MassSpringDamperVisualizer(r) | ||
obj = obj@Visualizer(r.getStateFrame); | ||
end | ||
|
||
function draw(obj,t,x) | ||
persistent hFig base wb lwheel rwheel spring dashpot; | ||
if (isempty(hFig)) | ||
hFig = figure(25); | ||
set(hFig,'DoubleBuffer', 'on'); | ||
|
||
theta = pi*[0:0.025:2]; | ||
wb = .3; hb=.2; | ||
wheelr = 0.05; | ||
lwheel = [-wb/2 + wheelr*cos(theta); wheelr + wheelr*sin(theta)]'; | ||
base = [wb*[1 -1 -1 1]; hb*[1 1 -1 -1]+hb+2*wheelr]'; | ||
spring = [ 0,linspace(.2,.8,length(theta)),1; [0,.1*sin(8*theta),0]+.3 ]; | ||
end | ||
|
||
figure(hFig); cla; hold on; view(0,90); | ||
|
||
x = x(1); | ||
% draw the cart | ||
patch(x(1)+base(:,1), base(:,2),0*base(:,1),'b','FaceColor',[.3 .6 .4]) | ||
patch(x(1)+lwheel(:,1), lwheel(:,2), 0*lwheel(:,1),'k'); | ||
patch(x(1)+wb+lwheel(:,1), lwheel(:,2), 0*lwheel(:,1),'k'); | ||
|
||
% draw the floor | ||
line([-5,5],[0,0],'Color',.7*[1 1 1],'LineWidth',1.2); | ||
|
||
% draw the wall | ||
line([-1,-1],[0,1],'Color',.7*[1 1 1],'LineWidth',1.2); | ||
|
||
% draw the spring | ||
plot(-1+spring(1,:)*(x-wb+1),spring(2,:),'k'); | ||
|
||
axis equal; | ||
axis([-1.5 1.5 -0.5 1]); | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters