Asked — Edited

Help With Script Again

Very simple logic, just don't know the commands in ARC... Just added a maxbotics analog distance sensor. It works in ARC. What I would like is when the distance is equal to or less than 50 speak out the ezb. I set up an analog port and I'm trying to use the adc wait command, from there? Thanks Chris


ARC Pro

Upgrade to ARC Pro

Don't limit your robot's potential – subscribe to ARC Pro and transform it into a dynamic, intelligent machine.

PRO
Synthiam
#1  

It does help to provide existing code that you have written so we can help build off of it. Could you paste your current code please? Thanks!

#2  

All I have so far is adc_wait(adc7,lower,50)

Im not sure how to add an if command say something out ezb speaker.

#3  

OK so I tried again.... how do I copy and paste what ive done? My code is this...

IF(ADC7,lower,50) SayEZB " I have detected something in my path " EndIf

It comes up with an error on line 1. Says missing quotes or invalid expression.

                                       Thanks   Chris
#4  

Your syntax is incorrect... The code doesn't make sense , but it should run... The if statement is redundant... meaning the if statement isn't needed because the code will continue only if the ADC_Wait returns above 50 ...


ADC_Wait(ADC7, HIGHER, 50)

$x=getadc(adc7)
IF($x>50)
SayEZB (" I have detected something in my path ")
EndIf


#5  

This is all you really need....



ADC_Wait(ADC7, HIGHER, 50) #the script stops here until the value exceeds 50

SayEZB (" I have detected something in my path ")


#6  

I agree with you to a certain extent... as we move closer to the sensor the number goes down not up. So what I am looking for is when something is detected closer. But I think I can modify what you did as an example. I will try , and then post back. Thanks Richard R

#7  

So modify it then...


ADC_Wait(ADC7, Lower, 50) #value lower than 50 or whatever value you want

SayEZB (" I have detected something in my path ")


#8  

Sorry Richard R , not working. I need to make sure i'm doing it right though. I just pulled out a script control and scripted inside it.

#9  

Is there a way to make it loop? To make it work I have to sit and push start script. I would like to have it sense an object and say it automatically, not just once. If I walk in front of the robot I want to say it, then when I get out of its path , and return to its path say it again. I will build upon this with eventually stopping the robot.

#11  

it works only when I push the start script button for me. The script runs only once.

#12  

Check my syntax as I am doing this from memory.. you need to check what values the sensor is feeding back before you can use it in a script...


$x=0
$quit=1

RepeatUntil($quit=0)

$x=getadc(adc7)

print($x)  #see what values the sensor is giving


sleep(50)

endrepeatuntil


#13  

I changed the code above to repeat forever so you can use it to see what values the sensor is continuing to put out...

Once you figure out what the sensor is reading and value you need you can then modify the code to actually use in your project...

#14  

Hey Richard the above code does run forever like you said. But when I add an If statement ($x) < 50) I get an error, Something about nesting. Ive had enough for tonight. Thanks for your help

#15  

Hey Kamaroman68 sorry to disturb but the reason why your getting an error message about nesting is because ($x)<50) is because you only have one pair of parentheses and a leftover one. When they say "nesting" they're saying your parentheses do not match up. I 'll give an example: (5+(3+2) if this was in a code I would get a nesting error because my parenthesis don't match up. I suggest reviewing Richard's previous example.

                                                           Happy building,
                                                                    Asher
#16  

This code should work... again, check my syntax before running....



$x=0
$quit=1

RepeatUntil($quit=0)

$x=getadc(adc7)

if($x&lt;50)  #This part will only run if $x is less than 50

SayWait(&quot;Object near&quot;)

endif

print($x)  #see what values the sensor is giving

sleep(50)

EndRepeatUntil


This simpler version should work too...


:top

ADC_Wait(ADC7,LOWER,50,50) 

SayWait(&quot;Object near&quot;)

goto(top)


United Kingdom
#17  

Simply use a repeatwhile(1 > 0) for a forever loop

So;


# Loop forever
RepeatWhile(1 &gt; 0)

  # Wait until ADC value is lower than 50
  ADC_Wait(ADC0, lower, 50)
  
  # Speak through the EZ-B V4
  SayEZB(&quot;I have detected something in my path&quot;)

  # Wait until ADC value is higher than 50 to avoid constant repeats
  ACD_Wait(ADC0, higher, 50)

# Loop back
EndRepeatWhile

You can click the stop button or run a ControlCommand to stop a script so there's no need for an escape variable.

Or, if you wanted the value displayed;


# Loop forever
RepeatWhile(1 &gt; 0)

  # Get the ADC Value
  $Distance = GetADC(ADC0)

  # Print the ADC Value
  Print(&quot;Distance: &quot;+$Distance)

  # Or output to an LCD Display (Code may vary)
  I2CWrite(0,0x27,&quot;TP&quot;,&quot;2&quot;,&quot;0&quot;)
  I2CWrite(0,0x27,&quot;TT&quot;)
  I2CWrite(0,0x27,&quot;Distance: &quot;+$Distance)
  I2CWrite(0,0x27,0)

  # Check the value is lower than 50
  IF($Distance &lt; 50)

    # If it is then speak warning
    SayEZB(&quot;I have detected something in my path&quot;)
  EndIf

  # Reduce processing load and comms
  Sleep(200)
EndRepeatWhile

In the above example you could replace the repeat with a simple :label and Goto()


:begin

  # Get the ADC Value
  $Distance = GetADC(ADC0)

  # Print the ADC Value
  Print(&quot;Distance: &quot;+$Distance)

  # Or output to an LCD Display (Code may vary)
  I2CWrite(0,0x27,&quot;TP&quot;,&quot;2&quot;,&quot;0&quot;)
  I2CWrite(0,0x27,&quot;TT&quot;)
  I2CWrite(0,0x27,&quot;Distance: &quot;+$Distance)
  I2CWrite(0,0x27,0)

  # Check the value is lower than 50
  IF($Distance &lt; 50)

    # If it is then speak warning
    SayEZB(&quot;I have detected something in my path&quot;)
  EndIf

  # Reduce processing load and comms
  Sleep(200)

# Loop back
Goto(begin)

#18  

OK so my saga continues..... at first all I wanted was to speak when an object was detected in its path. But after thinking about this, and already having the movement of the robot scripting in place (sort of) I would like to add to the complications. I looked at Rich's Ping roam script on the cloud but it didn't help much. What I have is one controller ezb4 in the robots head and one down at the drive base. The head board will need to interact with the base board as the head sensors are being used to determine distance to object. So..... I would like the robot to move on voice command, when approaching an object in path stop, say "I have detected an object in my path" Sleep(1000) then ask if it should proceed moving. An answer of yes will allow it to proceed while an answer of no well that's obvious... Any help is appreciated... Chris

United Kingdom
#19  

That's pretty simple. Do you want to be spoon fed or do you want the menu?

When using 2 boards you will need to tell the script commands which board to use (where applicable). This is denoted by the board number before the port i.e. Servo(0.D0, 60) or Servo(1.D0, 60)

The scripts provided so far should be a good base. but change the commands within the IF or after the ADC_Wait.

You want to use WaitForSpeech()

Quote:

WaitForSpeech( timeOut Seconds, phrases )

     Pauses and waits for one of the specified phrases to be spoken.

     Returns the phrase that was spoken.

     Will return timeout if no word is detected in the specified timeout length.

     Example: WaitForSpeech(30, Yes, No)

     Example: $value = WaitForSpeech(30, Yes, No)

and an IF to determine what to do. Check both out in the script manual.