Asked — Edited

Script Help Needed

I am having a little bit of trouble with this script. Everything works until I get to the "if" statement at the left and right sensor. So what it is supposed to do is not allow movement if tracks are disabled which upon startup they are. Once track motors are enabled and the command robot turn left is given the head is to turn left and down, again which it does. But then it never gets to the send serial commands. There is something missing, endif, elseif, end repeat? BTW I troubleshot by commenting out lines of code until figuring out where the problem began. I appreciate the help. Also how do I use code tags on this website?


if($movement = "false")
print("movement prohibited")
SayEzb("my track motors are disabled")
Else 
print("moving")

ControlCommand("Script Manager ", ScriptStart, "Head_Left")
ControlCommand("Script Manager ", ScriptStart, "Head Down")
sleep(500)

if ($leftsensor <60)And ($rightsensor <60)
sleep(500)
SendSerial(D0,38400,1)
SendSerial(D0,38400,255)
Sleep(5000)
SendSerial(D0,38400,0)
ElseIf 
SendSerial(D0,38400,0) 
SayEZB("i have detected something in my path") 
EndIf


ARC Pro

Upgrade to ARC Pro

Get access to the latest features and updates before they're released. You'll have everything that's needed to unleash your robot's potential!

#9  

@faengelm, yes, it should be but it will work the way he has it. The key though is to have an Endif for every If statement.

#10  

How are you guys formatting the posted code?

Thanks Chris

PRO
Synthiam
#11  

Use the tags to format code.

Maybe this is what you want? I "assume" the ENDIF is to be at the end of code because the next IF is comparing to see an object in the path - which i suspect means the robot is moving.

You added an ENDIF for one of the IF conditions, but not the other.


if ($movement = "false")
  
  print("movement prohibited")
  
  SayEzb("my track motors are disabled")
  
ELSE

  print("moving")

  ControlCommand("Script Manager ", ScriptStart, "Head_Left")
  ControlCommand("Script Manager ", ScriptStart, "Head Down")
  
  sleep(500)

  if ($leftsensor <60)And ($rightsensor <60)
  
    sleep(500)
    SendSerial(D0,38400,1)
    SendSerial(D0,38400,255)
    Sleep(5000)
    SendSerial(D0,38400,0)
    
  ELSEif
  
    SendSerial(D0,38400,0)
    SayEZB("i have detected something in my path")
    
  endif

endif

#12  

Guys after further testing this script today I found further issues. Im hoping someone can shed some light on it. What I want is if the "movement = false" I don't want any more of the script to run. What happens is if I say "robot turn left" and the movement is false, it will say "my track motors are disabled" and then the head lowers and looks in appropriate direction and if nothing detected it starts to move. It should NOT move if the track motors are disabled. Thanks guys major headache tonight.

                     Chris  

IF ($movement = "false") print("movement prohibited") SayEzb("my track motors are disabled")

ELSE print("moving") ENDIF

ControlCommand("Script Manager ", ScriptStart, "Head Down") sleep(1500)

$leftsensor = getadc(adc5) $topsensor = getadc(adc7) $rightsensor = getadc(adc6)

IF ($leftsensor <=60)And ($rightsensor <=60) sleep(2500) sendserial(d0,38400,235) sendserial(d0,38400,107) sleep(3000) sendserial(d0,38400,0) ELSE ($leftsensor >=60 Or ($rightsensor >=60) SendSerial(D0,38400,0) SayEZB("i have detected something in my path") ENDIF

ControlCommand("Script Manager ", ScriptStart, "Head_Center")

*** EDIT I need to try DJ's above script. I will try that and get back***

#13  

This doesn't answer your script question, just your question about formatting code.

Unfortunately, I can't type the UBB code, because the forum will format it, so I'll describe it...

Look in the box to the right of the text input window labeled UBB code (it will be under the window if you are on a mobile device or your screen is small).

Next to the word Code is an example...

To format code, type a left open bracket, the word "code" and a right close bracket.

Enter all of your code, then type a left open bracket, a slash, the word code, and a right close bracket.

Quoting is similar, but use the word quote instead of code.

Alan

#14  

Thanks Alan I will try that next time.

Now onto another question regarding DJ's code. What in there is defining $left sensor and $right sensor to there respective adc ports? Thanks again

   Chris
#15  

I believe DJ's code will do what you are looking for

#16  

@kamaroman68 To further what Alan said

Below is an example on how to use code tags

[code #use another closing square bracket after the word code]

#everything between these code tags will be black #example code can be anything say("I am a robot")

[/code #use another closing square bracket after /code]

DJ's code altered a little...


if ($movement = &quot;false&quot;)
  
  print(&quot;movement prohibited&quot;)
  
  SayEzb(&quot;my track motors are disabled&quot;)
  
ELSE

  print(&quot;moving&quot;)

  ControlCommand(&quot;Script Manager &quot;, ScriptStart, &quot;Head_Left&quot;)
  ControlCommand(&quot;Script Manager &quot;, ScriptStart, &quot;Head Down&quot;)

  
 sleep(250) #play with the value here

$leftsensor = getadc(adc5)
$topsensor = getadc(adc7)
$rightsensor = getadc(adc6)

sleep(250) #a sleep here may not be needed

  if ($leftsensor &lt;60)And ($rightsensor &lt;60)
  
    sleep(500)
    SendSerial(D0,38400,1)
    SendSerial(D0,38400,255)
    Sleep(5000)
    SendSerial(D0,38400,0)
    
  ELSE
  
    SendSerial(D0,38400,0)
    SayEZB(&quot;i have detected something in my path&quot;)
    
  endif

endif