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

Synthiam ARC Pro is a new tool that will help unleash your creativity with programming robots in just seconds!

Author Avatar
PRO
Canada
#1  

Short answer - it’s not a bug: Sharp IR sensors report a voltage that increases as an object gets closer, so the Collision and Radar skills trigger on a larger ADC value (Greater than) when something is near. Ultrasonic distance sensors return a distance value where smaller numbers mean closer, so those use Less than.

Below I explain why you’re seeing the robot stop "far away," why it may not be reversing/turning, and give stepbystep troubleshooting + recommended settings and a quick ADC test script so you can calibrate the thresholds for your GP2Y0A02YK0F.

Why "Greater than" (not "Less than")

  • The Sharp GP2Y0A02YK0F outputs an analog voltage that increases as an object gets closer (higher voltage -> higher ADC reading).
  • ARC’s ADC readings for the ADC.get()/skill use are 0-255. For Sharp IR, a closer object = larger ADC value, therefore collision detection should be set to "Greater than X."
  • Ultrasonic sensors typically produce a numeric distance in cm (larger number = farther), so those use "Less than X" to detect close objects. Different sensor types, different comparison.

Why your robot stops at a far distance

  • Your Collision skill trigger is set to Greater than 28. That means as soon as ADC7 > 28 the skill considers a collision - that may correspond to a far distance for your sensor.
  • The Sharp IR Radar "Minimum Distance Before Turn" is 31 - close to 28. If your ADC values for objects at far distances are already >28, the Collision/Radar will stop/trigger early. You need to calibrate the ADC thresholds to values that correspond to the physical distance you want.

Why it doesn’t reverse or turn Possible causes:

  1. Movement Panel capability mismatch - the Radar/Collision "Control Movement Panel" actions only work if the Movement Panel skill you added supports the commands the Radar skill calls (reverse, turn). Verify the Movement Panel skill you added exposes reverse/turn functions for ARC to call.
  2. Timing values too small - your Turn Delay 10ms and Reverse Delay 20ms are extremely short. The movement commands may be issued but the time is too short for the robot to actually move. Use values in the hundreds of milliseconds (e.g., 300-800ms) for testing.
  3. Threshold mismatch/order - collision may stop the Movement Panel but the Radar’s reverse/turn logic has its own thresholds (Minimum Distance Before Turn = 31). If collision triggers at >28 but Radar requires >31 to perform turn/reverse logic, you’ll get a stop without a follow-up reverse/turn.
  4. "Only Scan When Moving Forward" - if the robot is not recognized as "moving forward" by the Movement Panel, Radar may not run the scan/avoid routine. Verify the robot is actually sending movement state.

Stepbystep troubleshooting & recommended changes

  1. Calibrate raw ADC values:
    • Run a small ADC monitor script (place it in a JavaScript script control). This will show what ADC7 reports at various distances so you know proper thresholds.
