Shop OBEX P1 Docs P2 Docs Learn Events
Say It generated code faulty? — Parallax Forums

Say It generated code faulty?

MiltosMiltos Posts: 16
edited 2011-10-23 05:46 in BASIC Stamp
I've just generated the portion of code underneath with the Say It module:
VR_Action:
  DEBUG "got ", DEC VRCOMMAND
  SELECT VRGROUP
    CASE GROUP_0
      SELECT VRCOMMAND
        CASE G0_BOE
        PAUSE 0 '-- write your code here
      ENDSELECT
    CASE GROUP_1
      SELECT VRCOMMAND
        CASE G1_FORWARD
         PAUSE 0 '-- write your code here
        CASE G1_BACKWARD
         PAUSE 0 '-- write your code here
        CASE G1_RIGHT
         PAUSE 0 '-- write your code here
        CASE G1_LEFT
         PAUSE 0 '-- write your code here
        CASE G1_STOP
         PAUSE 0 '-- write your code here
      ENDSELECT
  ENDSELECT
  RETURN

I don't know why but only the first group of i.e CASE G0_BOE is executed. The code ignores all other cases. Am I doing sth wrong?

Comments

  • graffixgraffix Posts: 389
    edited 2011-10-21 14:04
    I started a similar thread see if you can find it,let me know how it goes.finding it and if it was helpful
    Sorry I'm away from my pc
  • GadgetmanGadgetman Posts: 2,436
    edited 2011-10-21 14:27
    Please ,use the [_C_O_D_E] tags before and after your code...
    VR_Action:
      DEBUG "got ", DEC VRCOMMAND
      SELECT VRGROUP
        CASE GROUP_0
          SELECT VRCOMMAND
            CASE G0_BOE
            PAUSE 0 '-- write your code here
          ENDSELECT
        CASE GROUP_1
          SELECT VRCOMMAND
            CASE G1_FORWARD
             PAUSE 0 '-- write your code here
            CASE G1_BACKWARD
             PAUSE 0 '-- write your code here
            CASE G1_RIGHT
             PAUSE 0 '-- write your code here
            CASE G1_LEFT
             PAUSE 0 '-- write your code here
            CASE G1_STOP
             PAUSE 0 '-- write your code here
          ENDSELECT
      ENDSELECT
      RETURN
    

    See how much more readable your code is?

    Anyway, your 'problem' is that you have a set of nested CASE statements. The first, working with the VRGROUP variable splits the program in TWO blocks, and only one of those can be executed.
    (GROUP_0 or GROUP_1 )
  • MiltosMiltos Posts: 16
    edited 2011-10-21 23:15
    The code is indeed readable. I knew that I'v got two nested groups ...but the first group is the triggering event i.e BOE or Robot anyhow. How can I have only one group with all this commands?
  • GadgetmanGadgetman Posts: 2,436
    edited 2011-10-22 02:12
    Why don't you tell us exactly what you want the program to do?

    Drawing a flow diagram can also help.
  • MiltosMiltos Posts: 16
    edited 2011-10-22 05:02
    OK,,,I want to use the word BOE as a trigger and then boe bot to execute simple commands like FORWAD-BACKWORD-LEFT-RIGHT etc. Thanks...
  • GadgetmanGadgetman Posts: 2,436
    edited 2011-10-22 08:15
    So, what you want is something like this:
    vars...
    Lots of other code...
    
      IF SpokenWord = "BOE" 
        CASE
          First_case
          Second_case
          Third_case
          ...
          Last_case
      ELSE - Not BOE...
      ENDIF
    

    Sorry that I can't write more clearly, but I think it's something like this you want...
    (I haven't programmed a BS2 in a couple of years... )

    It always helps to write your program in 'pseudocode' first, then transfer it to 'proper' code afterwards.
    Another thing I like to do is to print the code, then use a couple of underliners, draw large '[', starting at the beginning of the IF/CASE/DO/Whatever 'Flow control' command, towards the margin, down, and out to the ENDIF/ENDSELECT and so on. With another line out to the start of every ELSE/Select, you can see more clearly what is and isnt executed when a certain condition exists or not.
  • MiltosMiltos Posts: 16
    edited 2011-10-22 11:46
    VR_Action:
      DEBUG "got ", DEC VRCOMMAND
      SELECT VRGROUP
        CASE GROUP_0
          SELECT VRCOMMAND
            CASE G0_BOE
             PAUSE 0
             GOSUB LED_ON
            CASE G1_FORWARD
             PAUSE 0
             GOSUB FORWARD
            CASE G1_BACKWARD
             PAUSE 0
             GOSUB BACKWARD
            CASE G1_SPIN_RIGHT
             PAUSE 0
             GOSUB  SPIN_RIGHT
            CASE G1_SPIN_LEFT
             PAUSE 0
             GOSUB SPIN_LEFT
            CASE G1_TURN_RIGHT
             PAUSE 0
             GOSUB TURN_RIGHT
            CASE G1_TURN_LEFT
             PAUSE 0
             GOSUB TURN_LEFT
           ENDSELECT
        CASE GROUP_1
          PAUSE 0
        ENDSELECT
      RETURN
    
    
    
    
    LED_ON:
     FOR counter=1 TO 10
      HIGH 10
      PAUSE 500
      LOW 10
      PAUSE 500
    NEXT
    
    
    
    
    FORWARD:
      'DEBUG CR, "Robot Forward"
      FOR counter = 1 TO 50
        PULSOUT LServo, 1000
        PULSOUT RServo, 500
        PAUSE 20
      NEXT
      RETURN
    
    
    BACKWARD:
      'DEBUG CR, "Robot Backward"
      FOR counter = 1 TO 50
        PULSOUT LServo, 500
        PULSOUT RServo, 1000
        PAUSE 20
      NEXT
      RETURN
    
    
    SPIN_RIGHT:
      'DEBUG CR, "Robot Spin right"
      FOR counter = 1 TO 50
        PULSOUT LServo, 1000
        PULSOUT RServo, 1000
        PAUSE 20
      NEXT
      RETURN
    
    
    SPIN_LEFT:
      'DEBUG CR, "Robot Spin left"
      FOR counter = 1 TO 50
        PULSOUT LServo, 500
        PULSOUT RServo, 500
        PAUSE 20
      NEXT
      RETURN
    
    
    TURN_LEFT:
      'DEBUG CR, "Robot Turn Left"
      FOR counter = 1 TO 85
        PULSOUT LServo, 750
        PULSOUT RServo, 500
        PAUSE 20
      NEXT
      RETURN
    
    
    TURN_RIGHT:
      'DEBUG CR, "Robot Turn Right"
      FOR counter = 1 TO 85
        PULSOUT LServo, 1000
        PULSOUT RServo, 750
        PAUSE 20
      NEXT
      RETURN
    

    This is the portion of the code, I am talking about. Unfortunately only the command BOE turns the LED on (is executed). All the rest (FORWARD, BACKWARD, TURN_LEFT etc) are ignored...
    Thanks for your help anyway!
  • xanatosxanatos Posts: 1,120
    edited 2011-10-22 17:57
    Hi there,

    Sounds like you need to use the BOE word to change the GROUP from 0 to 1. This is what I did with my Speaking, Voice-Recognizing Home Automation System. See Voice Recognition code from my project below. Saying "Computer" changes the code vrom VRGROUP10 to VRGROUP1 - meaning it stops listening for Computer once it hears it and starts listening for teh commands to actually do stuff. Here's the code:
    VR_Action:
      DEBUG DEC VRCOMMAND
      SELECT VRGROUP
        CASE GROUP_0
          SELECT VRCOMMAND
            CASE G0_COMPUTER
             PAUSE 0
             HIGH VRLED
             GOSUB Listen_Tone     ' << This is just a place where I make it chirp at me to let me know it heard my wake-up command.
             VRGROUP = 1           ' <<<<<<<<<<  Here's the place you change to VRGROUP 1 so it starts listening for commands.
          ENDSELECT
        CASE GROUP_1
          SELECT VRCOMMAND
            CASE G1_OUTSIDE_WATER_ON
             PAUSE 0
             state = 1
             s1 = state
             cmd = 2
             GOSUB Bank_Build
            CASE G1_OUTSIDE_WATER_OFF
             PAUSE 0
             state = 0
             s1 = state
             cmd = 2
             GOSUB Bank_Build
            CASE G1_OUT_PEAK_LIGHT_ON
             PAUSE 0
             state = 1
             s2 = state
             cmd = 3
             GOSUB Bank_Build
            CASE G1_OUT_PEAK_LIGHT_OFF
             PAUSE 0
             state = 0
             s2 = state
             cmd = 3
             GOSUB Bank_Build
            CASE G1_SECURITY_LIGHT_ON
             PAUSE 0
             state = 1
             s3 = state
             cmd = 4
             GOSUB Bank_Build
            CASE G1_SECURITY_LIGHT_OFF
             PAUSE 0
             state = 0
             s3 = state
             cmd = 4
             GOSUB Bank_Build
            CASE G1_TABLE_LIGHT_ON
             PAUSE 0
             state = 1
             s4 = state
             cmd = 5
             GOSUB Bank_Build
            CASE G1_TABLE_LIGHT_OFF
             PAUSE 0
             state = 0
             s4 = state
             cmd = 6
             GOSUB Bank_Build
            CASE G1_ENT_CENTER_ON
             PAUSE 0
             state = 1
             s5 = state
             cmd = 6
             GOSUB Bank_Build
            CASE G1_ENT_CENTER_OFF
             PAUSE 0
             state = 0
             s5 = state
             cmd = 6
             GOSUB Bank_Build
            CASE G1_LANDSCP_LIGHTING_ON
             PAUSE 0
             state = 1
             s6 = state
             cmd = 7
             GOSUB Bank_Build
            CASE G1_LANDSCP_LIGHTING_OFF
             PAUSE 0
             state = 0
             s6 = state
             cmd = 7
             GOSUB Bank_Build
            CASE G1_WHAT_TIME_IS_IT
             PAUSE 0
             GOSUB Get_Time
             GOSUB Show_Time
             PUT Speak, 102
             RUN SG
            CASE G1_TEMPERATURE
             PAUSE 0
             GOSUB Get_Temp
             GOSUB Show_Temp
             PUT Speak, 103
             RUN SG
            CASE G1_WHAT_DAY_IS_TODAY
             PAUSE 0
             GOSUB Get_Time
             GOSUB Show_Time
             PUT Speak, 101
             RUN SG
          ENDSELECT
        CASE GROUP_16
          SELECT VRCOMMAND
            CASE G16_XANATOS_ALPHA_ONE
             PAUSE 0
             cmd = 40
             RUN SG
          ENDSELECT
      ENDSELECT
      RETURN
    

    Let me know if that helps. This is just a piece I have as a subroutine in my full program. Search for that Speaking, Voice-Recognizing Home Automation System thread to see FAR more details...

    Here's your code with the requisite line included:
    VR_Action:
      DEBUG "got ", DEC VRCOMMAND
      SELECT VRGROUP
        CASE GROUP_0
          SELECT VRCOMMAND
            CASE G0_BOE
            PAUSE 0 '-- write your code here
            VRGROUP = 1     ' <<<<<<<<<<<<<<<<<<<<<<<<<<  Here's your group switch...
          ENDSELECT
        CASE GROUP_1
          SELECT VRCOMMAND
            CASE G1_FORWARD
             PAUSE 0 '-- write your code here
            CASE G1_BACKWARD
             PAUSE 0 '-- write your code here
            CASE G1_RIGHT
             PAUSE 0 '-- write your code here
            CASE G1_LEFT
             PAUSE 0 '-- write your code here
            CASE G1_STOP
             PAUSE 0 '-- write your code here
          ENDSELECT
      ENDSELECT
      RETURN
    


    Good luck,

    Dave
  • MiltosMiltos Posts: 16
    edited 2011-10-23 01:55
    Dave, thanks...

    I will make the change from GROUP 0 to GROUP1 (i.e VRGROUP=1) and I will let you know...Thanks again!
  • MiltosMiltos Posts: 16
    edited 2011-10-23 03:06
    Yes it works, indeed!!! The switch VRGROUP=1 inside the first GROUP (i.e GROUP_0) did the trick... Thanks again!!!
  • xanatosxanatos Posts: 1,120
    edited 2011-10-23 05:46
    Glad I could help!!!
Sign In or Register to comment.