Previous line or next line of the program


I want the program this :

If digital_input[0] == On
Then go o the previous line of the program
If digital_input[1] == On
Then go to the next line of the program

I have 2 different inputs but I don’t know how to order the robot to go to the next or previous line of the program.

Can someone help me please ?

Best regards

Could you not change it to a subprograms call instead of using a program line? Something like:


# do_something_previous
if digital_input[0] == On:
     # do_something_previous
if digital_input[1] == On:
     # do_something_next


def subProgram_1:
     # do_something_previous
     # do_something_next

# main
if digital_input[0]:
if digital_input[1]:

Thanks for the answer but this doesn’t work with my program ;

I have several actions that follow one another and I want to be able to go to the previous action as well as the next action at any time.

For example I am at action 3 but I want to return to action 2 and again to action 1 and then move on to action 2.

I can’t permanently create subprograms for every combination.

Best regards

Check this post because it is a very similar question also posted yesterday: How to jump to a certain line in the program via Script or Assignment - #2 by eric.feldmann

If you place all the logic for each “action” as a subprogram like @cgs suggests, I don’t fully see why combinations matter. That’s the benefit of having single purpose functions, is that you can call them whenever, and trust the result of their actions.

There’s a few other simple, key design decisions you’ll have to make. Do you want the inputs to be able to interrupt each other? Do you want to latch the inputs and service their functions only after the previous action has finished? Should it always be sequential, such that if action 1 is called, action 2 and 3 execute in order?

Not knowing your specific use case, I’ll just give you an example of latching the action request, and sequentially advancing through them:


There’s some obvious problems/differences with this example. Notably, I am using digital outputs as my flag instead of inputs. This is just so I can manually trigger them on my simulator for testing. I also am not debouncing the trigger signal, so the program will constantly loop with whatever output you turn on.

Regardless of implementation, you will likely need a Thread to monitor the inputs and assign flagging variables appropriately, and subprograms to contain all the necessary logic that should happen. In this way, your entire program could simply be any combination of action_X() calls. Just remember the function will always return back to where it was called initially.