RobotStudio event

ABB Speedrefresh in Background Task

Hi guys. 
i got the problem that im not able to use the command "Speedrefresh" in the BG Task.
i always get the error "The task is not configured to control mechanical units".

Task setup on imgur link;
https://imgur.com/a/LZEe555

MODULE RBG_Velocity

  ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - !
  !                                                                                             !
  !            Modul/module:                        RBG_Velocity                                !
  !                                                                                             !
  !            Ersteller/creator:                   3CON-ROB-TEAM-FLEXLINE                      !
  !            Erstellung/creation date:            04.02.2023                                  !
  !            bearbeitet von/ changed by:          3CON-ROB-TEAM-FLEXLINE                      !
  !                                                                                             !
  ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - !

  ! > Routine variable's
  VAR num Velocity_ACT;
  VAR num Velocity_NEED:=100;
  ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - !

  ! PASSIVE WORK FOR ROBOT IN BACKGROUND
  !----------------------------------------------!

  PROC main()

    ! > Checking the interrupt state
    Velocity;

    ! > Waittime for CPU usage reduction
    WaitTime 0.2;

  ENDPROC

  ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - !

  ! SPEEDCHECK FOR ROBOT IN AUTOMODE
  !----------------------------------------------!

  PROC Velocity()

    ! > Setting up the speed if condition is given
  IF (OpMode()=OP_AUTO AND di_0058_3CS_Auto=1 AND do_INT_Autospeed_Free=0) THEN
    Velocity_ACT:=CSpeedOverride();
    IF Velocity_ACT<100 Speedrefresh Velocity_NEED;
  ENDIF
  ENDPROC

  ! - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - !

ENDMODULE


Robotic Software Engineer

Answers

  • Forge_Engineering
    edited February 5
    Hi Braap

    According to the manual, Speedrefresh can only be used in motion tasks that control robot movement.
    You may find your own solution that fits your code structure as I have no idea how it is set up.

    The logic shown in the task here is fairly short and could run in a trap routine in the main task easily. 
    The example code in the manual for speedrefresh shows this:

    <p>VAR intnum time_int;
    VAR num override;
    
    PROC main()
    	CONNECT time_int WITH 
    	speed_refresh;
    	ITimer 0.1, time_int;
    	ISleep time_int;
    	
    	MoveL p1, v100, fine, tool2;
    	! Read current speed override set from FlexPendant
    	override := CSpeedOverride (\CTask);
    	
    	IWatch time_int;
    	MoveL p2, v100, fine, tool2;
    	IDelete time_int;
    	
    	! Reset to FlexPendant old speed override
    	WaitTime 0.5;
    	SpeedRefresh override;
    	
    ENDPROC
    
    TRAP speed_refresh
    	VAR speed_corr;
    	! Analog input signal value from sensor, value 0 ... 10
        speed_corr := (ai_sensor * 10);
    	SpeedRefresh speed_corr;
    ERROR
        IF ERRNO = ERR_SPEED_REFRESH_LIM THEN
            IF speed_corr > 100 speed_corr := 100;
            IF speed_corr < 0 speed_corr := 0;
    	RETRY;
    ENDIF<br></p>

    If you want to have logic in a background task and just do the update in the main task you could set up a PERS speed value that is shared between both tasks and trigger an interrupt in the main task if the value of the PERS speed changes to execute a speedrefresh.

    Good Luck, 

    Harry

  • Hey Harry,
    Thank you for replying. I did a Speedrefresh like u in the past with a trap. But the costumer doesnt want that in the main Task... I'm gonna let you know the solution when im able to get it :D 

    Greets.
    - Chris

    Robotic Software Engineer
  • Hi Braap.

    Unfortunately the Speedrefresh has to be called from the main routine, there is no way to have it in another task.

    You could move a all the speed checking code to a background task and just have the speedrefresh function call in the main task:

    MAIN TASK:
    PERS num DesiredSpeed = 100;
    VAR intnum i_SpeedInterrupt;
    
    PROC Main()
    	CONNECT i_SpeedInterrupt WITH Refresh_Speed;
    	IPers n_DesiredSpeed, i_SpeedInterrupt;
    	
    	! Regular Program Logic 
    	
    	IDelete i_SpeedInterrupt
    ENDPROC
    
    ! Smallest possible trap routine
    TRAP Refresh_Speed
    	speedrefresh n_DesiredSpeed;<br>ENDTRAP

    BACKGROUND TASK:
    PERS num DesiredSpeed;
    
    VAR num Velocity_ACT;
    VAR num Velocity_NEED:=100;
    
    PROC main()
    	! > Checking the interrupt state
    	Velocity;
    	! > Waittime for CPU usage reduction
    	WaitTime 0.2;
    ENDPROC
    
    PROC Velocity()
    	! > Setting up the speed if condition is given
    	IF (OpMode()=OP_AUTO AND di_0058_3CS_Auto=1 AND do_INT_Autospeed_Free=0) THEN
    		Velocity_ACT:=CSpeedOverride();
    		IF Velocity_ACT<100 DesiredSpeed = Velocity_NEED;
    	ENDIF
    ENDPROC

    This way you can keep most logic in a background task and it will only trigger when you actually change the persistent variable. 

    That's about all I can think of, not having trap routines really limits you otherwise.
    If there is a concern about CPU load you can check out the display in RobotStudio under properties -> Device Browser:
    https://imgur.com/a/1QEoUuT
    It might help you monitor the difference at idle.

    Let me know if you find a better way,
    Good Luck, 

    Harry