Thumbnail

Ultrasonic Collision Script

by Synthiam Inc.

Use an ultrasonic distance sensor to execute a script when an object is detected within range of the sensor.

Requires ARC v1 (Updated 1/29/2024)

How to add the Ultrasonic Collision Script robot skill

  1. Load the most recent release of ARC (Get ARC).
  2. Press the Project tab from the top menu bar in ARC.
  3. Press Add Robot Skill from the button ribbon bar in ARC.
  4. Choose the Ultrasonic category tab.
  5. Press the Ultrasonic Collision Script icon to add the robot skill to your project.

Don't have a robot yet?

Follow the Getting Started Guide to build a robot and use the Ultrasonic Collision Script robot skill.

How to use the Ultrasonic Collision Script robot skill

This skill enables your robot to use an ultrasonic distance sensor to detect objects within a specified range. When an object is detected, a user-defined script is executed. This skill is particularly useful for navigation, obstacle avoidance, and interactive applications.

Features

  • Object Detection: Uses an ultrasonic distance sensor to detect objects.
  • Adjustable Detection Interval: Set the frequency of detection checks.
  • Minimum Distance Setting: Specify the minimum distance for object detection before executing the script.
  • Custom Script Execution: Run a user-defined script upon object detection.
  • Movement-Based Trigger: Option to trigger the script only when the robot is moving forward.

User-inserted image

Application Scenarios

  • Obstacle Avoidance: Use this skill to stop or navigate around obstacles.
  • Interactive Robots: Trigger interactions when someone approaches the robot.

Skill Settings

User-inserted image

  1. Detection Interval: Set the interval (in milliseconds) for how often the sensor checks for objects.
  2. Minimum Detection Distance: Enter the minimum distance (in centimeters) for the sensor to trigger the script.
  3. Script: Input the script you want to execute when an object is detected. If an object is detected, the detection will not resume until the script has been completed. You may have a script that loops to navigate, such as the example below. If your script gets stuck in a loop, press the Config button on the robot skill to stop it.
  4. Movement Check: Enable this checkbox if you want the script to trigger only when the robot is moving forward.

Usage

  • Start Detection: Once configured, start the skill to begin object detection.
  • Monitoring: The skill will continuously monitor for objects based on your interval setting.
  • Script Execution: The entered script will execute when an object is detected within the specified range. The script will only execute during forward movement if the movement check is enabled.

Example Script

This example JavaScript script is a practical example of integrating the Ultrasonic Distance Sensor Skill with your robot's movement and audio capabilities in Synthiam ARC. It demonstrates a scenario where the robot stops and changes its course upon detecting an object within a specific range. This script is ideal for applications requiring obstacle avoidance and interactive navigation.

Functionality

  • Immediate Stop: The robot halts any ongoing movement upon detecting an object.
  • Audio Feedback: The robot audibly announces when it detects an obstacle and when the path is clear.
  • Reverse Movement: On detection of an object, the robot reverses for a short duration.
  • Careful Navigation: The robot then slows down and turns right, continuously checking for obstacles using the ultrasonic sensor.

Key Steps

  1. Stop Movement: Initially, the script stops any movement to assess the situation.
  2. Audio Alert: The robot informs about the detected object through speech.
  3. Reverse and Assess: The robot reverses for 2 seconds, then stops to reassess.
  4. Turn and Navigate: It sets a slower speed, begins turning right, and continuously checks the distance using the ultrasonic sensor.
  5. Path Clearance: Once a clear path is detected (distance greater than 20cm), the robot stops turning, announces that the path is clear, and the script terminates.

Script Usage

This script can be used in various scenarios, such as:

  • Navigating in Crowded Environments: Where constant obstacle detection and avoidance are crucial.
  • Interactive Applications: Where the robot needs to respond to the presence of objects or people.

Note: Modify and adapt this script according to your robot configuration and requirements.*

// Stop the robot from moving
Movement.stop();

// Speak and let us know what's going on
Audio.say("I see an object");

// Reverse for 2 seconds
Movement.reverse();
sleep(2000);

Movement.stop();

// Set a slow speed for turning
Movement.setSpeed(50);

// Begin turning to the right
Movement.right();

while (true) {

  // Get the latest value from the ultrasonic sensor
  var distance = Ping.get(d0, d1);

  // Check if the path is clear
  if (distance > 20) {
  
    // Stop turning
    Movement.stop();
    
    // Let us know the path is clear by speaking
    Audio.say("Path is clear");
    
    // Exit the script
    halt();  
  }
  
  // Pause while we are turning
  sleep(200);
}


Troubleshooting

  • Sensor Not Detecting: Ensure the sensor is properly connected and configured in Synthiam ARC.
  • Script Not Executing: Check the script for errors and ensure the minimum distance is set correctly.
  • Intermittent Triggering: Adjust the detection interval for more consistent performance.
  • Script stuck in a loop: If your script gets stuck in a loop, press the Config button on the robot skill to stop it.

ARC Pro

Upgrade to ARC Pro

Join the ARC Pro community and gain access to a wealth of resources and support, ensuring your robot's success.

PRO
USA
#2  

Hey there-

Not seeing this skill to install.

What am I doing wrong?

User-inserted image

PRO
USA
#3   — Edited

User-inserted image

I had to do a manual install, I have it added.