Canada
Asked — Edited

Some Code Help Please

Hello, I need some code help. I realize this is super simple but can't get my head around it.
In the following code once "Master" or "Milady" has been identified and the ControlCommand has been executed, I would like the CameraObjectName subject to be ignored for say, 1/2 hour.

To try and be clear, once it sees you it won't execute the ControlCammand repeatedly .

Thanks in advance. Tony

SayEZB(("I see " + $CameraObjectName))

if ($CameraObjectName = "Master")

  sleep(2000)

  ControlCommand("Script Manager", ScriptStart, "Fist Bump")


elseif ($CameraObjectName = "Milady")

  sleep(2000)

  ControlCommand("Script Manager", ScriptStart, "Royal Wave")


else


endif


ARC Pro

Upgrade to ARC Pro

ARC Pro is your passport to a world of endless possibilities in robot programming, waiting for you to explore.

PRO
Synthiam
#1  

You got it! I have a few questions to get started...

  1. where does this script live? Is it in the camera control OnTracking event?

  2. What do the scripts "Fist Bump" and "royal wave" look like? A lot of the script you're asking to be reviewed is missing

  3. What do you mean the ControlCommand() executes repeatedly? I think this question would be answered with question #1, because we're not sure where this script lives

  4. Lastly, i'm not sure i'm following the goal because I'm confused by the mention of repeatedly ControlCommand() and waiting 30 minutes for something - but i see no reason why either of those things would happen in the partial code snippet posted. To clarify, are you wanting the script to WAIT 30 minutes before reacting to the detected object?

#2  

Try this one below. You need to declare your $CameraObjectName varable somewhere first like in your startup script or this script. You may be able to leave $CameraObjectName out of this script if it's declared somewhere else.

