Australia
Asked — Edited

Getping

hi all I am writing my own radar script

how do i use the value return by getping(d13,d12) e.g. :loop tr if getping(d13,d12) < 20 then Right(200) goto(tr) else stop script and exit


ARC Pro

Upgrade to ARC Pro

Take control of your robot's destiny by subscribing to Synthiam ARC Pro, and watch it evolve into a versatile and responsive machine.

United Kingdom
#1  

#baloo

Don't know if you can 'mix n match' the if and getping functions like that??

you need to test the value Getping returns with an if statement afterwards. Lots easier to use ping_wait

Australia
#2  

this what i have so far see code below i what to test to see if the distance is under 15", if so turn robot to the right or left, depending on where it is looking


Servo(d14, 100)

# start for radar loop
:radar_loop
goto(full_right)
goto (haft_right)
goto(Full_Forward)
goto (haft_left)
goto(full_left)
goto (haft_left)
goto(Full_Forward)
goto (haft_right)
goto(radar_loop)

#set the servo to look left
:full_left
Servo(d14, 10)
# turn to the right start here
#code go here to turn robot right ??
#end of turn right here
return()


:haft_left
Servo(d14, 25)
return()

:Full_Forward
Servo(d14, 50)

return()

:haft_right
Servo(d14, 75)
return()

:full_right
Servo(d14, 100)
return()

PRO
Synthiam
#3  

sounds like you want to use the radar control?

Australia
#4  

hi DJ my own radar ? so how do i use getping(d13,d12) in an if statment .. if possible

Australia
#5  

hi dj i am doing it this way just to learn about some of the script command you have showen on the help page

PRO
Synthiam
#6  

The most powerful commands for something like this are the WAIT commands. For example...


:Start

# Wait for ping sensor to return a value less than 15
Ping_Wait(d0, d1, lower, 15)

# If the head servo is greater than position 40, turn right
if (Servo(d5) > 40)
  Right()

# If the head servo is greater than position 40, turn left
if (Servo(d5) < 40)
  Left()

# Pause for 2 seconds while we move
Sleep(2000)

# Stop moving
Stop()

# Goto the start of the script
goto(Start)

And then you'll want to move the head back and forth... So create another script that does it...


# Set the servo speed on the head servo to a slow speed
ServoSpeed(D5, 4)

:Start

# Move servo head all way to the right
Servo(D5, 10)

# Pause for 7 seconds while head moves
Sleep(7000)

# Move servo head all way to the left
Servo(D5, 80)

# Pause for 7 seconds while head moves
Sleep(7000)

# Loop
goto(Start)

Australia
#7  

Hi DJ thanks for the help I broke your move script into 2 scripts I just need to fine tune the time, to get it all to run smooth:D

turn right


# Wait for ping sensor to return a value less than 15
Ping_Wait(d0, d1, lower, 15)
# If the head servo is greater than position 50, turn left
if (Servo(d5) > 50)
  Right()
# Pause for 2 seconds while we move
Sleep(2500)
forward()

Turn left


:start
# Wait for ping sensor to return a value less than 15
Ping_Wait(d13, d12, lower, 15)

# If the head servo is less than position 50, turn left
if (Servo(d14) < 50)
Left()

# Pause for 2 seconds while we move
Sleep(2500)

forward()

# Goto the start of the script
goto(Start)

and your scan to


Servo(d14, 80)
ServoSpeed(D14, 1)

:start
# Move servo head all way to the right
Servo(D14, 20)

# Pause for 7 seconds while head moves
Sleep(800)

# Move servo head all way to the left
Servo(D14, 80)

# Pause for 7 seconds while head moves
Sleep(800)

# Loop
goto(Start)

PRO
Synthiam
#8  

Nice:) It'll use a lot more processing to hav two scripts for movement. How come you separated them?

Australia
#9  

hi DJ it would not do a right()?

PRO
Synthiam
#10  

Strange. Works in my test when I wrote it.

Australia
#11  

hi DJ i'll play with the timing of the scan etc.

PRO
Synthiam
#13  

Ah you know what? Maybe don't have it move from 10 to 80 because that might be what's happening. Have it move from 10 to 40. The. 40 to 80. Then 80 to 40. Then 40 to 10.

Repeat

PRO
Synthiam
#14  

Also, if you get the latest ARC... There is a C# example for a radar control. Look under File -> Examples -> Script C Radar Control

Australia
#15  

hi DJ Thanks i did a little mod :)

  1. it move forward after turning
  2. scan rate is faster
  3. it works

using System;
using System.IO;
using System.Windows.Forms;
using EZ_B;

namespace VName {

  public class VClass {

    public void Main(EZB ezb0, EZB ezb1, EZB ezb2, EZB ezb3, EZB ezb4) {

      bool dir     = true;
      bool weMoved = false;

      ezb0.Servo.SetServoPosition(Servo.ServoPortEnum.D5, 10);
      
      while (true) {
      
        int servoPos = ezb0.Servo.GetServoPosition(Servo.ServoPortEnum.D5);
        int distance = ezb0.HC_SR04.GetValue(Digital.DigitalPortEnum.D0, Digital.DigitalPortEnum.D1);
 
        if (distance  40)
            ezb0.Movement.GoRight();
          else if (servoPos  80)
            dir = false;
        
          if (servoPos < 10)
            dir = true;

          ezb0.Servo.SetServoPosition(Servo.ServoPortEnum.D5, servoPos);
        }

        System.Threading.Thread.Sleep(250);
      }
    }
  }
}