// ADC monitor for ADC7. Press STOP to end the script.
while (true) {
  var v = ADC.get(ADC7);        // returns 0 - 255
  print("ADC7 = " + v);
  sleep(200);                   // update every 200 ms
}
  • Hold a target at known distances (e.g. 10 cm, 30 cm, 60 cm, 150 cm) and note ADC readings. Use those numbers to set your Collision and Radar thresholds.
  1. Set collision/radar thresholds from measurements:

    • In Sharp IR Collision: set Collision Detected Condition to Greater than the ADC value measured at the distance you want the robot to consider a "collision." If you want the robot to stop at 30 cm, use the ADC value you measured at 30 cm (maybe +/ a couple counts for tolerance).
    • In Sharp IR Radar: set Minimum Distance Before Turn to the ADC value measured where you want to start backing up/turning (likely larger than the Collision stop threshold if you want a backup/turn sequence).
  2. Increase delays so you can see motion:

    • Change Turn Delay and Reverse Delay from 10/20 ms to something like 300-800 ms while testing. That gives motors time to physically turn/reverse.
  3. Verify Movement Panel compatibility:

    • Open the Movement Panel skill you added (Project -> Add Skill -> Movement Panels if not present) and confirm which commands it supports (forward, reverse, left, right, stop).
    • The Radar/Collision "Control Movement Panel" requires a Movement Panel skill that accepts reverse/turn commands. If you used a custom servo Movement Panel that only supports forward/stop, Radar cannot make it reverse/turn. Try the Differential/Servo Movement Panel that supports these actions or configure your Movement Panel to support reverse and turn.
  4. Ensure names match and Control Movement Panel is enabled:

    • Open the Sharp IR Radar settings (click the three lines/hamburger on the skill window -> Configure).
    • Make sure "Control Movement Panel" is checked and the Movement Panel name selected is the same as the Movement Panel instance in your project. The skill must be able to find and call the Movement Panel by name.
  5. Test manual movement commands

  6. Re-test with adjusted thresholds and delays:

    • After calibration and increasing delays, run the robot and watch ADC printout to confirm when the thresholds are hit and the expected Reverse/Turn actions occur.

How to configure skills (kebab/hamburger)

  • Open the robot skill window (Sharp IR Collision or Radar).
  • Click the threelines/hamburger icon at the top-right to open Configure or Help.
  • In Configure you’ll set Board Index, Port (ADC7), Condition, Interval, and movement options. Use the Help (?) to open that skill’s manual for exact behavior and ControlCommand names.

Helpful links

Quick recommended starting settings (after you calibrate ADC):

  • Sharp IR Collision: Condition = Greater than [ADC value measured at desired stop distance]
  • Sharp IR Radar: Minimum Distance Before Turn = [ADC value slightly higher than stop, if you want backup+turn sequence]
  • Turn Delay = 300 ms, Reverse Delay = 400 ms (adjust for your robot)
  • Interval = 200-500 ms for responsive behavior (lower interval = more frequent readings)

Next steps I can help with

  • If you run the ADC monitor script above and paste the raw ADC values you saw at e.g. 10 cm, 30 cm, 60 cm and 150 cm, I’ll tell you specific threshold numbers to use for Collision and Radar.
  • If reverse/turn still don’t run after adjusting delays and thresholds, tell me which Movement Panel skill you’re using and its configured ports - I’ll check compatibility and the correct ControlCommand names you may need.

Would you like me to walk through running the ADC calibration and then set the exact thresholds to use?


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.
#2  

So I ran the little Sharp IR calibration script. I came up with a value of "90", that I want use. But, per your recommendation to "Set Minimum Distance Before Turn in the Sharp IR Radar skill, it would only go up to 60. I did increase the delays to 300/400 also. So with the fact that the IR Radar is limited. The robot still only stops when detecting the collision. Is there a new update to this skill?

Author Avatar
PRO
Canada
#3  

Thanks - that helps. A few points and two practical ways to fix this (quick script workaround, and longer-term skill change).

Why the Radar skill is capped at 60 (what’s happening)

  • The Sharp IR Collision skill triggers on the raw ADC value from the sensor (0-255). Because your sensor reading at the distance you want is 90, Collision can stop correctly when ADC7 > 90.
  • The Sharp IR Radar skill’s UI (Minimum Distance Before Turn) in the version you have is limited to a maximum of 60. That 60 is a UI/skill limitation (not an ADC hardware limit). Because Radar’s steering/back-up logic is limited to 60, it will not issue a reverse/turn when ADC > 90 - it will only stop (the Collision skill purposely only stops, it does not steer).
  • Result: Collision stops the robot at your threshold (90). Radar can’t run its avoid maneuver because its configurable threshold cannot reach your calibrated value.

What you can do right now (two options)

