United Kingdom
Asked — Edited
Resolved Resolved by Rich!

Searching For Glyphs

Hi guys and galls,

I am writing a script for K9, that depending on which glyph he sees first determines what he does next. now I am taking this step by step to increase my learning of ez script, so the plan is as follows.

When asked to "patrol", he wanders off and looks for glyph 3, then moves on looking for glyph 4, then glyph 2, then back home to glyph 1, with actions at the stops.

Now I have written what I believe to be the code and uploaded to the cloud, but, I just want a sense check to see if this is the right direction, or is there a better way to do this.

Thanks in advance for your patience whilst I am learning :-)


ARC Pro

Upgrade to ARC Pro

Experience the transformation – subscribe to Synthiam ARC Pro and watch your robot evolve into a marvel of innovation and intelligence.

Trinidad/Tobago
#1  

@mgodsell1973 Found it:)

you may want to use


ControlCommand("Camera", CameraStart)
ControlCommand("Camera", CameraGlyphTrackingEnable)

to enable the camera and glyph tracking from within the script. That way you won't have to manually enable the camera and start glyph tracking each time you want to run the script.

Also


ControlCommand("CameraGlyphTracking", glyph 3)

won't execute correctly since there isn't a ControlCommand that returns which glyph has been found.

I'm not sure exactly how to know in a script which glyph is being detected but what you can do is create a separate script for each glyph and then in the camera settings -> script -> glyph you have each script run when each specific glyph has been detected.

United Kingdom
#2  

Thanks @VGosine, I missed the fact that I needed to start the camera (doh). I do have so scripts operating when K9 "sees" a glyph, also I have added an augmented view for each one. Trust me to pick a project idea so complex, it looked so simple on paper (lol) Am I trying to achieve too much, is it possible?

Trinidad/Tobago
#3  

I think you can accomplish your goals for this project. What you might need to do is create small scripts that do a simple task, then have one main one that calls each smaller script. The only thing I think would be a little challenge is getting it to return to the home position. Maybe you can just use your patrol script to look for the first glyph. The augmented view was a nice touch :-) Let me know if you need any further assistance, I'll try my best to do what I can. I look forward to seeing this in action when you are all finished :-D

United Kingdom
#4  

Thanks dude,

This is where my knowledge is lacking, how do I "call" other scripts to a main one? I am I right in thinking that the scripts to be "called", would be written in the glyph section of camera tracking. Sorry I tend to have ideas outside my abilities :-)

#5  

It's all in the same place ... the control tab in every script...


ControlCommand("script", ScriptStart) # will start a script named "script"


United Kingdom
#6  

Thanks @Richard R, when you put it like that it's obvious i will investigate on that.

Do you know how i would ask K9 to look for a specific Glyph and ignore others until he has found the requested one?

#7  

You have 4 glyphs right? So k9 would wander around until he stumbles upon one of the glyphs.... Remember you have also 4 scripts that can run under each glyph being recognized... So, say K9 stumbles onto #2 glyph... In your code in that script you can have him execute what you want him to do.... That would apply to the rest of the 3 glyphs...

Now if you need to execute the glyphs in a certain order you could code into each script to check if K9 has encounter say glyph # 3 prior... If not he can keep looking until he hits #3... When he sees #3 (in the #3 script) you would set a flag (variable) that tells the rest of your scripts that he has indeed found #3 first and can move to the next one... repeat the flagging as required...

Seems kind of complicated, but if you break it down piece by piece it will start to make more sense...

United Kingdom
#8  

Liking the process Richard and have drawn out what i want to do. can i be cheeky and ask for a teaser code, for me to start with. not the full thing as i want to learn, just need a foot up.

;)

#9  

I wouldn't mind except I really don't have much time today... It is something that I would have to sit down and think about for a while before putting "pen to paper" so to speak...

I'll have to get back to you...

United Kingdom
#10  

