
I feel like a blind man wandering around in the bush at night hoping to find my way home!
So here's where I'm at with this project, I've put some comments in so you can see what I'm trying to accomplish. Any and all help will be appreciated. Code:
:loop
#timer to power down
$x = 0
RepeatUntil($x = 30)
$x++
Sleep(1000)
EndRepeatUntil
repeatUntil(1=2)
#what to do when timer gets to 30
set(D2,OFF)
#$x = GetDigital(D2)
ControlCommand("Script Manager", ScriptStart, "power down")#do this once
sleep(5000)
WaitForChange(GetDigital(D2))
sleep(5000)
#do this when the PIR is triggered after "power down"
$motion=getDigital(D2)
IF($motion=1) #pin went high
ControlCommand("Script Manager", ScriptStart, "Power up")#do this once
endif
#do this if PIR is triggered anytime after it has powered up
$motion=getdigital(D2)
if($motion=1)
#stay powered up - need something here - what?
sleep(10000)
EndIf
# if Pir is not triggered in 30 sec start the timer again
If($x = 30)
GoTo(loop)
endif
EndRepeatUntil
Thanks
PS. I would pay money to go to a course somewhere to learn EZ-Robot scripting!
To be honest I'd prefer (well, love to actually) rewrite this one (including comments and explanations to help you understand it all) however that'll have to wait until I finish work but to get it straight can you confirm the operation and order of.
Presumably it's this;
Robot sleeps until awoken by PIR sensor?
Robot powered up manually first time.
Robot detects movement via PIR
After 30 seconds of inactivity robot moves to low power state while still checking for movement
On detection of movement robot wakes up
After 30 seconds of inactivity robot moves to low power state while still checking for movement
and so on
I'll knock something up quickly later.
Thanks for your help
All scripts I assumed would be in "Script Manager", if they are separate scripts or your rename Script Manager you need to check the ControlCommands()
This will use three scripts. One for monitoring of the PIR over a period of roughly 30 seconds. One will shut down to low power mode and monitor the PIR waiting for motion and the last will Power Up the robot and start the monitoring.
Until all three scripts are written/added you may get some errors if you try to run them as the scripts will not exist.
First start with the power up script.
Code:
This will turn on all functions you need to have turned on and then start the "Monitor" script in Script Manager. It's this script which you would want in your "init" script which is run on connection.
It's a very basic script which shouldn't need any more explanation than this.
Next we need the "Monitor" script.
Code:
The comments in the script should explain each part of it.
The HALT() at the end is optional. Without it the script will just stop anyway however I have included it as I like to use HALT() and it also should indicate where the script will end.
When motion is detected the script will jump back up to the start rather than continue in it's current Repeat loop. Next time the Repeat loops are run the counters are reset to 0 so the time is reset to 0.
When the time runs out without motion detected the script starts up the LowPowerMonitoring script and this one ends.
So now, all that is left is the low power monitoring script;
Code:
Another very simple script. The start needs editing for your low power commands, control commands to shut off or pause functions etc.
Then it sits there monitoring the digital port (D0 in this case, edit to suit). When it changes, i.e. when there is motion it uses ControlCommand to start up the Power Up script again. The power up script starts the monitoring script and we have an endless circle.
Hopefully that should get you going
Thanks again,
Bob
Code:
Presuming it's on board 0. If on another board change the 0. If multiple boards put each board on a new line i.e.
Code:
If you only want to power down a specific servo use
Code:
Or multiple servos
Code:
Or multiple servos across multiple boards
Code:
It worked fine when using "D2", I changed ports because all of my digital ports are in use.
Code:
If not, you may need to build a small circuit to make it work for ADC.
Code:
When it is triggered it goes to 2.5V and up the the line second from the top on the graph.
I have tried all sorts of different setting and nothing makes a difference. The"Monitoring" script goes to the "LowPowerMonitoring" script and then immediately to the "Power up" script . I have put in a delay in the "LowPowerMonitoring" script, to give the PIR time to reset. That did not make a difference, either.
When the PIR is low the value is 25 when it is triggered it goes to 195.I set the high to be >190. I put "print()" in both the monitor script and the lowpowermonitoring script and if reads >25 in both.
As usual still not working.
Watching the LowPowermonitor script run, it runs through the script - does not "WaitForChange" Prints >25
You could do it slightly differently and add in another script that's always running which checks the ADC value and if it's above a certain value it sets a variable, if below it changes the variable... i.e.
Code:
When the PIR is triggered it will set $motion to 1. When it's not then $motion is reset to 0
You can then use $motion in your original script to replace the GetDigital() command
I applied your new script and it senses the change as does the "Monitoring script" but nothing happens. I must have something out of place in the "monitoring script" below;
Code:
Thanks
Code:
This is all from memory and without ARC. It looked like you had it detecting motion when there was none and vice versa. This was causing it to reset the timer and start again.
You could remove the whole converting it to 0 or 1 though, it's pretty redundant.
Code:
Code:
Thanks, we are getting closer. Thanks for the nice comments you said about my project.
Here's what I ended up with;
Code:
Thanks again for everyone's help.
Standby though, I'm working on another script, so you know I'll be calling on the community for help.