当前位置: 首页>>代码示例>>C++>>正文


C++ VariablesGrid::addVector方法代码示例

本文整理汇总了C++中VariablesGrid::addVector方法的典型用法代码示例。如果您正苦于以下问题:C++ VariablesGrid::addVector方法的具体用法?C++ VariablesGrid::addVector怎么用?C++ VariablesGrid::addVector使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在VariablesGrid的用法示例。


在下文中一共展示了VariablesGrid::addVector方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: getDataGrids

returnValue PlotWindow::getDataGrids(	const VariablesGrid* const variablesGrid,
										VariableType& _type,
										VariablesGrid& _dataGrid,
										Grid& _discretizationGrid
										)
{
	_dataGrid.init();
	_discretizationGrid.init( );

	_type = variablesGrid->getType( );

	InterpolationMode mode = IM_LINEAR;
	if ( ( _type == VT_CONTROL ) || ( _type == VT_PARAMETER ) )
		mode = IM_CONSTANT;
	
	switch ( mode )
	{
		case IM_CONSTANT:
			_discretizationGrid.addTime( 0.0 );
			
			for( uint i=0; i<variablesGrid->getNumPoints( )-1; ++i )
			{
				_dataGrid.addVector( variablesGrid->getVector(i),variablesGrid->getTime(i) );
				_dataGrid.addVector( variablesGrid->getVector(i),variablesGrid->getTime(i+1) );
				_discretizationGrid.addTime( (double)_dataGrid.getNumPoints() );
			}
 			_dataGrid.addVector( variablesGrid->getLastVector(),variablesGrid->getLastTime() );
			_discretizationGrid.addTime( (double)_dataGrid.getNumPoints() );
			break;

		case IM_LINEAR:
			_dataGrid = *variablesGrid;
			break;

		default:
			return ACADOERROR( RET_NOT_YET_IMPLEMENTED );
	}

	_dataGrid.setType( _type );

	return SUCCESSFUL_RETURN;
}
开发者ID:OspreyX,项目名称:acado,代码行数:42,代码来源:plot_window.cpp

示例2: main

int main( )
{
    USING_NAMESPACE_ACADO

    // DEFINE THE VARIABLES:
    // ----------------------------------------------------------
    DifferentialState   p    ;  // the trolley position
    DifferentialState   v    ;  // the trolley velocity
    DifferentialState   phi  ;  // the excitation angle
    DifferentialState   omega;  // the angular velocity
    Control             a    ;  // the acc. of the trolley

    const double     g = 9.81;  // the gravitational constant
    const double     b = 0.20;  // the friction coefficient
    // ----------------------------------------------------------


    // DEFINE THE MODEL EQUATIONS:
    // ----------------------------------------------------------
    DifferentialEquation f;

    f << dot( p     )  ==  v                                ;
    f << dot( v     )  ==  a                                ;
    f << dot( phi   )  ==  omega                            ;
    f << dot( omega )  == -g*sin(phi) - a*cos(phi) - b*omega;
    // ----------------------------------------------------------


    // SETTING UP THE (SIMULATED) PROCESS:
    // -----------------------------------
    OutputFcn identity;
    DynamicSystem dynamicSystem( f,identity );
    Process process( dynamicSystem,INT_RK45 );


    // SETTING UP THE MPC CONTROLLER:
    // ------------------------------
    ExportedRTIscheme rtiScheme( 4,1, 10, 0.3 );
#ifdef USE_CVXGEN
    set_defaults( );
#endif

    Vector xuRef(5);
    xuRef.setZero( );

    VariablesGrid reference;
    reference.addVector( xuRef,  0.0 );
    reference.addVector( xuRef, 10.0 );

    StaticReferenceTrajectory referenceTrajectory( reference );

    Controller controller( rtiScheme,referenceTrajectory );
    controller.set( USE_REFERENCE_PREDICTION,NO );


    // SETTING UP THE SIMULATION ENVIRONMENT,  RUN THE EXAMPLE...
    // ----------------------------------------------------------
    SimulationEnvironment sim( 0.0,10.0, process,controller );

    Vector x0(4);
    x0(0) = 1.0;
    x0(1) = 0.0;
    x0(2) = 0.0;
    x0(3) = 0.0;

    sim.init( x0 );
    sim.run( );


    // ... AND PLOT THE RESULTS
    // ------------------------
    VariablesGrid diffStates;
    sim.getProcessDifferentialStates( diffStates );

    VariablesGrid feedbackControl;
    sim.getFeedbackControl( feedbackControl );

    GnuplotWindow window;
    window.addSubplot( diffStates(0), "p" );
    window.addSubplot( diffStates(1), "v" );
    window.addSubplot( diffStates(2), "phi" );
    window.addSubplot( diffStates(3), "omega" );
    window.addSubplot( feedbackControl(0), "a" );
    window.plot( );

    return 0;
}
开发者ID:rtkg,项目名称:acado,代码行数:87,代码来源:getting_started_closed_loop.cpp


注:本文中的VariablesGrid::addVector方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。