OK thanks Richard, i will have a play later, but anything that you can do is much appreciated.

you are definitely an asset the the forum as a friend and a source of knowledge

:)

United Kingdom
#11  

It always sounds more complicated than it is. The reality of it is that each glyph would have a variable set, i.e. $Glyph1Seen = 1

Each Glyph would begin with

IF($Glyph1Seen = 1)

This way, if unseen the script wouldn't run. Or use 0 not 1 and if it hasn't seen it run some code...

For glyph 2 it;s as simple as

IF($Glyph1Seen = 0)
  # Keep searching for Glyph 1 and stop this script
  HALT()
Else
  # Do whatever Glyph does & Set Glyph 2 to having been seen
  $Glyph2Seen = 1
EndIf

If Glyph1 is unseen (i.e. 0 as set in the init script or script which starts this process) it doesn't do anything for Glyph 2. Use similar for Glyph 3 and 4...

IF($Glyph1Seen = 0 OR $Glyph2Seen = 0 OR $Glyph3Seen = 0)
  # Keep searching for Glyph 1 2 or 3 and stop this script
  HALT()
Else
  # Do whatever Glyph does & Set Glyph 3 to having been seen
  $Glyph3Seen = 1
EndIf

#12  

See... Even I made it more complicated than it has to be....:P

With what Rich has here I think you can get a good start on what you want to accomplish....

Well, have to do some work...

Cheers

United Kingdom
#13  

WOW, that gives me something to get my teeth into. thanks @Rich

once again, thanks @Richard R for your time and patience

i will revert with (hopefully) a video of K9 doing this thing of protecting the DR:)

United Kingdom
#14  

Hi there @Rich,

If I am reading your examples right, the following should work


# k9 leaves tardis glyph 1 and is looking for glyph 2
$Glyph1seen =1
IF ($Glyph2seen = 0 and $Glyph3seen = 1 and Glyph4seen = 1)
# looks just for glyph 2 as1, 3 & 4 are set to seen
Commandcontrol("soundboard", track_2)
#sets glyph 2 to seen
$Glyph2seen = 1
ENDIf

This can tgen be tailored and added as required, what do you think. Am I on the right track.

United Kingdom
#15  

Are you looking for the glyphs in order, i.e. Glyph 1 then 2 then 3 then 4?

Think logically and you'll get it working the way you want. IFs are pure logic and work the same way we think.

For instance, IF you are looking for the glyphs in order. You spot 1, you remember that (so you save it to a variable). You continue looking, you find glyph 3, you think "hmm, did I see glyph 2?), another IF. etc.

To find them in order...

Set the ground work first by adding in some script to the Glyph part of the camera control. Something as simple as; Glyph 1

$glyph = 1

Glyph 2

$glyph = 2

Glyph 3

$glyph = 3

Glyph 4

$glyph = 4

# Reset the seen variables
$glyph1seen = 0
$glyph2seen = 0
$glyph3seen = 0
$glyph4seen = 0

# Reset the last seen glyph
$glyph = 0

# Search for glyphs in order

ControlCommand() # Edit this to start up the roaming script used for hunting glyphs

# Wait until a glyph has been seen
WaitForChange($glyph)

IF($glyph = 1 AND $glyph1seen = 0)
  Say("Found number 1, now where is number 2?")
ELSEIF($glyph = 1 AND $glyph1seen = 1)
  Say("Found number 1 but I need number 2")
ELSEIF($glyph != 1 and $glyph1seen = 0) # Note I am not 100% sure of the != as I never use it, it may be =!
  Say("This isn't number 1, where is number 1?")
ELSEIF($glyph = 2 AND $glyph1seen = 0)
  Say("that's number 2 but I need number 1")
