<head><version>2.44.11</version></head>
<VBScript_Program>
  <tab_size_index>1</tab_size_index>
  <script>              ' Script to provide RobotRealm control over Rovio movement.  Inputs are the variables 'command' and 'intDistance'

       '   'command' = move, turn or stop

       '   'intDistance' = Distance in inches or angle in degrees

       '   Output is variable 'move' 

       '       0 = stop

       '       1 = Drive Forward

       '       2 = Drive Back

       '       5 = Turn Left

       '       6 = Turn Right

       ' The primary method of motor control is through use of timed movements.  Slightly more accurate results when timed

       '    in this script than when timed in a calling program.

       ' It would be nice to be able to use encoder ticks for feedback but they are very inaccurate.  

       '   Perhaps there would be an improvement if RoboRealm sampled the tick encoder at a higher rate??

       ' The NorthStar 'gps' does provide fairly accurate feedback and is especially useful when turning.

       '   Unfortunately, it may not be visible everywhere.  Possible future ennancement:  Automatically enable 

       '   Northstar feedback based on its signal strength.

       

       EnableTheta = 0    ' set to 1 if Northstar 'gps' is visible

       EnableEncoder = 0    ' set to 1 if we want to use wheel encoder values to correct moves

       If (GetStrVariable("command") = "move") Then

             MoveTime = ((Abs(GetVariable("intDistance")) - 0.75) / 12 + 0.3) * 1000  ' may need to adjust for individual Rovio

        ElseIf (GetStrVariable("command") = "turn") Then

             MoveTime = ((Abs(GetVariable("intDistance")) - 0.14) / 145 ) * 1000    ' may need to adjust for individual Rovio

        End If

        SetVariable "MoveTime", MoveTime 



      If (GetStrVariable("command") = "stop") Then

         SetVariable "move", 0

         SetVariable "command", 0

      ElseIf ((GetStrVariable("command") = "move") And (GetVariable("move") = 0)) Then ' For non turning moves, control by timing is probably better than contol using encoder ticks

         SetVariable "status", "start move" 

         If (GetVariable("intDistance") &gt;= 0) Then

           SetVariable "move", 1

         Else

           SetVariable "move", 2

         End If

         SetTimedVariable "move", 0, MoveTime 

         SetTimedVariable "command", 0, MoveTime 

       ElseIf ((GetStrVariable("command") = "turn")And (GetVariable("move") = 0)) Then

          if (EnableEncoder = 1) then 

            EncoderStart = GetVariable("ROVIO_REAR_TICK") 

            SetVariable "EncoderStart ", EncoderStart 

          end if

          if (EnableTheta = 1)  then  

            Destination =  GetFloatVariable("ROVIO_THETA") * 57.296 + GetVariable("intDistance")

            if (Destination &gt; 180) then Destination = 360 - Destination 

            if (Destination &lt; -180) then Destination = 360 + Destination 

            SetVariable "Destination", Destination 

          end if

          If (GetVariable("intDistance") &gt;= 0) Then   'Left Turn

            SetVariable "move", 5

          Else

            SetVariable "move", 6

          End If

          SetVariable "command", 4 '  Reuse 'command' as state machine variable - ugh - rewrite

          SetTimedVariable "move", 0, MoveTime 

       ElseIf ((GetVariable("command") = 4) and (GetVariable("move") = 0) and (EnableTheta = 0) and (EnableEncoder = 0)) Then    ' No Corrections

          SetVariable "command", 0 

       ElseIf ((GetVariable("command") = 4) and (GetVariable("move") = 0) and (EnableTheta = 1)) Then    ' wait for ROVIO_THETA to be updated

          SetVariable "command", 3 

          SetTimedVariable  "command", 2,4000 

       ElseIf ((GetVariable("command") = 4)and (GetVariable("move") = 0) and (EnableEncoder = 1)) Then    ' wait for ROVIO_REAR_TICK to be updated

          SetVariable "command", 3 

          SetTimedVariable  "command", 2,1000 

       ElseIf ((GetVariable("command") = 2)and (GetVariable("move") = 0)) Then    ' Turn correction based on feedback

          if (EnableTheta = 1)  then  

            Orientation = GetFloatVariable("ROVIO_THETA")* 57.296

            CorrectionDistance = Destination - Orientation 

          end if

          if (EnableEncoder = 1) then 

             CorrectionDistance =  GetVariable("intDistance") - (GetVariable("ROVIO_REAR_TICK") - EncoderStart )* 2.25   ' 2.25 empirically measured YMMV, Also need to add corrections for tick rollover

          end if

          if (CorrectionDistance &gt;= 180) then CorrectionDistance = 360 - CorrectionDistance

          if (CorrectionDistance &lt;= -180) then CorrectionDistance = -(360 + CorrectionDistance)

          SetVariable "CorrectionDistance", CorrectionDistance 

          MoveTime2 = ((Abs(CorrectionDistance)  - 0.14) / 145 ) * 1000

          if MoveTime2 &lt; 0 then MoveTime2 = 0

          SetVariable "MoveTime2", MoveTime2 

          If (CorrectionDistance &gt;= 0) Then   'Left Turn

            SetVariable "move", 5

          Else

            SetVariable "move", 6

          End If

          SetTimedVariable "move", 0, MoveTime2 

          SetTimedVariable "command", 0, MoveTime2 

       elseif (GetVariable("move") = 0) And GetVariable("command") &lt;&gt; 4 And GetVariable("command") &lt;&gt; 3 And GetVariable("command") &lt;&gt; 2 then

         SetVariable "command", 0

        End If