Option A - Quick, reliable workaround (recommended)

  • Run a small JavaScript script that watches ADC7 and issues Movement commands (stop, reverse, turn) when ADC7 > your calibrated threshold (90). This bypasses the Radar UI limit and gives you full control of delays and motion.
  • Steps to add and run:
    1. Project Add robot skill Scripts JavaScript (or add a Script control).
    2. Open the script, paste the code below, Save, then Start the script.
  • Example JavaScript (edit threshold, speeds, and times to match your robot):
// Sharp IR avoider - JavaScript for ARC
// Configure these values for your robot
var threshold = 90;        // ADC value you measured
var pollMs = 200;          // how often to check ADC
var reverseSpeed = 150;    // 0-255
var reverseTime = 500;     // ms to reverse
var turnSpeed = 150;       // 0-255
var turnTime = 500;        // ms to turn
var pauseAfterStop = 100;  // ms

print("Sharp IR avoider started. Threshold: " + threshold);

while (true) {
  var v = ADC.get(ADC7); // ADC7 constant (no quotes)
  print("ADC7 = " + v);

  if (v > threshold) {
    print("Obstacle detected (ADC7=" + v + ")");

    // Stop first
    Movement.stop();
    sleep(pauseAfterStop);

    // Reverse for a set time
    Movement.reverse(reverseSpeed, reverseTime);
    sleep(reverseTime + 50);

    // Turn (left). Use Movement.right(...) if you want the other side
    Movement.left(turnSpeed, turnTime);
    sleep(turnTime + 50);

    // Stop and continue
    Movement.stop();
    sleep(300);
  }

  sleep(pollMs);
}

Notes:

  • Make sure a Movement Panel skill is present in the project and supports reverse/left/right. Test those movement commands manually first (click panel or run small Movement.reverse() from a script) to confirm the Movement Panel works as expected.
  • Use larger Reverse/Turn times while tuning so you can observe motion; lower later as needed.

Option B - Longer-term: change the Radar skill or create a custom skill

  • The Radar skill’s numeric limit appears to be a UI limit in the skill code. To raise that limit permanently you’d need the skill updated (an update to the robot skill) or to create a custom robot skill that uses the same Radar logic but allows a higher Minimum Distance value.
  • If you want to go this route, you can:

Quick tests and items to verify

  1. Confirm Movement Panel supports reverse/turn:
    • Manually use Movement Panel buttons or call Movement.reverse(150, 500) from a short script. If the robot doesn’t reverse when issued manually, the problem is the Movement Panel configuration, not the sensor/skill.
  2. Confirm Collision vs Radar capabilities:
    • Sharp IR Collision skill stops movement only (it does not perform reverse/turn). Radar is the one that performs reverse/turn, and its threshold is limited in your skill version (hence no reverse/turn for ADC=90).
  3. If you want, paste:
    • The Movement Panel skill you are using (name/type), and
    • The ARC version and the Sharp IR Radar/Collision skill versions (open the skill kebab menu help/about)
      I’ll tell you whether the Movement skill supports the commands the Radar tries to call and whether there’s an obvious skill update path.

Would you like:

    1. the script tuned and provided as a robot skill file you can import, or
    1. instructions to create a custom Radar skill (I can provide starter code), or
    1. help checking your Movement Panel configuration to ensure reverse/turn are active?

Tell me which you prefer and which Movement Panel you’re using and I’ll proceed.


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.
#4  

Also like to add that I am using the servo Movement Panel to control the drive motors, and that my Bing Speech also can control drive direction.

Author Avatar
PRO
Canada
#5  

Great - thanks for the extra details. Since you’re using the servo Movement Panel (and Bing Speech can also drive the robot), the avoidance logic needs to:

  • use the measured ADC threshold you found (90), and
  • avoid conflicts with other controls (Bing Speech or UI buttons) while the robot is performing the reverse/turn sequence.