ELSEIF("$glyph = 2 AND $glyph2seen = 1)
  Say("that's number 2, I just saw that one, where is 3?")
ELSEIF("$glyph != 2 AND $glyph2seen = 0)
  Say("That's not number 2, I need number 2")
ELSEIF($glyph = 2 AND $glyph2seen = 0)
  Say("Found number 2, where is number 3")
# and so on
ENDIF

Use of AND and OR in the IF will reduce the number of IFs needed as will correctly ordering them. The IF is read in order and once one IF or ELSEIF returns true it ignores any others below it.

I don't have the time right now to properly think about the best order or the best operators to use in the ifs but hopefully the above should be a start and possibly help you understand that IFs work the same way as we think.

For more than one AND or IF read the statement back and see if it makes sense.

for instance, IF($x < $y AND $y > 100 OR $y > 200) that would only be true if $x was less than y and $y was more than 100 OR if $y was over 200. So if $y was 201 it would be true regardless of if $x was less than $y. If $y was 103 but $x was 104 it would be false.

Hope that's clear. If not, check my topics, I did write one on IFs and how to use them which may help you in your glyph hunt script.

United Kingdom
#16  

thanks Dude, again something to get my teeth into and my head around.

the end concept is to have K9 leave the Tardis (Glyph 1) and then depending upon which of the remaining 3 glyph's he finds does a different routine.

i.e if he leaves the Tardis and locates glyph 4 first he will then attack the dalek and then check on the Dr (Glyph 3) and then return home, but if he spotted the Warning (glyph 2) then he would move on to attack the Dalek and then check on the Dr, returning back to the Tradis after checking on the Dr each time.

i understand that this is a massive programming challenge for me, but if you don't push yourself you don't learn, right.

i totally appreciate all your time a assistance in my journey:)

United Kingdom
#17  

Hi @Rich,

just a quick question, would the code you suggested about naming the "glyphs"

Glyph 1



$glyph = 1


Does that not mean that Glyph 1 = True, not naming it No 1?

i don't mean to pull apart what you have written for me, just to understand

:)

United Kingdom
#18  

Pull it apart by all means, it shows me you are trying to learn for yourself so I really do not mind:)

$glyph = 1

basically just tells EZ-Script that the glyph it's found is #1. It's a label of sorts.

This can then be used with WaitForChange($glyph) or in IF statements etc.

You could use

$glyph = &quot;glyph1&quot;

if you wanted to. However the benefit of having

$glyph = 1

is you could use the < > or = operators in an if statement if looking for them in a specific order. Like if you were looking for glyph 2 or glyph 3 you could simply use

IF($glyph &gt; 1 AND $glyph &lt; 4)

which would be the same as

IF($glyph = &quot;glyph2&quot; OR $glyph = &quot;glyph3&quot;)

It gives some flexibility which may be useful.

#19  

@mgodsell1973 in the code you posted above all it does is assign the value 1 to the variable $Glyph... When you talk in terms of true or false usually that's in the context of a type of comparison ... For example.... if $Glyph = "true" or 1 then do something, else do something different...

United Kingdom
#20  

hi guys,

had a great session, left me feeling a bit worn out - learning is tough but so rewarding. i am slowly getting to grips with the "IF" statements and had a small victory (for me anyway) i got K9 to say something when shown Glyph 1. now i know that is a basic function however i was trying to do it in the Glyph script section and i failed, so i copied a small section of your large script over to the "script" (the clue is in the title) section and instead of it "saying" what you had written, it said what i had written in the Glyph script section?

anyway what i am trying to say really is that there are "script" sections for all of the different panels, and i am trying to work out how to link them together, from the soundboard track playing in the glyph recognition to the speech recognition when i ask K9 to go on patrol.

really i need to start at the beginning -

1 ask K9 to patrol, this i know starts with Forward and then the Ping sensor takes over and guides him around. 2 where does the code go that then pools the information from the camera, i have the variables Glyph = 1 - is the number used to identify the respective Glyph Glyph1seen - is identifying the fact that a glyph has or hasn't been seen

i am really sorry for troubling you guys, for what possibly is a daft question.

