コード例 #1
0
ファイル: pendulum.cpp プロジェクト: borishouska/acado
USING_NAMESPACE_ACADO

int main( )
{
	// Define a Right-Hand-Side:
	// -------------------------
	DifferentialState	phi; // the angle phi
	DifferentialState dphi; // the first derivative of phi w.r.t time
	Control F; // a force acting on the pendulum
	Parameter l; // the length of the pendulum

	const double m = 1.0; // the mass of the pendulum
	const double g = 9.81; // the gravitational constant
	const double alpha = 2.0; // friction constant

	IntermediateState z;
	DifferentialEquation f;

	z = sin(phi);

	f << dot(phi ) == dphi;
	f << dot(dphi) == -(m*g/l)*z - alpha*dphi + F/(m*l);

	// DEFINE INITIAL VALUES:
	// ----------------------

	DVector xStart( 2 );
	xStart(0) = 1.0;
	xStart(1) = 0.0;

	DVector xa;

	DVector u( 1 );
	u(0) = 0.0;

	DVector p( 1 );
	p(0) = 1.0;

	double tStart = 0.0;
	double tEnd = 2.0;

	Grid timeHorizon( tStart,tEnd );

	// DEFINE AN INTEGRATOR:
	// ---------------------

	IntegrationAlgorithm intAlg;

	intAlg.addStage( f, timeHorizon, INT_RK45 );

	//intAlg.set( INTEGRATOR_TYPE, INT_RK45 );
	intAlg.set( INTEGRATOR_PRINTLEVEL, HIGH );
	intAlg.set( INTEGRATOR_TOLERANCE, 1.0e-6 );

	// START THE INTEGRATION:
	// ----------------------

	intAlg.integrate( timeHorizon, xStart,xa,p,u );

	// GET THE RESULTS
	// ---------------

	VariablesGrid differentialStates;
	intAlg.getX( differentialStates );

	cout << "x = " << endl << differentialStates << endl;

	return 0;
}
コード例 #2
0
/* >>> start tutorial code >>> */
int main( ){


    USING_NAMESPACE_ACADO

    // Define a Right-Hand-Side:
    // -------------------------
    DifferentialState     x;
    DifferentialEquation  f;
    TIME t;

    f << dot(x) == -x + sin(0.01*t);


    // Define an initial value:
    // ------------------------

	Vector xStart( 1 );
	xStart(0) = 1.0;

    double tStart    =   0.0;
    double tEnd      =   1000.0;

	Grid timeHorizon( tStart,tEnd,2 );
	Grid timeGrid( tStart,tEnd,20 );


    // Define an integration algorithm:
    // --------------------------------

	IntegrationAlgorithm intAlg;
	
	intAlg.addStage( f, timeHorizon );

	intAlg.set( INTEGRATOR_TYPE, INT_BDF );
    intAlg.set( INTEGRATOR_PRINTLEVEL, MEDIUM );
    intAlg.set( INTEGRATOR_TOLERANCE, 1.0e-3 );
	intAlg.set( PRINT_INTEGRATOR_PROFILE, YES );
	intAlg.set( PLOT_RESOLUTION, HIGH );


	GnuplotWindow window;
	window.addSubplot( x,"x" );
	
	intAlg << window;


    // START THE INTEGRATION
    // ----------------------

    intAlg.integrate( timeHorizon, xStart );


    // GET THE RESULTS
    // ---------------

	VariablesGrid differentialStates;
	intAlg.getX( differentialStates );
	
	differentialStates.print( "x" );

	Vector xEnd;
	intAlg.getX( xEnd );
	
	xEnd.print( "xEnd" );


    return 0;
}