void EventSendingController::mouseMoveTo(int x, int y)
{
#ifdef USE_WEBPROCESS_EVENT_SIMULATION
    m_position.x = x;
    m_position.y = y;
    WKBundlePageSimulateMouseMotion(InjectedBundle::shared().page()->page(), m_position, m_time);
#else
    WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
    WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());

    WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
    WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("MouseMoveTo"));
    WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());

    WKRetainPtr<WKStringRef> xKey(AdoptWK, WKStringCreateWithUTF8CString("X"));
    WKRetainPtr<WKDoubleRef> xRef(AdoptWK, WKDoubleCreate(x));
    WKDictionaryAddItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());

    WKRetainPtr<WKStringRef> yKey(AdoptWK, WKStringCreateWithUTF8CString("Y"));
    WKRetainPtr<WKDoubleRef> yRef(AdoptWK, WKDoubleCreate(y));
    WKDictionaryAddItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());

    WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
#endif
}
Пример #2
0
returnValue PIDcontroller::step(	double currentTime,
									const Vector& _x,
									const Vector& _p,
									const VariablesGrid& _yRef
									)
{
	if ( getStatus( ) != BS_READY )
		return ACADOERROR( RET_BLOCK_NOT_READY );

	if ( _x.getDim( ) != getNumInputs( ) )
		return ACADOERROR( RET_VECTOR_DIMENSION_MISMATCH );


	/* 1) Use reference trajectory if it is defined */
	// set default reference to zero
	Vector xRef( _x.getDim() );

	if ( _yRef.getNumPoints( ) > 0 )
	{
		if ( _yRef.getNumValues( ) != getNumInputs( ) )
			return ACADOERROR( RET_VECTOR_DIMENSION_MISMATCH );

		xRef = _yRef.getVector( 0 );
	}
	else
	{
		xRef.setZero( );
	}


	/* 2) Determine PID control action. */
	if ( getNumOutputs( ) > 0 )
	{
		if ( determineControlAction( xRef-_x,u ) != SUCCESSFUL_RETURN )
			return ACADOERROR( RET_CONTROLLAW_STEP_FAILED );
	}
	else
		u.init();

	p = _p;


	/* 3) Call output transformator. */
	if ( clipSignals( u,p ) != SUCCESSFUL_RETURN )
		return ACADOERROR( RET_OUTPUTTRANSFORMATOR_STEP_FAILED );

	return SUCCESSFUL_RETURN;
}
void EventSendingController::setTouchPointRadius(int radiusX, int radiusY)
{
    WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
    WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());

    WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
    WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("SetTouchPointRadius"));
    WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());

    WKRetainPtr<WKStringRef> xKey(AdoptWK, WKStringCreateWithUTF8CString("RadiusX"));
    WKRetainPtr<WKUInt64Ref> xRef(AdoptWK, WKUInt64Create(radiusX));
    WKDictionaryAddItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());

    WKRetainPtr<WKStringRef> yKey(AdoptWK, WKStringCreateWithUTF8CString("RadiusY"));
    WKRetainPtr<WKUInt64Ref> yRef(AdoptWK, WKUInt64Create(radiusY));
    WKDictionaryAddItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());

    WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
}
void EventSendingController::mouseScrollBy(int x, int y)
{
    WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
    WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());

    WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
    WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("MouseScrollBy"));
    WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());

    WKRetainPtr<WKStringRef> xKey(AdoptWK, WKStringCreateWithUTF8CString("X"));
    WKRetainPtr<WKDoubleRef> xRef(AdoptWK, WKDoubleCreate(x));
    WKDictionaryAddItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());

    WKRetainPtr<WKStringRef> yKey(AdoptWK, WKStringCreateWithUTF8CString("Y"));
    WKRetainPtr<WKDoubleRef> yRef(AdoptWK, WKDoubleCreate(y));
    WKDictionaryAddItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());

    WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
}
Пример #5
0
returnValue PIDcontroller::init(	double startTime,
									const Vector &x0_,
									const Vector &p_,
									const VariablesGrid& _yRef
									)
{
	if ( x0_.getDim( ) != getNumInputs( ) )
		return ACADOERROR( RET_VECTOR_DIMENSION_MISMATCH );

	// Use reference trajectory if it is defined, 
	// otherwise set default reference to zero
	Vector xRef( x0_.getDim() );

	if ( _yRef.getNumPoints( ) > 0 )
	{
		if ( _yRef.getNumValues( ) != getNumInputs( ) )
			return ACADOERROR( RET_VECTOR_DIMENSION_MISMATCH );

		xRef = _yRef.getVector( 0 );
	}
	else
	{
		xRef.setZero( );
	}


	// initialize control and parameter signals
	u.init( getNumOutputs() );
	u.setZero( );
	
	p = p_;


	lastError = xRef - x0_;

	setStatus( BS_READY );

	return SUCCESSFUL_RETURN;
}
Пример #6
0
void RecordedCamera::initializeViewUp()
{
    if(m_translationPositions.isSet() && m_translationPositions.getValue().size() > 1)
    {
        Vec3 zAxis = m_translationPositions.getValue()[1] -  m_translationPositions.getValue()[0];
        zAxis.normalize();
        Vec3 xRef(1,0,0);
        // Initialize the view-up vector with the reference vector the "most perpendicular" to zAxis.
         m_cameraUp.setValue(xRef);
        double normCrossProduct = cross(zAxis,xRef).norm();
        for(int i = 1; i<3; ++ i)
        {
            Vec3 vecRef(0,0,0);
            vecRef[i] = 1;
            if(cross(zAxis,vecRef).norm() >= normCrossProduct )
            {
                normCrossProduct = cross(zAxis,vecRef).norm();
                m_cameraUp.setValue(vecRef);
            }
        }
    }
}
void EventSendingController::updateTouchPoint(int index, int x, int y)
{
    WKRetainPtr<WKStringRef> EventSenderMessageName(AdoptWK, WKStringCreateWithUTF8CString("EventSender"));
    WKRetainPtr<WKMutableDictionaryRef> EventSenderMessageBody(AdoptWK, WKMutableDictionaryCreate());

    WKRetainPtr<WKStringRef> subMessageKey(AdoptWK, WKStringCreateWithUTF8CString("SubMessage"));
    WKRetainPtr<WKStringRef> subMessageName(AdoptWK, WKStringCreateWithUTF8CString("UpdateTouchPoint"));
    WKDictionaryAddItem(EventSenderMessageBody.get(), subMessageKey.get(), subMessageName.get());

    WKRetainPtr<WKStringRef> indexKey(AdoptWK, WKStringCreateWithUTF8CString("Index"));
    WKRetainPtr<WKUInt64Ref> indexRef(AdoptWK, WKUInt64Create(index));
    WKDictionaryAddItem(EventSenderMessageBody.get(), indexKey.get(), indexRef.get());

    WKRetainPtr<WKStringRef> xKey(AdoptWK, WKStringCreateWithUTF8CString("X"));
    WKRetainPtr<WKUInt64Ref> xRef(AdoptWK, WKUInt64Create(x));
    WKDictionaryAddItem(EventSenderMessageBody.get(), xKey.get(), xRef.get());

    WKRetainPtr<WKStringRef> yKey(AdoptWK, WKStringCreateWithUTF8CString("Y"));
    WKRetainPtr<WKUInt64Ref> yRef(AdoptWK, WKUInt64Create(y));
    WKDictionaryAddItem(EventSenderMessageBody.get(), yKey.get(), yRef.get());

    WKBundlePostSynchronousMessage(InjectedBundle::shared().bundle(), EventSenderMessageName.get(), EventSenderMessageBody.get(), 0);
}
returnValue AuxiliaryFunctionsExport::setup( )
{
	String fileName( "auxiliary_functions.c" );

	int printLevel;
	get( PRINTLEVEL,printLevel );

	if ( (PrintLevel)printLevel >= HIGH ) 
		acadoPrintf( "--> Preparing to export %s... ",fileName.getName() );


	ExportVariable x   ( "x",    N+1,NX, REAL,ACADO_VARIABLES );
	ExportVariable u   ( "u",    N,NU,   REAL,ACADO_VARIABLES );
	ExportVariable p   ( "p",    1,NP,   REAL,ACADO_VARIABLES );
	ExportVariable xRef( "xRef", N+1,NX, REAL,ACADO_VARIABLES );
	ExportVariable uRef( "uRef", N,NU,   REAL,ACADO_VARIABLES );


	getAcadoVariablesX.setup( "getAcadoVariablesX" );
	getAcadoVariablesX.setReturnValue( x,BT_TRUE );

	getAcadoVariablesU.setup( "getAcadoVariablesU" );
	getAcadoVariablesU.setReturnValue( u,BT_TRUE );

	getAcadoVariablesXRef.setup( "getAcadoVariablesXRef" );
	getAcadoVariablesXRef.setReturnValue( xRef,BT_TRUE );

	getAcadoVariablesURef.setup( "getAcadoVariablesURef" );
	getAcadoVariablesURef.setReturnValue( uRef,BT_TRUE );


	printStates.setup( "printStates" );
	printStates.addStatement( ExportPrintf(x.getTranspose()) );

	printControls.setup( "printControls" );
	printControls.addStatement( ExportPrintf(u.getTranspose()) );


	int operatingSystem;
	get( OPERATING_SYSTEM,operatingSystem );

	getTime.setup( "getTime" );
	ExportVariable currentTime( "current_time",(Matrix)0.0 );
	currentTime.callByValue();

	if ( (OperatingSystem)operatingSystem == OS_WINDOWS )
	{
		getTime.addStatement( "LARGE_INTEGER counter, frequency;\n" );
		getTime.addStatement( "QueryPerformanceFrequency(&frequency);\n" );
		getTime.addStatement( "QueryPerformanceCounter(&counter);\n" );
		getTime.addStatement( "current_time = ((real_t) counter.QuadPart) / ((real_t) frequency.QuadPart);\n" );
	}
	else
	{
		// OS_UNIX
		getTime.addStatement( "struct timeval theclock;\n" );
		getTime.addStatement( "gettimeofday( &theclock,0 );\n" );
		getTime.addStatement( "current_time = 1.0*theclock.tv_sec + 1.0e-6*theclock.tv_usec;\n" );
	}

	getTime.setReturnValue( currentTime );


	printHeader.setup( "printHeader" );
	printHeader.addStatement( "    printf(\"\\nACADO Toolkit -- A Toolkit for Automatic Control and Dynamic Optimization.\\nCopyright (C) 2008-2011 by Boris Houska and Hans Joachim Ferreau, K.U.Leuven.\\nDeveloped within the Optimization in Engineering Center (OPTEC) under\\nsupervision of Moritz Diehl. All rights reserved.\\n\\nACADO Toolkit is distributed under the terms of the GNU Lesser\\nGeneral Public License 3 in the hope that it will be useful,\\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\\nGNU Lesser General Public License for more details.\\n\\n\" );\n" );

	if ( (PrintLevel)printLevel >= HIGH ) 
		acadoPrintf( "done.\n" );

	return SUCCESSFUL_RETURN;
}