Esempio n. 1
0
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;
}
Esempio n. 2
0
USING_NAMESPACE_ACADO

/* >>> start tutorial code >>> */
int main( )
{
    // DEFINE A RIGHT-HAND-SIDE:
    // -------------------------
    DifferentialState         x;
    AlgebraicState            z;
    Parameter               p,q;

    DifferentialEquation f;

    f << dot(x) == -p*x*x*z  ;
    f <<     0  ==  q*q - z*z + 0.1*x;

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

    DVector xStart( 1 );
	xStart(0) = 1.0;
    
	DVector zStart( 1 );
	zStart(0) = 1.0;

	DVector pp( 2 );
	pp(0) = 1.0;
	pp(1) = 1.0;
	
    double t0   = 0.0 ;
    double tend = 1.0 ;

	Grid timeHorizon( t0,tend );


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

    IntegrationAlgorithm intAlg;

	intAlg.addStage( f, timeHorizon );

	intAlg.set( INTEGRATOR_PRINTLEVEL, HIGH );


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

	//integrator.freezeAll();
    intAlg.integrate( timeHorizon, xStart, zStart, pp );


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

    VariablesGrid differentialStates;
    VariablesGrid algebraicStates   ;

//    intAlg.getX ( differentialStates );
    intAlg.getLast( LOG_DIFFERENTIAL_STATES,differentialStates );
    intAlg.getXA( algebraicStates    );

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

    return 0;
}
Esempio n. 3
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;
}