Below I give a ready-to-run JavaScript script you can add to your ARC project (fast workaround), explain how it works, give instructions to test Movement Panel commands manually, and show how to make Bing Speech respect the avoider via a small guard in its scripts.

  1. Quick recommended solution - JavaScript avoider script
  • Add it as a Script robot skill: Project -> Add robot skill -> Script -> JavaScript.
  • Paste the code below, adjust the speed/time values to your robot, Save and Start the script.
// Sharp IR avoider (ARC JavaScript)
// Configure these values for your robot:
var threshold = 90;        // ADC threshold you measured
var pollMs = 150;          // how often to check ADC (ms)
var reverseSpeed = 120;    // speed 0-255 used for reverse
var reverseTime = 600;     // ms to reverse
var turnSpeed = 120;       // speed 0-255 used for turn
var turnTime = 800;        // ms to turn
var pauseAfterStop = 120;  // ms pause after stopping before reverse

print("Sharp IR avoider started. Threshold: " + threshold);

// Main loop
while (true) {
  try {
    // If robot is speaking, wait a little (avoid interrupting TTS)
    if (getVar("$IsSpeaking", "false") === "true") {
      sleep(200);
      continue;
    }

    // Read ADC7 (use constant ADC7 - do not quote)
    var v = ADC.get(ADC7); // returns 0 - 255
    print("ADC7 = " + v);

    // If obstacle detected above threshold, run avoidance
    if (v > threshold) {
      print("Obstacle detected (ADC7=" + v + "). Running avoidance.");

      // Set a global flag so other scripts can know we're avoiding
      setVar("$Avoiding", "1");

      // Immediately stop movement
      Movement.stop();
      sleep(pauseAfterStop);

      // Reverse for reverseTime
      Movement.reverse(reverseSpeed, reverseTime);
      sleep(reverseTime + 50);

      // Turn (left). Use Movement.right(...) to turn other direction
      Movement.left(turnSpeed, turnTime);
      sleep(turnTime + 50);

      // Stop and clear avoid flag
      Movement.stop();
      sleep(200);
      setVar("$Avoiding", "0");

      print("Avoidance complete.");
    }
  } catch (e) {
    print("Error in avoider: " + e);
  }

  sleep(pollMs);
}

Notes about the script:

  • It uses ADC.get(ADC7) so it will honor your measured 90 threshold.
  • It sets setVar("$Avoiding","1") while performing the reverse/turn; setVar("$Avoiding","0") afterward - useful if you want other scripts (like speech actions) to skip issuing movement while avoidance runs.
  • Movement.* calls (Movement.stop(), Movement.reverse(), Movement.left()) work with the servo Movement Panel if that panel supports those directions. If your servo Movement Panel uses different names or behavior, we can adapt.
  1. Test Movement Panel manually (important) Before relying on the script, confirm your servo Movement Panel accepts the commands used:
  • Add a tiny test script (or use Script control console) and try:
Movement.stop();
sleep(200);
Movement.reverse(120, 500); // reverse at speed 120 for 500 ms
sleep(600);
Movement.left(120, 500);    // turn left
sleep(600);
Movement.stop();

If the robot physically reverses and turns when you run the test, the panel supports those commands and the avoider script should work. If it does nothing, tell me what happens and which servo Movement Panel variant you added so I can match the API.

  1. Preventing conflicts with Bing Speech Bing Speech in ARC usually runs scripts or controlCommands when words are heard. To avoid conflicts:
  • Edit the movement actions in Bing Speech so they check $Avoiding before setting movement. Example snippet to use in a Bing Speech action (JavaScript form) instead of directly calling Movement.forward():
