// Copyright (C) 2007  Interdepartmental Research Center "E. Piaggio", University of Pisa
//
// This file is part of RTSS, the Robotics Toolbox for Scilab/Scicos.
//
// RTSS is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// RTSS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with RTSS; if not, write to the Free Software
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA



function rt_drivebotcb1(name)
// File name:       rt_drivebotcb1.sci
//
// Function:        rt_drivebotcb1
//
// Description:     callback for the slider-styled uicontrol of the GUI generated by
//                  rt_drivebot() function
//
// Annotations:     this code is a Scilab port of corresponding function in the
//                  Robotics Toolbox for MATLAB(R) written by Peter I. Corke.
//
// References:      Robotics Toolbox for MATLAB(R), robot7.1/drivebot.m
//
// Author:          Matteo Morelli, I.R.C. "E. Piaggio", University of Pisa
//
// Date:            April 2007
//
// $LastChangedDate: 2007-10-05 23:28:34 +0200(ven, 05 ott 2007) $

    // graphical callback function

    tol = 1e-10;
    // who is the caller?
    obj = findobj("Tag", name);   // because i'm here, it does exist surely
    fig = get(obj, "Parent");

    rh = rt_findtag(name);
    ud = rh(1).user_data;
    rr = ud(2);
    n = rr.n;
    q = [];

    gui_ud = evstr(get(obj, "Userdata"));
    scale = gui_ud(1:n);
    escale = gui_ud(n+1:2*n);
    rplot_id = gui_ud($);

    // get value from sliders
    for j = 1:rr.n,
        objslider_j = findobj("Tag", "hslider" + sci2exp(j) + "_" + sci2exp(fig));
        sli_val = get(objslider_j, "Value");
        if abs(sli_val) < tol then
            q(j) = 0;
        else
            q(j) = sli_val/scale(j);
        end
        objedit_j = findobj("Tag", "hedit" + sci2exp(j) + "_" + sci2exp(fig));
        set(objedit_j, "String", sci2exp(escale(j)*q(j)));
    end

    // update plot
    scf(rplot_id);
    rt_plot(rr, q.');
    show_pixmap();

    t6 = rt_fkine(rr, q);
    for i = 1:3,
        objxyza1 = findobj("Tag", "hxyzatext" + sci2exp(i) + "1_" + sci2exp(fig));
        set(objxyza1, "String", sci2exp(t6(i,4)));
        objxyza2 = findobj("Tag", "hxyzatext" + sci2exp(i) + "2_" + sci2exp(fig));
        set(objxyza2, "String", sci2exp(t6(i,3)));
    end

endfunction
