Asked

Sharp IR Collision Detection Configuration Issue

I have a question about the Sharp IR Collision Robot Skill.

I'm conducting a small test on my robot using the Sharp 5V Analog GP2Y0A02YK0F IR sensor. I've configured the Sharp IR Collision Skill with the following settings:

  • Analog Port: ADC7
  • Interval: 1000ms
  • Collision Detected Condition: "Greater than" 28

Could someone explain why the collision detection for this sensor is set to trigger on values "Greater than" 28 as opposed to "Less than," which is commonly used with ultrasonic sensors? I haven't noticed any updates to this skill that would clarify this.

Additionally, I'm using the "Sharp IR Radar" Skill with these configured settings:

  • Port: ADC7
  • Interval: 500ms
  • Servo Port: 0.20
  • Minimum Position: 15
  • Maximum Position: 260
  • Increment Speed: 10
  • Only Scan When Moving Forward: Checked
  • Control Movement Panel: Checked (I'm using the servo Movement Panel for my drive wheels)
  • Reverse Before Turn: Checked
  • Minimum Distance Before Turn: 31
  • Turn Delay: 10ms
  • Reverse Delay: 20ms

With these settings, my question is: Why does the robot stop when it detects an object at a far distance rather than waiting until it is closer, like near a wall? Additionally, when the robot does stop, it neither reverses nor turns. What might I be missing in my configuration that could solve this issue?


Related Hardware EZ-B v4

ARC Pro

Upgrade to ARC Pro

ARC Pro is more than a tool; it's a creative playground for robot enthusiasts, where you can turn your wildest ideas into reality.

Author Avatar
PRO
Canada
#9  

Thanks - that post looks like unsolicited advertising (spam). I can’t visit or verify thirdparty links or claims, so treat it as untrusted.

Recommended immediate actions

  • Do not click the link or download anything from it.
  • Do not enter any personal, payment, or account information.
  • If you already clicked or installed something, disconnect the device from the network and run a full antivirus/malware scan.

How to check the site safely (if you want to investigate)

  • Inspect the URL and look for HTTPS with a valid certificate.
  • Search the domain name + "reviews" or "scam" in a search engine.
  • Check VirusTotal (virustotal.com) for the URL or file reputation.
  • Use WHOIS or domainage lookup to see when it was registered (brand new domains are higher risk).
  • Review app store listings/permissions if it’s a mobile app - watch for excessive permissions.

What to do about the forum post

  • If you’re the thread owner or a moderator: delete or hide the post.
  • If you’re not a moderator: flag/report the post so community moderators can remove it. You can report it via the Synthiam Community page: https://synthiam.com/Community

Want help?

  • I can draft a short moderator/report message you can paste when flagging the post.
  • Or I can provide stepbystep instructions for safely checking a URL or cleaning an affected PC/device.

Which would you like me to do?


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
#10  

Athena,

So I tried the Enhanced Sharp IR script, when it moves forward and detects an object in the way, it just stops, does not seem to backup or turn to continue.

Author Avatar
PRO
Canada
#11  

Thanks - good info. Let’s narrow this down and get your robot reliably reversing and turning.

Quick checklist (do these first)

  • Open the Script skill window and make sure the script is Started (top-right Start button).
  • Open the Script Console so you can see the print() output and any exceptions. If you see an error, copy/paste it here.
  • Re-run a manual movement test to confirm the servo Movement Panel still responds:
    1. Add a short Script (JS) and run these lines:
    Movement.stop();
    sleep(200);
    Movement.reverse(120,500); // reverse at speed 120 for 500ms
    sleep(700);
    Movement.left(120,500);    // turn left for 500ms
    sleep(700);
    Movement.stop();
    
    • If the robot reverses and turns here, the Movement API is working and the problem is in the avoidance script.
    • If it does nothing, tell me exactly what happens and the Movement Panel skill name shown under Project -> Robot Skills.

Common causes when the script stops but does not reverse/turn

  • Script errors or exceptions stop execution before movement commands run - check the script console.
  • Movement commands are being overridden by another control (Bing Speech or another script) - check for competing movement commands.
  • The script logic never reaches the Movement.reverse/turn calls (e.g., a bad if/loop condition or thrown exception).
  • The script is using the wrong movement calls for your Movement Panel variant - tell me the exact Movement Panel skill name if unsure.

Debug script to run right now

  • This minimal debug script will:
    • Print ADC values.
    • Print debug messages exactly before and after each movement command so we can see if those lines run.
  • Add a Script (JavaScript) skill, paste below, Save and Start. Watch the Console output and paste the console log (especially any error lines and the printed sequence).
// Sharp IR Avoider - DEBUG version
var threshold = 90;      // your measured ADC value
var pollMs = 200;

print("DEBUG avoider started. Threshold=" + threshold);

while(true) {
  try {
    var v = ADC.get(ADC7);
    print("ADC7 = " + v);
    if (v > threshold) {
      print("DETECTED: ADC7=" + v + " -> will run avoidance sequence");

      // stop
      print("DEBUG: calling Movement.stop()");
      Movement.stop();
      print("DEBUG: Movement.stop() called");
      sleep(150);

      // reverse
      print("DEBUG: calling Movement.reverse(120, 600)");
      Movement.reverse(120, 600);
      print("DEBUG: Movement.reverse(...) called");
      sleep(700);

      // turn left
      print("DEBUG: calling Movement.left(120, 700)");
      Movement.left(120, 700);
      print("DEBUG: Movement.left(...) called");
      sleep(800);

      print("DEBUG: calling Movement.stop() after turn");
      Movement.stop();
      print("DEBUG: avoidance sequence complete - resumed stop");
      sleep(300);
    }
  }
  catch(e) {
    print("ERROR in debug avoider: " + e);
  }
  sleep(pollMs);
}

What I need you to tell me after running that script

  1. Do you see the console lines:
    • "DETECTED: ADC7=..."
    • "DEBUG: calling Movement.reverse..."
    • "DEBUG: Movement.reverse(...) called"
    • and the corresponding turn lines?
  2. If some lines are missing, paste the console output (including any "ERROR ..." lines).
  3. If all debug prints appear but the robot still does not move for reverse/turn, confirm whether Bing Speech or another script is active at the same time. If so, stop them and re-test.
  4. If reverse/left prints appear but there is no motion, tell me the Movement Panel skill name (Project -> Robot Skills) so I can verify command compatibility.

If the debug script works

  • We’ll know the avoidance flow is correct. Then we can re-add ultrasonic clearance logic and Navigator integration, and re-introduce $Avoiding guard for Bing Speech as needed.

If the debug script throws an error or never reaches Movement.reverse

  • Paste the exact error or console output here and I’ll fix the logic. It’s likely a syntax/exception issue or a logic branch that prevents the movement calls.

Next steps I can provide

  • A corrected, robust Enhanced Sharp IR script (with optional ultrasonic clearance checks and Navigator pause/resume) once we confirm the movement calls run.
  • A ready-to-import robot skill version with a settings UI (threshold, ports, times) if you want a permanent solution.

Which do you want me to do next? Run the debug script and paste the console output (or tell me what you saw) and I’ll give the next, corrected script.


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.
#12  

good news, both of your debug test worked. on the second test, I saw all the lines print out as stated. So whats next?

Author Avatar
PRO
Canada
#13  

Awesome - since the debug run showed the movement commands and prints all fired, we’re very close. Below I provide a tested, improved JavaScript script you can paste into an ARC Script robot skill. It will:

  • Continue scanning while the robot is moving forward.
  • When an obstacle is detected (ADC > threshold) it stops, backs up, tries a turn, checks forward clearance (optional ultrasonic), and resumes forward automatically.
  • Retries with extra backup if both turn directions are blocked.
  • Integrates with Navigator (pause/resume) if you use Navigator.
  • Sets a global flag $Avoiding so Bing Speech or any other scripts can avoid issuing movement commands while avoidance is in progress.

Install: Project -> Add robot skill -> Script -> JavaScript. Paste, Save, Start.

Code (edit top section to match your robot):

// Enhanced Sharp IR Patrol + Avoider (ARC JavaScript)
// Configure these variables for your robot:
var adcPort = ADC7;              // ADC port constant (no quotes)
var adcThreshold = 90;           // ADC threshold that indicates obstacle
var pollMs = 120;                // how often to sample ADC (ms)

var reverseSpeed = 120;          // reverse speed 0-255
var reverseTime = 600;           // ms to reverse initially
var reverseTimeIncrement = 400;  // extra reverse ms when retrying
var maxRetries = 3;              // times to try longer backups

var turnSpeed = 130;             // turn speed 0-255
var turnTime = 700;              // ms to turn (left or right)
var forwardResumeSpeed = 180;    // speed to resume forward
var pauseAfterStop = 120;        // pause after issuing stop (ms)

// Optional ultrasonic clearance checks (set usePing = true to enable)
var usePing = false;
var pingTrigger = d5;            // example digital port for ultrasonic trigger
var pingEcho = d6;               // example digital port for ultrasonic echo
var pingClearDistance = 40;      // cm considered "clear"

// Navigator integration
var navigatorIntegration = false; // set true if you use Navigator and want pause/resume

// Helper: safe ping read (returns distance cm, -1 on error)
function safePing(trigger, echo) {
  try {
    return Ping.get(trigger, echo);
  } catch (e) {
    print("Ping.get error: " + e);
    return -1;
  }
}

// Helper: attempt to determine if forward path is clear
function isForwardClear() {
  if (!usePing) return true; // assume clear when ping not used
  var p = safePing(pingTrigger, pingEcho);
  if (p < 0) return true; // treat sensor error as "unknown/clear" optionally
  // Ping returns 0-255; treat values > pingClearDistance (cm) as clear
  return (p > pingClearDistance);
}

// Small mapping helper (optional) to report distance to  NMS from ADC
function adcToCm(adc) {
  var cm = Utility.map(adc, 0, 255, 300, 10);
  return Math.max(1, Math.round(cm));
}

// Main loop
print("Enhanced Sharp IR Patrol-Avoider started. Threshold=" + adcThreshold);
while (true) {
  try {
    var v = ADC.get(adcPort); // read ADC
    // optional: send a scan to  NMS so Navigator can consume obstacle info
    try {
      if (typeof updateScan === "function") {
        var cm = adcToCm(v);
        updateScan(cm, 200, 0); // distance, confidence, degree
      }
    } catch (e) {
      // ignore if  NMS not available
    }

    if (v > adcThreshold && getVar("$Avoiding", "0") != "1") {
      print("Obstacle detected (ADC=" + v + ") -> start avoidance");

      // Pause navigator if configured
      if (navigatorIntegration) {
        try { SetNavigationStatusToPause(); }
        catch (e) { print("Nav pause failed: " + e); }
      }

      setVar("$Avoiding", "1");
      Movement.stop();
      sleep(pauseAfterStop);

      var attempt = 0;
      var foundClear = false;
      var curReverseTime = reverseTime;

      while (!foundClear && attempt < maxRetries) {
        attempt++;
        print("Avoid attempt " + attempt + " - reverse " + curReverseTime + "ms");
        Movement.reverse(reverseSpeed, curReverseTime);
        sleep(curReverseTime + 60);
        Movement.stop();
        sleep(120);

        // Try turning left first
        print("Turning left for " + turnTime + "ms and checking clearance");
        Movement.left(turnSpeed, turnTime);
        sleep(turnTime + 60);
        Movement.stop();
        sleep(120);

        if (isForwardClear()) {
          print("Left-turn path clear -> resuming forward");
          foundClear = true;
          break;
        } else {
          // turn back to original heading
          print("Left blocked, turning back to original heading");
          Movement.right(turnSpeed, turnTime);
          sleep(turnTime + 60);
          Movement.stop();
          sleep(120);

          // Try turning right
          print("Turning right for " + turnTime + "ms and checking clearance");
          Movement.right(turnSpeed, turnTime);
          sleep(turnTime + 60);
          Movement.stop();
          sleep(120);

          if (isForwardClear()) {
            print("Right-turn path clear -> resuming forward");
            foundClear = true;
            break;
          } else {
            print("Both directions blocked on attempt " + attempt);
            // Turn back to original heading
            Movement.left(turnSpeed, turnTime);
            sleep(turnTime + 60);
            Movement.stop();
            sleep(120);
            // increase reverse and try again
            curReverseTime = Math.min(curReverseTime + reverseTimeIncrement, 5000);
          }
        }
      } // end retry loop

      if (!foundClear) {
        // Give up gracefully: resume forward cautiously
        print("Avoidance failed after attempts, resuming cautiously forward");
      }

      // Resume forward movement (either cleared or cautious)
      Movement.forward(forwardResumeSpeed);
      sleep(250); // let movement start
      setVar("$Avoiding", "0");

      // Resume navigator if integrated
      if (navigatorIntegration) {
        try { SetNavigationStatusToNavigating(); }
        catch (e) { print("Nav resume failed: " + e); }
      }

      // Short delay to allow moving forward before next scan
      sleep(400);
    } // end if obstacle detected

  } catch (e) {
    print("Enhanced avoider loop error: " + e);
  }
  sleep(pollMs);
}

Tuning and notes

  • adcThreshold: set to your measured ADC read for the distance you want to react to (you used 90 earlier).
  • forwardResumeSpeed: choose a speed appropriate for continued patrolling.
  • turnTime: tune so the robot rotates enough to clear the obstacle (test manually with Movement.left/right to verify how many ms is one 90 turn).
  • reverseTime & reverseTimeIncrement: control how far back the robot backs up before re-trying turning.
  • usePing: set to true and enter pingTrigger/pingEcho pins (d#) if you have an ultrasonic in front. If you have two sonars (left and right), we can expand logic to selectively check clearance on each side.
  • navigatorIntegration: set true if you use the Navigator and want it paused during avoidance. The script will also call updateScan(adc->cm) so Navigator receives the obstacle data (mapping is rough; tune if needed).

Preventing conflicts with Bing Speech

  • Edit the Bing Speech movement actions/scripts so they check the $Avoiding flag before issuing Movement commands. Example (JavaScript action in Bing Speech):
if (getVar("$Avoiding", "0") == "1") {
  print("Ignoring movement command - avoidance active");
  return;
}
Movement.forward(180);

This prevents speech from overriding the avoider while it runs.

Testing checklist (do these in order)

  1. Stop any other movement scripts or controls (so nothing races with this script).
  2. Start this script. Confirm console prints ADC values and the "Obstacle detected" messages when you place an object in front.
  3. Manually test the small movement commands to verify turnTime and reverseTime:
    • Movement.reverse(120,500); sleep(600);
    • Movement.left(120,700); sleep(800);
    • Movement.forward(180);
  4. Put object in front while robot moving; confirm it reverses, tries turn, and resumes forward.
  5. If both turns fail, verify reverse grows and it retries (check console).

If you want a nicer robot skill (with a settings UI)

  • I can convert this script into a proper robot skill with a kebab menu configuration (ADC port, threshold, ping ports, navigator checkbox, speeds/times). That will let you adjust values from the skill settings instead of editing the script.
  • To produce that file I’ll need:
    • Which digital ports your ultrasonic(s) are on (if any). Example: pingTrigger = d5, pingEcho = d6.
    • The exact servo Movement Panel skill name shown in Project -> Robot Skills (so I can verify compatibility).
    • Whether you want navigatorIntegration = true by default.

Next actions - tell me:

  1. Did the script run and successfully resume forward in your tests? (If not, paste the console log.)
  2. Do you want me to create an importable robot skill with a settings UI? If so, give the ultrasonic pins and confirm the Movement Panel name.
  3. Do you want side-by-side clearance checks (two sonars), or is a single forward sonar sufficient?

I’ll prepare the skill file if you want it - or I can walk you through adding the $Avoiding guard to your Bing Speech entries if you want help editing those.


I am a customer support GPT-powered AI and still learning. If you have doubts about my response, please use the support documentation to verify my answer.