Is it possible to write a routine which only works when the button is pressed?
Khizar
✭
Hey everyone
I would like to ask if it is possible to create a routine that only runs
when a push button is pressed, without the use of a PLC? If this is not
possible, what other options are available to achieve this
functionality?
We are planning to use it for homing purposes, so the operator must keep
pushing the button while homing the robot. If the operator releases the
button while homing, the robot should stop immediately.
i am using IRC5 with serial number 14M-50275.
Any help would be very appreciated.
0
Best Answer
-
Hi Khizar,
That sounds interesting, and could probably work.
If your program is partway through executing a movement and a user presses this button, should it interrupt the program where it is, or wait for the movement to finish?
A trap routine is sometimes called an interrupt routine because it 'interrupts' the program execution to do something else when the program is executing. The interrupt can be caused by a change in digital or analog IO, a change in persistent value, an error etc. The program executes the Trap routine code, then the program pointer goes back to where it was before, depending on the implementation.
This is the best way I can think of. It isn't perfect but here is the example code:MODULE MainModule VAR errnum en_GoHome:= -1; VAR intnum in_Sen1; PERS num n_HomeRegister := 3; VAR bool b_GoHome := FALSE; PERS jointtarget jt_StopPoint:=[[0,0,0,0,0,0],[287.559,2315.43,0,287.559,9E+9,0]]; VAR pathrecid pri_Stopped; PROC Main() ! get an error number BookErrNo en_GoHome; ! Connect trap to routine CONNECT in_Sen1 WITH trp_Sen1; ! Connect trap to digital input ISignalDI sen1, 2, in_Sen1; ! Main execution WHILE TRUE DO ! Movement 1 n_HomeRegister := 1; MoveAbsJ [[0,0,0,0,0,0],[0,0,0,0,9E9,0]], vmax, fine, TWeldGun_5845XL; MoveAbsJ [[0,0,0,0,0,0],[0,3250,0,0,9E9,0]], vmax, fine, TWeldGun_5845XL; ! Movement 2 n_HomeRegister := 2; MoveAbsJ [[0,0,0,0,0,0],[1000,0,0,1000,9E9,0]], vmax, fine, TWeldGun_5845XL; MoveAbsJ [[0,0,0,0,0,0],[1000,3250,0,1000,9E9,0]], vmax, fine, TWeldGun_5845XL; ! Movement 3 n_HomeRegister := 3; MoveAbsJ [[0,0,0,0,0,0],[3000,0,0,3000,9E9,0]], vmax, fine, TWeldGun_5845XL; MoveAbsJ [[0,0,0,0,0,0],[3000,3250,0,3000,9E9,0]], vmax, fine, TWeldGun_5845XL; ENDWHILE ERROR(en_GoHome) ! Check error number TEST ERRNO CASE en_GoHome: ! Error is for homing HomingSequence; ! Execute homing required and repoisiton b_GoHome := FALSE; ! Homing is now done ! Get user to stop pushing button and resume program TPErase; TPWrite "Robot returned to program position."; TPWrite "Let go of button and push play"; Stop; StartMoveRetry; ! Restart Program DEFAULT: RETRY; ENDTEST ENDPROC ! Homing procedure PROC HomingSequence() ! Store current move path StorePath; ! Store stopped location jt_StopPoint := CJointT(); ! Check register and perform movement code required to home robot TEST n_HomeRegister CASE 1: MoveAbsJ [[0,0,0,0,0,0],[0,0,0,0,9E9,0]], vmax, fine, TWeldGun_5845XL; MoveAbsJ [[0,0,0,0,0,0],[6000,0,0,6000,9E9,0]], vmax, fine, TWeldGun_5845XL; CASE 2: MoveAbsJ [[0,0,0,0,0,0],[0,0,0,0,9E9,0]], vmax, fine, TWeldGun_5845XL; MoveAbsJ [[0,0,0,0,0,0],[6000,0,0,6000,9E9,0]], vmax, fine, TWeldGun_5845XL; CASE 3: MoveAbsJ [[0,0,0,0,0,0],[0,0,0,0,9E9,0]], vmax, fine, TWeldGun_5845XL; MoveAbsJ [[0,0,0,0,0,0],[6000,0,0,6000,9E9,0]], vmax, fine, TWeldGun_5845XL; DEFAULT: ! Go straight home MoveAbsJ [[0,0,0,0,0,0],[6000,0,0,6000,9E9,0]], vmax, fine, TWeldGun_5845XL; ENDTEST ! Robot is now home TPErase; TPWrite "Robot is home"; TPWrite "Push Play to return to stop position"; Stop; ! Push Play to restart ! Rewind homing movements TEST n_HomeRegister CASE 1: MoveAbsJ [[0,0,0,0,0,0],[0,0,0,0,9E9,0]], vmax, fine, TWeldGun_5845XL; CASE 2: MoveAbsJ [[0,0,0,0,0,0],[0,0,0,0,9E9,0]], vmax, fine, TWeldGun_5845XL; CASE 3: MoveAbsJ [[0,0,0,0,0,0],[0,0,0,0,9E9,0]], vmax, fine, TWeldGun_5845XL; DEFAULT: ! Went straight home, no movement to unwind ENDTEST ! Move back to stopped pose MoveAbsJ jt_StopPoint, vmax, fine, TWeldGun_5845XL; ! Restore original path RestoPath; ENDPROC ! Trap routine to capture button input TRAP trp_sen1 IF b_GoHome = FALSE THEN IF sen1 = 1 THEN ! Button pushed ! Stop moving, raise the go home error StopMove; b_GoHome := TRUE; RAISE en_GoHome; ELSE ! Button released ! Do Nothing ENDIF ELSE IF sen1 = 1 THEN ! Button pushed IF IsStopMoveAct(\FromMoveTask) THEN ! If the robot is stopped then start it StartMove; ENDIF ELSE ! Button released StopMove; ENDIF ENDIF ! Capture specific error and raise ERROR(en_GoHome) RAISE; ENDTRAP ENDMODULE
The robot performs movements and updates the register. When the button is pushed the program is interrupted with the trap routine which throws an error. The custom error is captured in the Main routine using error handling with long jump. The robot stops where it is, its current position is recorded, and it begins to move towards home. If the user lets go of the button at any point the robot stops, when they push it again it will keep moving until it is home and then it will stop at the home position and display a message. When the user pushed play again the program will resume as long as the button is held and the robot will execute reverse movements to go back to where it stopped. Once it is back where it stopped another message is displayed, the button can be released and if play is pressed the program should resume from where it left off.
Hopefully this example code helps, let me know about any questions, it uses a few techniques but can be expanded for as many movements as needed. The move commands were examples I used for my system.\
Regards,
Harry
0
Answers
-
Hi Khizar,
The code would have to be different depending on how many movements are involved, and if different homing movements are required from different positions, do you have any existing homing code, and how many movements are involved?
It also depends where you want the program pointer to go after the movement is finished or if it is aborted by letting go of the button.
I think you could make use of trap routines to capture the input state changes.
Regards,
Harry0 -
hey harry,Thank you for your reply.I am attempting to work with the registers as the robot has 64 movements. Every time the robot moves, the number of the register changes.For example,IF Home_register =1 GOTO label_1;label_1:The homing code i want to runIt has to perform the homing depending on the position it is in.The program has to start again where it stopped when we released the button.Can you please also explain a bit how the trap routines work?Best regards,
KhizarPost edited by Khizar on0 -
Hi Harry,Thank again for your reply.The program has to be interrupted right away.I will try to write my program this way and will let you know if it works.Best regards,Khizar1
-
Hi Harry,The program you have written worked perfectly. i had to change some stuff here and there as we didn't want the robot to go back to the location it was when we homed.Thanks a lot for you help!Best regards,Khizar0
-
Hi Harry,I have another problem now. Every time my trap completes its task, it generates an error 40229. When I check the events, no other errors are shown to indicate what could be wrong. However, I can start the program again without confirming the error, and it works as intended.This the code i am using:PROC Main()
! get an error number
BookErrNo en_GoHome;
! Connect trap to routine
CONNECT in_Homing WITH trp_DkHoming;
! Connect trap to digital input
ISignalDI di3_Start_Homing, 2, in_Homing;
WHILE TRUE DO
!Wis alle meldingen van de teachpanel
TPErase;
Timeout1:=FALSE;
Timeout2:=FALSE;
Reset do25OnevenRijAangezogen;
Reset do26EvenRijAangezogen;
Reset do27Robot5MagVerplaatsen;
!Programma selectie
TEST giToolCode
CASE 0:
!Voer programma 1 uit, productie van mes met enkele rij zuignappen
!programma01;
!Voer programma 2 uit, productie van vork met enkele rij zuignappen
!programma02;
!Voer programma 3 uit, productie van lepel met enkele rij zuignappen
programma03;
DEFAULT:
TPWrite "Geen of verkeerd programma geselecteerd";
ENDTEST
ENDWHILE
ERROR(en_GoHome)
! Kijk error number
TEST ERRNO
CASE en_GoHome: ! Error voor homing
Homing; ! Execute homing
b_GoHome := FALSE; ! Homing is klaar
TPErase;
ResetRetryCount ;
TPWrite "Robot returned to home position.";
!WaitUntil DI5_Start = 1;
StartMove;
DEFAULT:
RETRY;
ENDTEST
!Einde routine
ENDPROCTRAP trp_DkHoming
IF b_GoHome = FALSE THEN
IF di3_Start_Homing = 1 THEN ! Button pushed
! Stop moving, raise the go home error
StopMove;
ClearPath;
b_GoHome := TRUE;
RAISE en_GoHome;
ELSE ! Button released
! Do Nothing
ENDIF
ELSE
IF di3_Start_Homing = 1 THEN ! Button pushed
IF IsStopMoveAct(\FromMoveTask) THEN ! If the robot is stopped then start it
StartMove;
ENDIF
ELSE ! Button released
StopMove;
ENDIF
ENDIF
! Capture specific error and raise
ERROR (en_GoHome)
RAISE;
ENDTRAPAny idea what could be the reason behind it?Kind regards,Khizar
Post edited by Khizar on0 -
Hi Khizar,I'm glad it started working.It's hard to say, are there any other errors in the log that get registered at the same time?There will likely be an error occurring from within the error handler somewhere that doesn't get dealt with as there is no error handler to deal with it; It is already in the main error handler so there is no error handler in the calling function as there is no calling function for Main.
I think the first issue is that there is no instruction at the end of your error handler as to whether to Retry, Trynext, exit, raise etc. after the 'StartMove' instruction.
If the program was executing inside "proramma03;" or some subroutine, after the Main error handler the program pointer will be back at the "programma03;" line within Main.
If you want it to retry that section you need to add "RETRY;" after the 'StartMove' instruction.
If you want to skip the section and continue in Main you need to add "TRYNEXT;" instead.
If you want to go back to the start of main you can execute ExitCycle; which will move the program pointer back to the start too.If it's not that, there could be an unhandled error in the homing routine, or in the error handler.If there has been no "StopMove" executed before it, it will throw an error that will not be handled.ERROR(en_GoHome)! Kijk error numberTEST ERRNOCASE en_GoHome: ! Error voor homingHoming; ! Execute homingb_GoHome := FALSE; ! Homing is klaarTPErase;ResetRetryCount ;TPWrite "Robot returned to home position.";!WaitUntil DI5_Start = 1;StartMove; !!!!!!!!!!!!
RETRY;DEFAULT:
This can be fixed with:IF IsStopMoveAct(\FromMoveTask) THEN ! If the robot is stopped then start it
StartMove;
ENDIFOr if you don't need it at all you can remove it if the robot is already able to move.
Good Luck,
Harry0 -
Hi Harry,There were no other errors registered at the same time.I have been able to solve the problem. There was an issue with the error handling as I had placed a button within the error handler. This caused the program to stop when I pushed the homing button twice, as it was already in the process of handling the error.Thanks again for your help.Best regards,Khizar
1
Categories
- All Categories
- 5.5K RobotStudio
- 396 UpFeed
- 18 Tutorials
- 13 RobotApps
- 297 PowerPacs
- 405 RobotStudio S4
- 1.8K Developer Tools
- 250 ScreenMaker
- 2.8K Robot Controller
- 316 IRC5
- 61 OmniCore
- 7 RCS (Realistic Controller Simulation)
- 798 RAPID Programming
- AppStudio
- 3 RobotStudio AR Viewer
- 18 Wizard Easy Programming
- 105 Collaborative Robots
- 5 Job listings