($CameraObjectName = #Master or Milady)


:Start

WaitForChange($CameraObjectName)

SayEZB("I see " + $CameraObjectName)

if ($CameraObjectName = "Master")
  sleep(2000) #you may be able to remove this wait
  ControlCommand("Script Manager", ScriptStart, "Fist Bump")

ELSE ($CameraObjectName = "Milady")
  sleep(2000) #you may be able to remove this wait
  ControlCommand("Script Manager", ScriptStart, "Royal Wave")

endif

Goto(Start)

PRO
Synthiam
#3  

Dave, the $CameraObjectName is automatically declared and populated by the camera device. The variable holds the object name that has been detected by the camera. Find out more using this the robot program episode: https://synthiam.com/Tutorials/Lesson/106

#4  

After rereading your first post I see my script may not help. How about this one: By placing a Pause( ) near the end of this script it will stop the script and hold it until another script calls this script to resume by using a ControlCommand Resume function. It will then loop back the the beginning and start again.


:Start

SayEZB(("I see " + $CameraObjectName))

if ($CameraObjectName = "Master")

  sleep(2000) #you may be able to remove this wait

  ControlCommand("Script Manager", ScriptStart, "Fist Bump")


ELSE ($CameraObjectName = "Milady")

  sleep(2000)#you may be able to remove this wait

  ControlCommand("Script Manager", ScriptStart, "Royal Wave")

endif

Pause( )

Goto(Start)

#5  

Oh, thanks DJ. That makes it easy. I know nothing about the camera control.

I think my last script should work. However to make it simpler you should find a way to pause the script for your wanted 30 minutes in place of the Pause() command I show. Maybe have the script use the computer's clock?

PRO
Synthiam
#6  

The original poster cannot "pause a script for 30 minutes" unless it is in the right place. That's what my question #1 is about - where does this script live?

You see, the sleep() command can delay for a period of time, but 30 minutes is a long time - specifically if the script is in the camera control On Tracking Start event. There's no reason to hold an event active in the compiler. Having a stand-alone script would be fine, it can wait for ever... but in an event, such as Tracking Start, is a bad idea.

The original poster needs to explain a bit more about what they're trying to do because there's too many unanswered questions at this time.

#7  

I assumed from the original post that he wanted a Stand alone script triggering other scripts when a face was recognized. That's why I suggested figuring out how to pause the script 30 minutes after a face was recognized. I thought that's what the OP was wanting to do. I was thinking that the script could check the system clock after a face was recognized, run the wanted script depending who it was, then loop back to the beginning then wait till another face was recognized.

Canada
#8  

Thanks Dave and DJ,

Sorry for the confusion. Writing English is difficult for me and the use of proper terminology eludes me. Perhaps I will just say what I want to do:

When someone enters the room and is recognized by the camera object tracking and is spoken to, and waved to, I would like that to happen only once. Then (their face but not other objects) ignored for awhile. So the same person isn't being continually spoken to, and waved to.

But after that event, I would like other objects to be recognized in the within the same script and acted upon.

I hope this is clear enough.

To answer the below questions, 1, this is a script in the camera control. like in this episode https://synthiam.com/Tutorials/Lesson/106 2, fist bump and royal way are a script to activate an auto positions from different ezb's. 3, I really don't know I meant. 4, i hope the explanation above answers this.

  1. where does this script live? Is it in the camera control OnTracking event?

  2. What do the scripts "Fist Bump" and "royal wave" look like? A lot of the script you're asking to be reviewed is missing

  3. What do you mean the ControlCommand() executes repeatedly? I think this question would be answered with question #1, because we're not sure where this script lives

  4. Lastly, i'm not sure i'm following the goal because I'm confused by the mention of repeatedly ControlCommand() and waiting 30 minutes for something - but i see no reason why either of those things would happen in the partial code snippet posted. To clarify, are you wanting the script to WAIT 30 minutes before reacting to the detected object?

#9  

Really not a good idea to run a loop in the camera control script... In essence it is already basically a loop in itself....

#10  

I am probably making this more complex than it needs to be, and I haven't completely formed the thought so I am not sure how I would do all of this, but...

In your camera control script, I would check for the contents of a variable and only execute the command if the variable was 'true' or whatever you set it to. after running the command, set the variable to 'false'.

Then you need another script that watches for that variable to change, and sets a timer when it does, and changes it back when the timer expires. That one can run in a loop.

Alan

Canada
#11  

@Richard R. Ok, I'll give up trying.

#12  

Quote:

Ok, I'll give up trying.
You shouldn't give up, just run the loop outside the camera control, like I describe above. In a few weeks I expect to finally have time to spend on robots again (3 year project at work coming to an end) and if you haven't solved it by then, I will write examples.

Alan

#13  

Don’t give up trying. This is actually a good exercise that could benefit others. Hopefully DJ will return to this post.

Canada
#14  

Thanks Alan. it is a challenge for me.

PRO
Synthiam
#15  

Okay - that's an easy bit of code to write. This doesn't need a loop. I'll write something for you to get you started. Stay tuned

PRO
USA
#16  

Initialization script:


$master_alert_expire_on=""
$milady_alert_expire_on=""

Camera script :


SayEZB("I see " + $CameraObjectName)

if ($CameraObjectName="Master")

  #logic: both conditions 1 and 2
  #       1) expiration date is set, i.e. string not empty
  #       2) current time i.e. Now() is less than the current expiration date time
  #       => Ignore!         
  if ($master_alert_expire_on!="" AND now()<$master_alert_expire_on)
    print("ignoring master")
  ELSE
    # set the master variable expiration date to 30 minutes
    $master_alert_expire_on=AddMinutes(now(),30)
    ControlCommand("Script Manager", ScriptStart, "Fist Bump")
  endif

ELSEif ($CameraObjectName="Milady")

  if ($milady_alert_expire_on!="" AND now()<$milady_alert_expire_on)
    print("ignoring milady")
  ELSE
    # set the milady variable expiration date to 30 minutes
    $milady_alert_expire_on=AddMinutes(now(),30)
    ControlCommand("Script Manager", ScriptStart, "Royal Wave")
  endif

endif

PRO
Synthiam
#17  

Here you go.... it keeps a list of 10 historical objects and doesn't alert on them for 30 minutes. Put this in the Camera Device TRACKING START script


$numberOfPeopleInHistory = 10

DefineArray($peopleScene, $numberOfPeopleInHistory, "unknown")

DefineArray($lastscene, $numberOfPeopleInHistory, $date)

repeat ($cnt, 0, $numberOfPeopleInHistory - 1, 1)

  if ($CameraObjectName = $peopleScene[$cnt])

    if (AddMinutes($lastScene[$cnt], 30) < $date)

      # haven't seen this object in 30 minutes
      # store this time update and run action

      $lastScene[$cnt] = $date

      goto(doAction)

    endif

      # no need to continue looping since this detected object
      # didn't pass the time check condition

    halt()

  endif

endrepeat ()


  # If we get here, there was no prior detect stored
  # Now we store the detection and run the action
  # Find an index that is empty and populate it

repeat ($cnt, 0, $numberOfPeopleInHistory - 1, 1)

  if ($peopleScene[$cnt] = "unknown")

    $peopleScene[$cnt] = $CameraObjectName
    $lastScene[$cnt] = $date

    goto(doAction)

  endif

endrepeat


:doAction

if ($CameraObjectName = "DJ")
  ControlCommand("Auto Position", AutoPositionAction, "Bow")
ELSEif ($CameraObjectName = "Holy")
  ControlCommand("Auto Position", AutoPositionAction, "Wave")
ELSEif ($CameraObjectName = "Tony")
  ControlCommand("Auto Position", AutoPositionAction, "Fist Bump")
endif

halt()

Canada
#18  

Thanks Gentlemen. I'll chew on that for a bit. There is hope.

PRO
Synthiam
#19  

No need to chew:)

  1. Copy the code that i posted

  2. load ARC

  3. PASTE the code into the camera device TRACKING START

voila:D