if (getVar("$Avoiding","0") === "1") {
  print("Ignoring movement command - avoidance in progress");
  return;
}
Movement.forward(180); // or whatever your speech action used
  • If you prefer not to modify every Bing Speech movement action, the avoider script still works - but speech commands may override the Movement commands while avoidance runs. Adding the $Avoiding guard to your speech actions prevents that.
  1. Why Collision stops but Radar didn’t reverse/turn
  • You already discovered the skill UI limit (Radar's Minimum Distance Before Turn capped to 60) - your measured 90 is beyond that UI limit, so the built-in Radar steering logic won't run. The script above bypasses that limitation and implements the reverse/turn behavior at your threshold.
  1. Turning this into a proper robot skill (optional, recommended) If you want this to be integrated like a skill (with settings dialog, kebab menu), I can:
  • provide code you can paste into a new robot skill (Create Robot Skill), or
  • create a ready-to-import skill file and give you instructions to import it. The advantage is a settings UI (threshold, times, speeds, ADC port) and the kebab menu help/config options.
  1. If avoidance still doesn't run Things to verify and tell me if it fails after adding the script:
  • Confirm the script prints ADC values in its Console (so ADC reading is working).
  • Confirm Movement.reverse() and Movement.left() work when you call them manually (section 2).
  • Tell me the exact servo Movement Panel skill name shown in Project -> Robot Skills (so I can verify commands).
  • Let me know if Bing Speech still overrides movement; I’ll show exactly where to insert the $Avoiding guard in your speech actions.

Resources

Next step - which would you like?

    1. I provide a cleaned/parameterized robot skill file you can import, or
    1. I walk you step-by-step to modify your Bing Speech actions to respect $Avoiding, or
    1. Help troubleshoot if Movement.reverse()/left() do not work during manual tests.

Tell me which and paste the output of a short ADC check (run only the top few lines of the avoider printing "ADC7 = ...") and the name of your servo Movement Panel skill if you want me to tailor the skill/script settings.


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.
#6  

This is awesome info and I look forward to trying them.

In the meantime, if a new or updated "Sharp IR Radar skill" can be created to increase the "Minimum Distance Before Turn" beyond the limit of 60, that would also be great.

I did try the first Sharp IR Avoider script. I was successful in getting the robot to reverse and turn, based on your recommended settings previously. But after the turn happens the robot stops which is ok for now, but I'm also looking to have two things happen, the robot will continue forward (while still scanning) and the turns will be based on the robot having enough space to turn in opposite direction, then to continue forward (this may require the help of my Ultrasonic sensors) and all this works with the Navigator skill if possible.

Author Avatar
PRO
Canada
#7  

Nice - thanks for the clear goals. Below I provide:

  • A ready-to-run JavaScript "Enhanced Sharp IR Radar" script you can add as a Script robot skill (no need to wait for an official skill update).
  • What it does (raises the turn threshold, uses your ADC = 90, optional ultrasonic clearance checks, and integration with the Navigator).
  • How to install, configure and test it.
  • Next steps if you want it turned into a full robot skill with a settings UI.

Reminder: to add this as a quick workaround, use Project Add robot skill Script JavaScript, paste the code, Save and Start.

Enhanced Sharp IR Radar (JavaScript)

  • Configurable top section (ADC port, threshold > 60, polling rate, reverse/turn timings, optional ultrasonic ports).
  • Sets and clears $Avoiding so Bing Speech or other scripts can check it.
  • Optionally pauses/resumes Navigator (SetNavigationStatusToPause / SetNavigationStatusToNavigating).
  • Optional ultrasonic clearance checks after turning; tries left then right and resumes forward only when a clear path is found (retries limited).
  • Sends updateScan() to NMS (optional) when an obstacle is detected so Navigator can consume obstacle info.

Paste this into a JavaScript Script robot skill and edit the top settings to match your robot:

// Enhanced Sharp IR Radar - ARC JavaScript
// Configure these variables for your robot:
var adcPort = ADC7;                // ADC port constant (no quotes)
var adcThreshold = 90;             // your measured threshold (90)
var pollMs = 150;                  // how often to check ADC (ms)

var reverseSpeed = 120;            // 0-255
var reverseTime = 600;             // ms to reverse once obstacle detected

var turnSpeed = 130;               // 0-255
var turnTime = 800;                // ms to turn when trying a direction

var forwardResumeSpeed = 180;      // speed to resume forward after avoidance
var pauseAfterStop = 120;          // ms pause after initial stop

// Ultrasonic usage (optional). Set usePing to true and configure ports:
var usePing = true;
var pingTrigger = d0;              // Example digital pins for ultrasonic
var pingEcho = d1;
var pingClearDistance = 40;        // cm threshold considered "clear"

// Navigator integration
var navigatorIntegration = true;   // call SetNavigationStatusToPause and SetNavigationStatusToNavigating
var updateNMS = true;              // call updateScan(distanceCm, confidence, degree)

// Retry behavior
var maxRetries = 3;                // try reverse+turn again up to this many times

// Helper function - safe Ping.read
function readPing(trigger, echo) {
  try {
    var p = Ping.get(trigger, echo);
    return p; // 0-255
  } catch (e) {
    print("Ping.get error: " + e);
    return -1;
  }
}

// Helper to map ADC -> approximate cm (adjust if you want different mapping)
// This is a rough mapping to allow updateScan to send some distance to NMS.
// Map ADC (0-255) to 300..10 cm (invert because higher ADC means closer)
function adcToCm(adc) {
  // Map adc 0 -> 300cm, 255 -> 10cm
  var cm = Utility.map(adc, 0, 255, 300, 10);
  if (cm < 0) cm = 0;
  return Math.round(cm);
}

// Main loop
print("Enhanced Sharp IR Radar started. ADC threshold: " + adcThreshold);
while (true) {
  try {
    // Don't start avoidance while speaking
    if (getVar("$IsSpeaking", "false") == "true") {
      sleep(200);
      continue;
    }

    // Read ADC
    var v = ADC.get(adcPort); // returns 0-255
    print("ADC = " + v);

    // Send to  NMS as a scan (optional)
    if (updateNMS && v > 0) {
      try {
        var distanceCm = adcToCm(v);
        // degree and confidence are optional. We send degree=0 confidence=200 as a rough value.
        updateScan(distanceCm, 200, 0);
      } catch (e) {
        // ignore if  NMS not configured
      }
    }

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

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

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

      var success = false;
      var attempt = 0;
      while (!success && attempt < maxRetries) {
        attempt++;
        // Reverse a bit
        Movement.reverse(reverseSpeed, reverseTime);
        sleep(reverseTime + 50);

        // Try left then right
        var directions = ["left", "right"];
        for (var i = 0; i < directions.length && !success; i++) {
          var dir = directions[i];
          print("Attempting turn: " + dir + " (attempt " + attempt + ")");
          if (dir == "left") {
            Movement.left(turnSpeed, turnTime);
          } else {
            Movement.right(turnSpeed, turnTime);
          }
          sleep(turnTime + 50);
          Movement.stop();
          sleep(120);

          // If using ultrasonic, check forward clearance after turning
          if (usePing) {
            var p = readPing(pingTrigger, pingEcho);
            print("Ping reading after turn: " + p + " cm");
            if (p >= pingClearDistance) {
              success = true;
              break;
            } else {
              // not enough space - return to original heading by turning opposite
              print("Not enough clearance after turning " + dir + " (p=" + p + "). Returning to original.");
              // turn back opposite direction for same time
              if (dir == "left") Movement.right(turnSpeed, turnTime);
              else Movement.left(turnSpeed, turnTime);
              sleep(turnTime + 50);
              Movement.stop();
              sleep(120);
            }
          } else {
            // If no ping available, assume turn is ok and resume
            success = true;
            break;
          }
        } // directions loop

        if (!success) {
          print("No clear direction found on attempt " + attempt + ". Increasing reverse and retrying.");
          // increase reverseTime a bit to back up more and retry
          reverseTime = Math.min(reverseTime + 300, 3000);
        }
      } // retry loop

      if (!success) {
        print("Avoidance failed to find a clear path after " + attempt + " attempts. Resuming cautiously forward.");
      } else {
        print("Clear path found. Resuming forward.");
      }

      // Resume forward for patrol
      Movement.forward(forwardResumeSpeed);
      // small wait so movement actually starts
      sleep(200);

      // Clear flags and resume navigator state
      setVar("$Avoiding", "0");
      if (navigatorIntegration) {
        try { SetNavigationStatusToNavigating(); } catch (e) { print("Nav resume failed: " + e); }
      }

      // Let the robot move a short distance before continuing scanning
      sleep(400);
    } // obstacle detected

  } catch (e) {
    print("EnhancedRadar error: " + e);
  }

  sleep(pollMs);
}

