Universal Robots Forum

get_MaxSwitchCase

Is there a function available from the script commands to get the maximum switch case value?

Hi @smilchuck

I’m not sure I understand your question? There is no URScript function for returning the maxximum “value” from a switch case method, as a switch/case statement is a block of code, not a variable/string that can be passed as an argument to a function.

What is it that you are trying to acheive that requires this functionality? I am sure there will be a work around that you can implement.

As @sam.hilton mentioned you can’t get the maximum ‘value’ for a switch case but if you are concerned about a case not being handled the default case will handle any case not setup.

Sam, thank you for the reply.
We use the switch case to create a state machine in some of our specific applications.
At the end of the main program, we compare our current state to the switch max and either increment to the next case (<max) or loop to the beginning (>= max) .
Currently this logic flow has worked well, it just requires manually updating the switch comparison value in the program.

I was just requesting if a variable existed that I was perhaps unaware of that would provide the maximum value of the current switch case.

Roman, thank you for the reply.
I understand the answer is no that the functionality I am inquiring about does not exist.

I think I understand what you’re trying to do, so allow me to try and help. You may be able to acheive the functionality you require using a this sort of srtucture:

global current_state = 0    <- these 2 lines at the top of the script file. It declares the variables so they can be used later.
global maximum_state = 6    <- whatever happens to be the maximum case value, save it here. It will be referenced at a later date.

...rest of program   

switch(state)
    case(state_1)
        current_state = state    <- make sure to save "state" to "current_state"
        ...do a thing
    case(state_2)
        current_state = state    <- make sure to do it for every case
        ...do another thing
    .
    .
    .
    case(state)
        current_state = state    <- in this case, state is equal to max_state.
        ... do max state things

if (current_state == max_state)
    ... set variable that conttrols state back to beginning value.
else
    ... increment state value.

I hope this template is useful for you. I am not sure if the syntax for the script is correct, as it’s been a while since I wrote URScript.

As an alternative you could also set a boolean variable true in the maximum case and perform your loop based on this varialble. You could also do this if you are using Polyscope’s built in switch/case functionality, as well as oding it at a URScript level. Actually, now I’ve written it, I suspect this would be the better approach regardless!