stress

United Kingdom
#21  

Hi me again,

i can already hear the painful sighs, but tonight its good news (sort of).

i walked away from my problem the other night as i was getting frustrated and reading back my last post (which i should not have written) obviously i was not thinking clearly either blush

After some time away i have made a little headway and have decided to crawl before walking. now i have added a "script manager" in my file and am writing scripts in the "glyph" section - nicely linked together.

none of the above are groundbreaking - but the one thing i am having an issue with is the fact that the Variable state is set to 1 in the "Variable Watch" panel and remains unchanged (that i can see) despite altering the Variables in the Glyph script from = 1, = 0 or leaving a blank space, could this have something to do with the fact that the Glyph reader "remembers" the last seen Glyph and will not repeat it until is sees another Glyph?

so with that in mind i am unable to run the code as you suggested as the variable is sticking at 1?

however progress is being made. tired

United Kingdom
#22  

Just a thought, could i use an if statement to say that says something like

 IF(Glyph1 = 1 AND Glyph1seen = 1, Glyphpast = 0)

?

United Kingdom
#23  

Don;t have much time so haven't read it all but that If statement is invalid.

What is it you want it to do?

If it's to set $glyphpast to 0 if the seen glyph is 1 and has been seen then you need;


If($glyph = 1 AND $glyph1seen = 1)
  $glyphpast = 0
EndIf

If it's to say to do something if $glyph = 1 and $glyph1seen = 1 or if $glyphpast = 0 then you need it to be

If($glyphpast = 0 OR $glyph = 1 AND $glyph1seen = 1)

Also, don't forget variables need the $ preceding them.

United Kingdom
#24  

Hello Again.

i have taken a good look around and thourght i had found a way to ensure that the variable "Glyph1" altered it's state as the last time i was on i found that i could not get the state to change.

Whilst i was playing around i noticed that the varaible "CameraIsTracking" changes its state from 1 - 0 depending on what it see's.

So i came up with what i believed to be an ingenious plan, which was that if i placed the Code below in to the Script editor on Glyph 1 then when "CameraIsTracking" spotted the Glyph, it would change its state and in turn then change the state of $Glyph1 to 1. but it failed..... why would that be.......?

$CameraIsTracking
$Glyph1

If($CameraIsTracking = 1)
  $Glyph1 = 1
Say(&quot;I have found the tardis&quot;)

EndIf

thanks guys, i am trying not to be a pain blush

United Kingdom
#26  

HI guys and Galls,

i am making progress ( i know i keep saying it:) ).

but i have came a small stumbling block and need some guidance.

how do i semi permanently alter the value of a variance, i have managed to use the "$CameraIstracking" variable to alter the state of some home brewed variables, however i want certain ones to remain at "1" until i ask it to revert back.

currently the problem i have is that it is reverting back to "0", this will be a simple fix but have tried to work it out myself with no luck.

thanks once again for reading.

United Kingdom
#27  

Your question is a little unclear, it may be easier if you explained exactly what you are trying to achieve.

I presume you will need to use IF and ELSEIF with OR and AND in the conditions however with the brief, vague and confusing information provided it's difficult to answer.

First look at why it's reverting back to 0, you must be telling it to revert back to 0. Surround the commands that revert it back to 0 with an IF statement with the conditions that match when you want it to revert back to 0, if the conditions are not met then it wont run the code between the IF and EndIf

United Kingdom
#28  

Hi All,

Happy new year to all:)

just a quick update to this thread, i have managed to write the code for what i wanted K9 to do. (it may not be the cleanest but it works)

Thanks to @Rich and @Richard R for your patience with my ambiguously worded questions.

the file has been uploaded "K9", please feel free to have a look and offer advice for any improvements that you think might work.

i will be uploading a video, but i am currently experiencing traction issues that i am working on.

thanks once again

P.S R.A.D has arrived and, family time - whats that LOL:)