
R2D2
Spain
Asked
— Edited
You can pause a script and then unpause?
I'm trying to run my personal radar control and I have a script that moves the servo ping sensor, but I would like to pause the movement when turning to avoid obstacle and then unpause to move forward.
I have proven this if successful:
CC ("Script Manager" ScriptPauseOn, "radar")
Not if it is misspelled or does not exist the command "PauseOn" for Script Manager
I have also proven with the command PauseMS but seems not to work.
Thanks in advance for your answers
Yeah you got me, I missed the :sweep and also missed a closed bracket on IF($sweepprevious = "none"
I know where the problem is, and I can't believe I did it...
The $sweepprevious is set to "none" near the start. It cannot then be changed to a number. Easy fix for that though.
Also I just found that I've got muddled with variable names too, so re-written to correct the minor mistakes (only variable names and rookie mistakes, the method displayed above is still correct but I'll correct that too when I get chance).
Bear with me while I correct the code and check it (this time)
This at least runs and loops. I've not tested it with an EZB setup with a servo and ping sensor though.
The main problems were I had overlooked the fact that it would check the $sweepcurrent variable before it was defined. So calling for the script to immediately go to sweep resolved that. It could have been resolved by setting the variable at the start of the script too (like the $sweepprevious) I had also gotten mixed up between the variable name for $sweepcurrent and wrote it as $currentposition, so the variable didn't exist and it threw an error. These are the problems with trying to multitask
I also missed the :sweep label and missed a ) at the end of one of the IFs.
All have been corrected above. I have run it in ARC and it loops fine but I have not tested on an EZB with the sensor etc. Let me know if it operates correctly or not.
Download it from EZ-Cloud https://synthiam.com/Community/EZCloud/Download.aspx?id=336
Okay, I've checked your file and set the ping sensor ports, servo and sensing distance, but seems not to work at all. When active the script, the ping sensor servo starts moving too fast and not reaching the specified reccorrido (25,52,77), seems as if time were missing breaks between each position. The script does not start the robot forward by default, I guess with a forward () somewhere is solved, but then when I press a Convenience key to go forward and reaches an obstacle it dodges, but also stops, also quick scan stops the ping servo.
This is the video of the robot executing your code:VIDEO.zip
and that the files you download from the cloud (your code) with the modified parameters for my servo ports.RADAR.EZB
Sorry I should have explained that this only detects and avoids, it doesn't start the movement nor will it continue it should something disrupt the movement panels action.
You could create another script with the forward command and then a ControlCommand to start the avoidance script. Loop it and I think it would work.
From memory I can't remember the ControlCommand syntax so please replace that line with the correct syntax.
DJ has now added Pause and WaitForChange to EZ-Script as of today's update. These will be very useful in this example (I suspect he saw this post and added the command). It means each of the sub routines can be made in to their own scripts and called, paused and resumed when required. When time permits I will post an example.
A WaitForChange could be used along side a variable in the other script as a flag so the above script doesn't keep calling the script to start or calling for the forward movement when it doesn't need to.
He has become prove their code by adding a script with: ...................................................................... : loop Forward () ControlCommand (script name, ScriptStart) Goto (loop) ...................................................................... This script starts another forward but suspect "goto (loop)" causes a loop at high speed and only moving forward without control. Furthermore, although not advancing forward the ping sensor servo seems to reach no fixed route, just shake near the center position, I think that setting the servo positions (25,52,77) and consider the it takes the servo to reach each position, the script assumes that you have reached the position instantly, and it is not. Maybe we should add something like this in the appropriate place:
............................................ Servo_Servo_Wait (equals, 25) Servo_Servo_Wait (equals, 52) Servo_Servo_Wait (equals, 77) .......................................... What do you think?
I'll have a good look at it when I get home. My other EZB should be with me tomorrow (should have been today but I wasn't home) so I'll knock up a test rig and get it sorted
This is the problem when I try scripting while at work without ARC or an EZB to test with...
As for the the sweeping servo, I think I may have missed out some sleep commands. After the Servo($sweepservo, $sweepmin) (and center and max) commands try adding in a Sleep(250) and see how that works.