RobotStudio event

Choose speeddata

Hi,
i'm a mechatronics student and i'm learning robotstudio and rapid programming.
I have a question: i would develop a interface command that allow to choose the speed of the movemente
I have a problem, there are an error when i declare the speeeddata, in particular with the speedata vel_con_pezzo, 
what is the cause? is the variabile  v?
Waiting for a reply,
best regards
Edoardo

<div> ! DEFINIZIONE VELOCITA'
    PERS num v;
    PERS speeddata vel_avuoto:=[200,200,0,0];
    PERS speeddata vel_conpezzo:=[v,v,0,0];

CONST listitem elenco{3} := [ ["","50"], ["","100"],["","200"] ];
    VAR num list_item;
    VAR btnres button_answer;

PROC selezioneVelocita()</div><div>&nbsp; &nbsp; &nbsp; &nbsp; list_item := UIListView (\Result:=button_answer\Header:="Selezione velocita",elenco\Buttons:=btnOKCancel\Icon:=iconInfo\DefaultIndex:=1);</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF button_answer = resOK THEN</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; IF list_item = 1 THEN</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v:=50;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSEIF list_item = 2 THEN</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v:=100;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSEIF list_item = 3 THEN</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; v:=200;</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ENDIF</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ELSE</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ! User has select Cancel</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ENDIF</div><div>&nbsp; &nbsp; ENDPROC</div>

Comments

  • DenisFR
    DenisFR ✭✭✭
    Hello,
    Your PERS variables have to be initialized with a value:
    PERS num v:=0;

  • jeppe
    jeppe
    edited January 2020
    Hi,

    in my understanding you cannot declare data using another data. Instead of trying to declare vel_conpezzo.v_tcp and vel_conpezzo.v_ori using another variable v, you can reassign these values in the program code.

    ! DEFINIZIONE VELOCITA'

    PERS num v;
    PERS speeddata vel_avuoto:=[200,200,0,0];
    PERS speeddata vel_conpezzo:=[0,0,0,0];

    CONST listitem elenco{3}:=[["","50"],["","100"],["","200"]];
    VAR num list_item;
    VAR btnres button_answer;

    PROC selezioneVelocita()
    list_item:=UIListView(\Result:=button_answer\Header:="Selezione velocita",elenco\Buttons:=btnOKCancel\Icon:=iconInfo\DefaultIndex:=1);
    IF button_answer=resOK THEN
    IF list_item=1 THEN
    v:=50;
    ELSEIF list_item=2 THEN
    v:=100;
    ELSEIF list_item=3 THEN
    v:=200;
    ENDIF
    ! reassign two values of vel_conpezzo
    vel_conpezzo.v_tcp:=v;
    vel_conpezzo.v_ori:=v;
    ELSE
    ! User has select Cancel
    ENDIF
    ENDPROC
    hopefully this helps!

    -Jeppe


  • Another way for your consideration is to use UINum or TPReadNum to allow the user to input using the numeric keypad.  Also, there is an instruction SpeedRefresh to allo speeding up or slowing down an ongoing movement if you use it with an interrupt.
    Lee Justice
  • edorobot said:
    Hi,
    i'm a mechatronics student and i'm learning robotstudio and rapid programming.
    I have a question: i would develop a interface command that allow to choose the speed of the movemente
    I have a problem, there are an error when i declare the speeeddata, in particular with the speedata vel_con_pezzo, 
    what is the cause? is the variabile  v?
    Waiting for a reply,
    best regards
    Edoardo

    You can try this, normaly, it works fine in all case ;)

    Please give feedback !

      ! speed definitions
      PERS speeddata vEmpty:=[200,500,1000,5000];
      PERS speeddata vWithPart:=[0,500,1000,5000];

      CONST listitem lstSpeeds{3}:=[["","50"],["","100"],["","200"]];
      VAR num noChoice;
      VAR bool bOk;
      VAR string strValue;
      VAR btnres button_answer;

      PROC selezioneVelocita()
        ! Show the differetns choices
        ! In this case, likelemster has said, you can use UINumEntry with a respond directly as num
        noChoice:=UIListView(\Result:=button_answer
                             \Header:="Please select a speed"
                             ,lstSpeeds
                             \Buttons:=btnOKCancel
                             \Icon:=iconInfo
                             \DefaultIndex:=1);

        IF button_answer=resOK THEN
          ! Convert the text from list to a value
          ! and store this value inside the v_tcp speed.
          bOk:=StrToVal(lstSpeeds{noChoice}.text,vWithPart.v_tcp);
        ELSE
          ! User has select Cancel 
          ! Default value
          vWithPart:=vEmpty;
        ENDIF
      ENDPROC

    Note : I have translate all data in english
  • Hi to all,
    thank you very much for the support.

    Now i would try all replies.
    Have a nice day and good work
    Edoardo