Hi Guys!
Recently I've been venturing into the world of KAREL language and tested on small applications.
I make it very clear that I am in the process of learning this language. Well, I've been trying to store a value in R [x] registers using commands like SET_INT_REG (register_no, int_value, status) as well as triggering digital outputs using the SET_PORT_VAL (port_type, port_no, value, status) command via the KAREL interface. My program did not have problems but also did not work 100% as I would like.
I would like to know where or what is missing so that I can store a response in an external variable, eg an R [x] or trigger a DOUT [x] output.
Thank you if you can support me.
------------------------------------------------------------------------------------------------------------
PROGRAM QUESTION
%COMMENT = 'Question Proc V1.0'
%NOLOCKGROUP
%NOPAUSE = ERROR + COMMAND + TPENABLE
CONST
io_all = 0 -- Any I/O type
io_din = 1 -- Digital input
io_dout = 2 -- Digital output
io_anin = 3 -- Analog input
io_anout = 4 -- Analog output
io_tool = 5 -- Tool output
io_plcin = 6 -- PLC input
io_plcout = 7 -- PLC output
io_rdi = 8 -- Robot digital input
io_rdo = 9 -- Robot digital output
io_brake_out = 10 -- Brake output
io_opin = 11 -- operator panels input
io_opout = 12 -- operator panels output
io_sopin = 11 -- Same as io_opin
io_sopout = 12 -- Same as io_sopout
io_estop = 13 -- Emergency stop
io_tpin = 14 -- Teach pendant digital input
io_tpout = 15 -- Teach pendant digital output
io_wdi = 16 -- weld inputs
io_wdo = 17 -- weld outputs
io_gpin = 18 -- Grouped inputs
io_gpout = 19 -- Grouped outputs
io_uopin = 20 -- User operator's panel input
io_uopout = 21 -- User operator's panel output
io_ldin = 22 -- laser DIN
io_ldout = 23 -- laser DOUT
io_lain = 24 -- laser AIN
io_laout = 25 -- laser AOUT
io_wstk_in = 26 -- weld stick input
io_wstk_out = 27 -- weld stick output
io_mem_boo = 28 -- memory image boolean's
io_mem_num = 29 -- memory image din's
io_dummy_boo = 30 -- dummy boolean port type
io_dummy_num = 31 -- dummy numeric port type
io_proc_axes = 32
io_iopin = 33 -- Internal operator's panel input
io_iopout = 34 -- Internal operator's panel output
io_flag = 35 -- Flag (F[ ])
io_marker = 36 -- Marker (M[ ])
------------------------
max_log_port = 36
------------------------
-- physical only
io_keep_rly = 41 -- Backuped internal relay
io_rly = 42 -- No backuped internal relay
io_keep_reg = 43 -- Backuped internal register
io_reg = 44 -- No backuped internal register
------------------------
max_phy_port = 44
------------------------
io_min_type = 1 -- same as io_din
io_max_type = 44 -- same as max_log_port
-----------------
VAR
STATUS, data_type, int_value, conv_type,InputVal, i: INTEGER
step_val : INTEGER
ExitLoop:BOOLEAN
real_value: REAL -- Used only for the GET_TPE_PRM command
str_value : STRING[32] -- Used only for the GET_TPE_PRM command
to_prog : STRING[32] -- TP program name to be copied TO
RegNr,Reg_Value :INTEGER -- dynamically displayed variable
real_v:REAL
port_no:INTEGER
BEGIN
--
IF UNINIT(RegNr) THEN RegNr = 0 ; ENDIF
IF UNINIT(Reg_Value) THEN Reg_Value = 0 ; ENDIF
IF UNINIT(port_no) THEN port_no = 0 ; ENDIF
--
--Get the first argument passed, the type of conversion to do.
--Should be an int from 1-50.
GET_TPE_PRM(1, data_type, int_value, real_value, str_value, STATUS)
--Validate what was passed.
IF (data_type=1) AND (STATUS=0) THEN
--Argument is an int.
IF (int_value<1) OR (int_value>50) THEN
--Invalid argument 2, not in range.
--Clear and home user screen.
WRITE(CHR(128))
WRITE(CHR(137))
--Force the user screen.
FORCE_SPMENU(TP_PANEL , SPI_TPUSER , 1)
WRITE('Invalid Argument 1. Must be an integer.',CR)
WRITE('Valid Arguments are: 1 to 50',CR)
ABORT
ENDIF
--Argument 1 is ok.
conv_type=int_value
ELSE
--Invalid argument 2, not an integer, or the GET_TPE_PRM failed.
--Clear and home user screen.
WRITE(CHR(128))
WRITE(CHR(137))
--Force the user screen.
FORCE_SPMENU(TP_PANEL , SPI_TPUSER , 1)
WRITE('Invalid Argument 1. Must be an integer.',CR)
WRITE('Valid Arguments are: 1 to 50',CR)
ABORT
ENDIF
---
IF (conv_type = 1) THEN
REPEAT
--Clear and home user screen.
WRITE(CHR(128))
WRITE(CHR(137))
--Force the user screen.
FORCE_SPMENU(TP_PANEL , SPI_TPUSER , 1)
--Show Message Selected
WRITE('-------------------------------------',CR)
WRITE ('> Robot fuera de HOME <',CR)
WRITE ('-------------------------------------',CR)
WRITE ('!Elige una Opción!',CR)
WRITE('1 --> Regresar a HOME',CR)
WRITE('2 --> Regresar manualmente',CR)
WRITE('-------------------------------------',CR)
READ(InputVal)
IF (InputVal = 1) THEN
Reg_Value = 1
RegNr = 25
port_no = 1
SET_PORT_VAL (io_flag, 1, 1, STATUS)
--Clear and home user screen.
WRITE(CHR(128))
WRITE(CHR(137))
WRITE('Realizacion de regreso',CR)
WRITE('automatico a la posicion',CR)
SET_INT_REG(RegNr, REG_VALUE, STATUS) -- <-------------- * (Does not change register value) *
ExitLoop = TRUE
ELSE
IF (InputVal = 2) THEN
Reg_Value = 2
RegNr = 25
port_no = 0
SET_PORT_VAL (io_flag,1, 1, STATUS) -- <-------------- * (Does not change Output value) *
WRITE(CHR(128))
WRITE(CHR(137))
WRITE('Realizacion de regreso',CR)
WRITE('automatico a la posicion',CR)
SET_INT_REG(RegNr, Reg_Value, STATUS)
ExitLoop = TRUE
ENDIF
ENDIF
UNTIL ExitLoop
------------------------------
ELSE
IF (conv_type = 2) THEN
ExitLoop = FALSE
REPEAT
--Clear and home user screen.
WRITE(CHR(128))
WRITE(CHR(137))
--Force the user screen.
FORCE_SPMENU(TP_PANEL , SPI_TPUSER , 1)
--Show Message Selected
WRITE('-------------------------------------',CR)
WRITE ('Falla del sistema de succion',CR)
WRITE ('Verifique el problema y ',CR)
WRITE ('presione la opcion (1)',CR)
WRITE('-------------------------------------',CR)
WRITE('1 --> Intentar nuevamente',CR)
WRITE('-------------------------------------',CR)
READ(InputVal)
IF (InputVal = 1) THEN
ExitLoop = TRUE
ENDIF
UNTIL ExitLoop
------------------------------
ELSE
IF (conv_type = 3) THEN
-- NEXT QUESTION
ENDIF
ENDIF
ENDIF
END QUESTION