Distance Auto Stop

This project showcases a dynamic motor control system utilizing the ACROME SMD platform. The project integrates hardware, real-time processing, and dynamic scaling to achieve precision control. The goal is to create a motorized system where the speed decreases as the motor approaches an object and stops completely when it gets very close. This is achieved using distance measurements and velocity interpolation.

Key Features

  1. Distance-Based Motor Control The motor dynamically adjusts its speed based on proximity.

  2. Smooth Interpolation The velocity decreases gradually instead of abrupt stops, ensuring smoother operation.

  3. Real-Time Feedback The system logs current distance and velocity values for monitoring.

Hardware Components

  1. ACROME SMD Red Platform The ACROME SMD platform serves as the control hub, interfacing with the motor and reading sensor data.

  2. Ultrasonic Distance Sensor A distance sensor is used to measure the object's position in real-time.

  3. Motor The motor is controlled using velocity commands, allowing for smooth acceleration and deceleration.

Getting Started

  1. Hardware Setup

  2. Run the Script

    • Run the script on your computer. This will establish communication with the SMD and initiate control of the Ultrasonic Distance Sensor.

from smd.red import *
from serial.tools.list_ports import comports
from platform import system

def USB_Port():
	ports = list(comports())
	usb_names = {
		"Windows": ["USB Serial Port"],
		"Linux": ["/dev/ttyUSB"],
		"Darwin": [
			"/dev/tty.usbserial",
			"/dev/tty.usbmodem",
			"/dev/tty.SLAB_USBtoUART",
			"/dev/tty.wchusbserial",
			"/dev/cu.usbserial",
            		"/dev/cu.usbmodem",
			"/dev/cu.SLAB_USBtoUART",
			"/dev/cu.wchusbserial",
		]
	}
	
	os_name = system()
	if ports:
		for port, desc, hwid in sorted(ports):
			if any(name in port or name in desc for name in usb_names.get(os_name, [])):
				return port
		print("Current ports:")
		for port, desc, hwid in ports:
			print(f"Port: {port}, Description: {desc}, Hardware ID: {hwid}")
	else:
		print("No port found")
	return None
	
port = USB_Port()
if port is None:
    print("No suitable USB port found.")
    exit(1)

m = Master(port)
m.attach(Red(0))

middle_distance = 20
near_distance = 5
max_speed = 100
m.set_shaft_cpr(0,6533)
m.set_shaft_rpm(0,100)
m.enable_torque(0,1)

while True:
    distance = m.get_distance(0,1)

    if distance < near_distance:
        m.set_duty_cycle(0, 0)
        print("Stopped")
    elif near_distance <= distance < middle_distance:
        speed = max_speed * (distance - near_distance) / (middle_distance - near_distance)
        speed = max(10, speed)
        m.set_duty_cycle(0, speed)
        print("Running at speed:", speed)
    else:
        m.set_duty_cycle(0, max_speed)
        print("Running at max speed")

Conclusion

This project highlights the ACROME SMD Red platform's versatility in creating advanced motor control systems. By combining real-time distance sensing with velocity interpolation, it provides a robust solution for a range of applications.

Last updated