How to install and test

  1. Project Add robot skill Script JavaScript.
  2. Paste the script and edit the top variables:
    • adcPort: ADC7 (no quotes)
    • adcThreshold: 90 (your measured value)
    • If you have an ultrasonic sensor, set usePing = true and enter pingTrigger/pingEcho (d#) pins.
    • Adjust reverse/turn speeds and times to match your robot’s movement power.
  3. Save and Start the script.
  4. Manually test Movement commands first:
    • Use a small test script or console: Movement.reverse(120,500); sleep(600); Movement.left(120,500); sleep(600); Movement.forward(180);
    • Confirm the servo Movement Panel does honor Movement.reverse/left/right (you already saw it worked earlier).
  5. Observe script Console prints to verify ADC readings & checking/avoid steps.
  6. If you use Bing Speech, add the $Avoiding guard to its movement actions so speech won’t conflict:
if (getVar("$Avoiding","0") == "1") { print("Ignoring movement - avoidance active"); return; }
Movement.forward(180);

Notes and tips

  • Radar skill UI limit: the original Sharp IR Radar skill you used has a UI maximum of 60 for its "Minimum Distance Before Turn." That’s a skill UI limit. This script bypasses that restriction.
  • Ultrasonic placement: to check turning clearance reliably you need an ultrasonic pointed forward after a turn (or dual side sensors). The code assumes a forward-facing ping that will measure forward clearance after the turn.
  • Navigator integration: the script calls SetNavigationStatusToPause and SetNavigationStatusToNavigating so the Navigator (NMS Level 1) will be paused while avoidance occurs and then resumed. It also calls updateScan(distanceCm, confidence, degree) with a mapped ADC->cm value so the Navigator can receive obstacle scans. Fine tune mapping (adcToCm) if you want more accurate distances.
  • If your servo Movement Panel uses non-standard commands, tell me the exact Movement Panel skill name as shown in Project Robot Skills and I will adapt the Movement.* calls to it.
  • If you want a polished robot skill with a settings UI and kebab-menu config, I can create that for you (Create robot skill guide: https://synthiam.com/Support/Create-Robot-Skill/Overview). Tell me whether you want:
    • A ready-to-import .skill file (I’ll prepare), or
    • Step-by-step to create it yourself and add UI options.

Follow-ups I need to finish tuning or produce the importable skill

  1. Which exact pins are your ultrasonic sensor(s) on (if any)? Provide trigger/echo pins (e.g., d5/d6).
  2. Which servo Movement Panel skill are you using? (Name shown in Project Robot Skills.)
  3. Do you want the robot to always continue forward after turn or only when the ping says forward is clear?
  4. Would you like me to prepare a .skill file you can import so you can modify settings from the kebab menu?

If you prefer, I can convert the script into a proper robot skill with a configuration UI (threshold, ports, times, sonar settings, Navigator integration checkbox). Which would you like me to do next?


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.
Author Avatar
Unknown Country
#8  

You can make a little bit of passive money without any investment or betting on this platform. Because this app offers promotions with promo codes to earn cash rewards. Moreover, it also offers a welcome and plenty of other bonuses.

y999 game download