</script>
  <filename>.\command.vbs</filename>
  <source_mode>gui</source_mode>
</VBScript_Program>
<WowWee_Rovio>
  <move_map>move</move_map>
  <compression>1</compression>
  <framerate>23</framerate>
  <ip_port>80</ip_port>
  <enhance_image>FALSE</enhance_image>
  <battery_map>battery</battery_map>
  <speed>slow</speed>
  <video_enabled>TRUE</video_enabled>
  <speed_map>speed</speed_map>
  <head_position>13</head_position>
  <ip_address>192.168.10.155</ip_address>
  <is_running>TRUE</is_running>
  <volume>15</volume>
  <brightness>6</brightness>
  <resolution>3</resolution>
  <remember_as_default>TRUE</remember_as_default>
</WowWee_Rovio>
<Display_Variables>
  <display_as_annotation>FALSE</display_as_annotation>
  <font_size_index>2</font_size_index>
  <display_value_only>FALSE</display_value_only>
  <dim_background>TRUE</dim_background>
  <border_color_index>5</border_color_index>
  <northwest>battery
ROVIO_CHARGING
</northwest>
</Display_Variables>
<Fiducial>
  <perspective>255</perspective>
  <max_x_angle>360</max_x_angle>
  <max_angle>30</max_angle>
  <max_y_angle>360</max_y_angle>
  <create_shape_array>TRUE</create_shape_array>
  <monitor_folder>FALSE</monitor_folder>
  <display_coord>FALSE</display_coord>
  <display_filename>TRUE</display_filename>
  <adaptive_threshold>30</adaptive_threshold>
  <matched_color_index>3</matched_color_index>
  <max_confidence>100</max_confidence>
  <min_angle>330</min_angle>
  <sort_array_on_y>FALSE</sort_array_on_y>
  <min_y_angle>0</min_y_angle>
  <font_size_index>2</font_size_index>
  <min_x_angle>0</min_x_angle>
  <base_folder>C:\Program Files\RoboRealm\Fiducials</base_folder>
  <min_contrast>0</min_contrast>
  <display_ry>FALSE</display_ry>
  <display_ty>FALSE</display_ty>
  <display_orientation>FALSE</display_orientation>
  <max_size>1000</max_size>
  <max_contrast>100</max_contrast>
  <display_contrast>FALSE</display_contrast>
  <test_color_index>5</test_color_index>
  <display_scale>FALSE</display_scale>
  <min_confidence>83</min_confidence>
  <sort_array_on_x>FALSE</sort_array_on_x>
  <occurrence_threshold>0</occurrence_threshold>
  <min_size>0</min_size>
  <select_top_blobs>38</select_top_blobs>
  <display_rx>FALSE</display_rx>
  <display_tx>FALSE</display_tx>
  <display_confidence>TRUE</display_confidence>
</Fiducial>
<VBScript_Program>
  <tab_size_index>1</tab_size_index>
  <script>fiducials = GetArrayVariable("FIDUCIALS")

names = GetStrVariable("FIDUCIALS_PATH")



if isArray(fiducials) then

  if ubound(fiducials) &gt; 0 then

    for i=0 to ubound(fiducials)-1 step 17

      nstart = fiducials(i+15)

      nend = fiducials(i+16)

      write "Conf: " &amp; fiducials(i) &amp; "%  Path: " &amp; _

        mid(names, nstart, nend) &amp; vbCRLF

    next

  end if

end if



</script>
  <source_mode>gui</source_mode>
</VBScript_Program>
