Spain
Asked — Edited

Script Manager And Script Pauseon

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:)


ARC Pro

Upgrade to ARC Pro

Your robot can be more than a simple automated machine with the power of ARC Pro!

United Kingdom
#17  

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)

United Kingdom
#18  

# Ping Object Avoidance
# Using Ultra Sonic Ping Sensor on servo for avoidance

# Adjust values below for configuration
$pingport = D0 # Change for Ping Port
$echoport = D1 # Change for Echo Port
$maxdistance = 35 # Change for maximum distance from object before avoiding in units
$onlyforward = 0 # Only if moving forwards? 0 = no, 1 = yes
$reverseturn = 0 # Reverse before turn? 0 = no, 1 = yes
# centreturndirection removed
$turnamount = 500 # Change for how long to turn for in ms
$reverseamount = 500 # Change for how long to reverse for in ms (if applicable)
$movementspeed = 255 # Change for movement speed

# Sweep variables
$sweepmin = 25 # Change for min limit
$sweepmax = 77 # Change for max limit
$sweepcenter = 52 # Change for center position
$sweepservo = "D3" # Change for servo port
$sweepprevious = 1000 # Do not change

# -- The Script --

GOTO(sweep)

# Check if only to detect when moving forwards
:detect
IF ($onlyforward = 1)
  IF ($Direction = "Forward")
    GOTO (detectstart)
  ELSE 
    GOTO (detect)
  ENDIF 
ELSE 
  :detectstart
  $currentdistance = GetPing($pingport, $echoport)
  IF ($currentdistance <= $maxdistance)
    GOTO(avoid)
  ENDIF 

# Sweep the servo to the next position
  GOTO(sweep)

  SLEEP (50)
  GOTO(detect)
ENDIF 

# The avoidance script
:avoid
IF ($reverseturn = 1)
  reverse($movementspeed,$reverseamount)
ENDIF 
IF($sweepcurrent = $sweepmin)
  RIGHT($movementspeed,$turnamount)
ELSEIF($sweepcurrent = $sweepmax)
  LEFT($movementspeed,$turnamount)
ELSE
  Servo($sweepservo,$sweepmin)
  $pingmin = GetPing($pingport, $echoport)
  Servo($sweepservo,$sweepmax)
  $pingmax = GetPing($pingport, $echoport)
  Servo($sweepservo,$sweepcenter)
  IF($pingmin > $pingmax)
    RIGHT($movementspeed,$turnamount)
  ELSE
    LEFT($movementspeed,$turnamount)
  ENDIF
ENDIF
RETURN()

# The sweep script
:sweep
# Check for previous position, if no position assume to be $sweepmax
IF($sweepprevious = 1000)
  $sweepprevious = $sweepmax
ENDIF

# Get the current position
$sweepcurrent = GetServo($sweepservo)

# Move in the correct direction and store previous position
IF($sweepcurrent = $sweepmin)
  $sweepprevious = $sweepcurrent
  Servo($sweepservo, $sweepcenter)
ELSEIF($sweepcurrent = $sweepcenter and $sweepprevious = $sweepmin)
  $sweepprevious = $sweepcurrent
  Servo($sweepservo, $sweepmax)
ELSEIF($sweepcurrent = $sweepcenter and $sweepprevious = $sweepmax)
  $sweepprevious = $sweepcurrent
  Servo($sweepservo, $sweepmin)
ELSE
  $sweepprevious = $sweepcurrent
  Servo($sweepservo, $sweepcenter)
ENDIF

# Return back to the main script
Return()

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.

Spain
#20  

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.

Spain
#21  

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

United Kingdom
#22  

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.


:loop
Forward()
ControlCommand(WindowName, ScriptStart)
Goto(loop)

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.

Spain
#23  

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?

United Kingdom
#24  

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.