Discussion

Left ArrowBack to discussions page
kimberly05kimberly05 Posts: 6 Apprentice
edited June 2017 in Programming
i have a problem in executing it in another case.. only Case 1 is executing other case is not..

Comments

  • StudentStudent Posts: 21 Apprentice
    You have to create a switch function with the cases you want and the identifiers (case 1, case 23, case 41...). And then you have to call that cases, if you don't have case 2, you can't execute it. Do you have a correct code inside the case?
  • kimberly05kimberly05 Posts: 6 Apprentice
    edited June 2017

    robot prog

    var 2 =0

    switch var 2 = 0

    case 1

    do something

    case 2 do something

    end of prog


    this is just a simple program created with a switch command.. in this case only case 1 is excuted and case 2 is not.. but I don't know if the program is correct, it is my first tym using switch command..

  • matthewd92matthewd92 Posts: 958Founding Pro, Tactile Sensor Beta Testers Handy
    Unless var2 = 2 then that case will not execute, in your example case 1 would also not execute since var2 == 0. 

    If you had a default case in your example when var2 equals anything other than 1 or 2 the default case would execute. 

    Hope me this makes sense. Let me know if you need anymore help. 
  • StudentStudent Posts: 21 Apprentice
    Try with something like this (pseudocode):

    Robot program

    option = 'Choose option' (Source: operator)

    Switch option
      Case 1
         do something
      Case 2
         do something
      Default Case
         do something else

    End of program
  • abeachy_HG24abeachy_HG24 Posts: 79 Handy
    Depending on how you want your program to function there's a couple ways to do it. In the example @student gave, the operator will be asked for a number and then based on that number it will run everything in that specific case. If you wanted the robot to go from case to case to all the way through the switch you would want to do something along these lines:

    Robot program

    option = 1
    Switch option
      Case 1
         do something
         option=2
      Case 2
         do something
         option=3
      Case 3
         do something
         option=4
    I use this approach to control the flow of my programs easily. If you were in case one and based off of a certain condition that was met during that case, you could use an if-statement to make the decision on which case to run next. Lets say case 1 is trying to pick a part from a specific location and based on if the robot found the part or not determines what case you want the robot to go next.
    if part_found= True 
        option=2
    if part_found= False
       option=3
    I hope that makes sense and helps out.

Sign In or Register to comment.
Left ArrowBack to discussions page