Ejemplo n.º 1
0
Archivo: mpc.hpp Proyecto: Zvone10/mpc
double MPC::myfunc(const std::vector<double> &u, std::vector<double> &grad, void *my_func_data){
	//double myfunc(unsigned dd, const double *u, double *grad, void *my_func_data){

		/********** Define x_uk_ matrix **********/

		Symbolic x_uk_pom;
		//x_uk_pom = Symbolic ("x_uk_pom", 4, controller.Hp_);
		x_uk_pom = x_uk_;

		/********** Substitute control variable in state matrix **********/

		x_uk_pom = substState(&u[0], x_uk_pom);

		/*
	    cout <<"Dimensions x_uk: "<< controller.x_uk_.rows() << " x " << controller.x_uk_.columns() << "\n";
	    cout << "x_uk_pom = " << x_uk_pom << "\n";
		*/

		/********** Get predictive output (Hw to Hp) **********/

		getPredictOutput(x_uk_pom);

		/*
	    cout <<"Dimensions nelin: "<< controller.nelin_.rows() << " x " << controller.nelin_.cols() << "\n";
	    cout << "nelin = \n" << controller.nelin_ << "\n";

	    cout <<"Dimensions zp: "<< controller.zp_.rows() << " x " << controller.zp_.cols() << "\n";
	    cout << "zp = \n" << controller.zp_ << "\n";

	    cout <<"Dimensions z_k: "<< controller.z_k_.rows() << " x " << controller.z_k_.cols() << "\n";
	    cout << "z_k = \n" << controller.z_k_ << "\n";
		*/

		/********** Substitute control variable in cost **********/

		substCost();

		/********** Get control window **********/

		getControlWindow(&u[0]);

		/*
	    cout <<"Dimensions u_k: "<< controller.u_k_.rows() << " x " << controller.u_k_.cols() << "\n";
	    cout << "u_k = \n" << controller.u_k_ << "\n";
		*/

		/*****************************************/

	    cout << "Iteracija br.: " << iter_ << "\n";
	    iter_++;

		/********** Get cost and return value **********/

		return getCost();
}
Ejemplo n.º 2
0
double MPC::myfunc(const std::vector<double> &tau, std::vector<double> &grad, void *my_func_data){
	//double myfunc(unsigned dd, const double *u, double *grad, void *my_func_data){

		/********** Define x_uk_ matrix **********/

		Symbolic z_uk_pom;
		z_uk_pom = z_uk_;

		/********** Substitute control variable in state matrix **********/

		z_uk_pom = substState(&tau[0], z_uk_pom);

		/*
	    cout <<"Dimensions z_uk: "<< controller.z_uk_.rows() << " x " << controller.z_uk_.columns() << "\n";
	    cout << "z_uk_pom = " << z_uk_pom << "\n";
		 */

		/********** Get predictive output (Hw to Hp) **********/

		getPredictOutput(z_uk_pom);

		/*
	    cout <<"Dimensions z_p: "<< controller.z_p_.rows() << " x " << controller.z_p_.cols() << "\n";
	    cout << "z_p = \n" << controller.zp_ << "\n";

	    cout <<"Dimensions z_k: "<< controller.z_k_.rows() << " x " << controller.z_k_.cols() << "\n";
	    cout << "z_k = \n" << controller.z_k_ << "\n";
		*/

		/********** Substitute control variable in cost **********/

		substCost();

		/********** Get control window **********/

		getControlWindow(&tau[0]);

		/*
	    cout <<"Dimensions tau_k: "<< controller.tau_k_.rows() << " x " << controller.tau_k_.cols() << "\n";
	    cout << "tau_k = \n" << controller.tau_k_ << "\n";
		*/

		/*****************************************/

	    cout << "Iteracija br.: " << iter_ << "\n";
	    iter_++;

		/********** Get cost and return value **********/

		return getCost();
}
Ejemplo n.º 3
0
void VlcPlugin::redrawToolbar()
{
    libvlc_exception_t ex;
    int is_playing = 0;
    bool b_mute = false;
    unsigned int dst_x, dst_y;
    GC gc;
    XGCValues gcv;
    unsigned int i_tb_width, i_tb_height;

    /* This method does nothing if toolbar is hidden. */
    if( !b_toolbar )
        return;

    const NPWindow& window = getWindow();
    Window control = getControlWindow();
    Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;

    getToolbarSize( &i_tb_width, &i_tb_height );

    libvlc_exception_init( &ex );

    /* get mute info */
    b_mute = libvlc_audio_get_mute( getVLC() );

    gcv.foreground = BlackPixel( p_display, 0 );
    gc = XCreateGC( p_display, control, GCForeground, &gcv );

    XFillRectangle( p_display, control, gc,
                    0, 0, window.width, i_tb_height );
    gcv.foreground = WhitePixel( p_display, 0 );
    XChangeGC( p_display, gc, GCForeground, &gcv );

    /* position icons */
    dst_x = BTN_SPACE;
    dst_y = i_tb_height >> 1; /* baseline = vertical middle */

    if( p_btnPause && (is_playing == 1) )
    {
        XPutImage( p_display, control, gc, p_btnPause, 0, 0, dst_x,
                   dst_y - (p_btnPause->height >> 1),
                   p_btnPause->width, p_btnPause->height );
        dst_x += BTN_SPACE + p_btnPause->width;
    }
Ejemplo n.º 4
0
void VlcPlugin::hideToolbar()
{
    const NPWindow& window = getWindow();
    Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
    Window control = getControlWindow();
    Window video = getVideoWindow();

    i_tb_width = i_tb_height = 0;

    if( p_btnPlay )  XDestroyImage( p_btnPlay );
    if( p_btnPause ) XDestroyImage( p_btnPause );
    if( p_btnStop )  XDestroyImage( p_btnStop );
    if( p_timeline ) XDestroyImage( p_timeline );
    if( p_btnTime )  XDestroyImage( p_btnTime );
    if( p_btnFullscreen ) XDestroyImage( p_btnFullscreen );
    if( p_btnMute )  XDestroyImage( p_btnMute );
    if( p_btnUnmute ) XDestroyImage( p_btnUnmute );

    p_btnPlay = NULL;
    p_btnPause = NULL;
    p_btnStop = NULL;
    p_timeline = NULL;
    p_btnTime = NULL;
    p_btnFullscreen = NULL;
    p_btnMute = NULL;
    p_btnUnmute = NULL;

    /* reset panels position and size */
    /* XXX  use i_width */
    XResizeWindow( p_display, video, window.width, window.height );
    XMoveWindow( p_display, control, 0, window.height-1 );
    XResizeWindow( p_display, control, window.width, 1 );

    b_toolbar = 0; /* says toolbar is now hidden */
    redrawToolbar();
}
Ejemplo n.º 5
0
void VlcPlugin::showToolbar()
{
    const NPWindow& window = getWindow();
    Window control = getControlWindow();
    Window video = getVideoWindow();
    Display *p_display = ((NPSetWindowCallbackStruct *)window.ws_info)->display;
    unsigned int i_height = 0, i_width = BTN_SPACE;

    /* load icons */
    if( !p_btnPlay )
        XpmReadFileToImage( p_display, DATA_PATH "/mozilla/play.xpm",
                            &p_btnPlay, NULL, NULL);
    if( p_btnPlay )
    {
        i_height = __MAX( i_height, p_btnPlay->height );
    }
    if( !p_btnPause )
        XpmReadFileToImage( p_display, DATA_PATH "/mozilla/pause.xpm",
                            &p_btnPause, NULL, NULL);
    if( p_btnPause )
    {
        i_height = __MAX( i_height, p_btnPause->height );
    }
    i_width += __MAX( p_btnPause->width, p_btnPlay->width );

    if( !p_btnStop )
        XpmReadFileToImage( p_display, DATA_PATH "/mozilla/stop.xpm",
                            &p_btnStop, NULL, NULL );
    if( p_btnStop )
    {
        i_height = __MAX( i_height, p_btnStop->height );
        i_width += BTN_SPACE + p_btnStop->width;
    }
    if( !p_timeline )
        XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_line.xpm",
                            &p_timeline, NULL, NULL);
    if( p_timeline )
    {
        i_height = __MAX( i_height, p_timeline->height );
        i_width += BTN_SPACE + p_timeline->width;
    }
    if( !p_btnTime )
        XpmReadFileToImage( p_display, DATA_PATH "/mozilla/time_icon.xpm",
                            &p_btnTime, NULL, NULL);
    if( p_btnTime )
    {
        i_height = __MAX( i_height, p_btnTime->height );
        i_width += BTN_SPACE + p_btnTime->width;
    }
    if( !p_btnFullscreen )
        XpmReadFileToImage( p_display, DATA_PATH "/mozilla/fullscreen.xpm",
                            &p_btnFullscreen, NULL, NULL);
    if( p_btnFullscreen )
    {
        i_height = __MAX( i_height, p_btnFullscreen->height );
        i_width += BTN_SPACE + p_btnFullscreen->width;
    }
    if( !p_btnMute )
        XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_max.xpm",
                            &p_btnMute, NULL, NULL);
    if( p_btnMute )
    {
        i_height = __MAX( i_height, p_btnMute->height );
    }
    if( !p_btnUnmute )
        XpmReadFileToImage( p_display, DATA_PATH "/mozilla/volume_mute.xpm",
                            &p_btnUnmute, NULL, NULL);
    if( p_btnUnmute )
    {
        i_height = __MAX( i_height, p_btnUnmute->height );
    }
    i_width += BTN_SPACE + __MAX( p_btnUnmute->width, p_btnMute->width );

    setToolbarSize( i_width, i_height );

    if( !p_btnPlay || !p_btnPause || !p_btnStop || !p_timeline ||
        !p_btnTime || !p_btnFullscreen || !p_btnMute || !p_btnUnmute )
        fprintf(stderr, "Error: some button images not found in %s\n", DATA_PATH );

    /* reset panels position and size */
    /* XXX  use i_width */
    XResizeWindow( p_display, video, window.width, window.height - i_height);
    XMoveWindow( p_display, control, 0, window.height - i_height );
    XResizeWindow( p_display, control, window.width, i_height -1);

    b_toolbar = 1; /* says toolbar is now shown */
    redrawToolbar();
}