Acrome-SMD Docs
All Acrome ProductsReferencesBlogCase StudiesContact Us
  • ACROME SMD
  • Electronics
    • 🔴SMD Red
      • Troubleshooting Guide
    • 🔵SMD Blue
    • 🟢SMD Green
    • Gateway Modules
      • Arduino Gateway Module
      • USB Gateway Module
    • Electrical Motors
      • Brushed DC Motors (BDC)
      • Stepper DC Motors (SDC)
      • Brushless DC Motor (BLDC)
      • Linear Actuator with Feedback – 75 lbs
    • Add-on Modules
      • Ambient Light Sensor Module
      • Button Module
      • Buzzer Module
      • IMU Module
      • Joystick Module
      • Potentiometer Module
      • Reflectance Sensor Module
      • RGB LED Module
      • Servo Module
      • Ultrasonic Distance Sensor Module
  • SMD Kits
    • Starter Kit
      • What You Can Build
    • Education Kit
      • What You Can Build
    • Motion Kit
      • What You Can Build
  • Software
    • Libraries
      • Python Library
      • Arduino Library
      • Java Library
      • Matlab Library
    • SMD UI
    • SMD Blockly
      • Introducing Customized Blockly Blocks
  • SMD Applications
    • Basics
      • Blink
      • Action - Reaction
      • Autonomous Lighting
      • Smart Doorbell
      • Security System
      • Distance Buzzer Warning
      • Distance Auto Stop
      • Smart Light Control
    • Interactive
      • Automatic Trash Bin
      • Radar
      • Chrome Dino Game Player
      • Play Chrome Dino Game With Joystick
      • Snake Game With Joystick
      • Pan-Tilt with Joystick Module
      • Joystick Mouse Control
      • Rev Up the Engine
      • Motor Rotation Based on Turn Input Value
      • Basic Motor Speed Control Application
      • Basic Motor Control Application Using PWM Input
      • Basic Motor Position Control Application
      • Basic Motor Torque Control Application
      • Motor Rotation Based on Joystick Counting
    • Robotics
      • Differential Robot Projects
      • Mouse Cursor Tracker Motion Robot
      • Waypoint tracker robot
      • Braitenberg Robot
      • Line-Follower Robot
      • Teleoperation Robot
      • Obstacle Avoidance Robot
      • ESP32 Wireless Controlled Mobile Robot
  • AI
    • Object Tracking Robot
    • Groq Chatbot-Controlled Robot
  • ROS
    • Teleoperation Robot with ROS
  • Mechanics
    • Building Set
      • Plates
        • 2x2 Plate Package
        • 2x3 120° Plate Package
        • 3x3 Plate Package
        • 3x5 Plate Package
        • 3x9 Plate Package
        • 11x19 Plate
        • 9x19 Plate
        • 5x19 Plate
        • 3x19 Plate
        • 9x11 Plate
        • 5x13 Plate
      • Joints
        • 60° Joint Package
        • 90° Joint Package
        • 120° Joint Package
        • Slot Joint M2 Package
        • Slot Joint M3 Package
        • U Joint Package
      • Mounts
        • Add-on Mount Package
        • Motor L Mount Package
        • Pan-Tilt Package
      • Wheels
        • Ball Wheel Package
        • Caster Wheel Package
        • Wheel Package
      • Cables
        • Power Cable 10 cm Package
        • Power Cable 20 cm Package
        • Power Cable 35 cm Package
        • RJ-11 Cable 7.5 cm Package
        • RJ-11 Cable 20 cm Package
        • RJ-11 Cable 35 cm Package
        • RJ-45 Cable 7.5 cm Package
        • RJ-45 Cable 20 cm Package
        • RJ-45 Cable 35 cm Package
      • Fasteners
        • M2x5 Allen Hex Screw Package
        • M3x6 Allen Hex Screw Package
        • M3x8 Allen Hex Screw Package
        • M3 Hex Nut Package
  • Help
    • Manual
    • Shops
    • Reach Us
Powered by GitBook
On this page
  • Step 1: Hardware & Software Overview
  • Step 2: Assemble
  • Step 3: Run & Test
  • Codes
  1. SMD Applications
  2. Robotics

Teleoperation Robot

PreviousLine-Follower RobotNextObstacle Avoidance Robot

Last updated 15 days ago

The Teleoperation Robot is a differential drive robotic system that allows remote control via a keyboard interface. This project provides a Python-based teleoperation system, enabling users to control the robot’s movement in real-time. The robot is equipped with two independent motors and utilizes a PID controller for smooth and precise motion control.

About Tools and Materials:

2x ()

()

()

2x ()

Step 1: Hardware & Software Overview

Project Key Components

  1. The SMD acts as a bridge between the script and the modules. It is responsible for interpreting the commands sent by the script and translating them into actions that read input from the and meanwhile, actuate the motor for the continuous reading of the script.

  2. The 100 RPM BDC Motor with Encoder is used to rotate the radar mechanism in a full circle. The user can precisely control the motor and get the position through the built-in encoder.

Key Features:

• Real-time teleoperation via keyboard inputs.

• PID-based motor control for smooth and stable movement.

• Cross-platform support (Windows, Linux, macOS).

• USB serial communication for motor control.

• Differential drive mechanism for precise navigation.

• Emergency stop function to halt movement immediately.

Step 2: Assemble

  1. Hardware Setup

    • Make sure that the SMD is powered and all connections are correct.

Project Wiring diagram

Step 3: Run & Test

1. Connect the Robot • Ensure that the robot is powered on and all connections are secure. • The USB connection should be properly established before running the script.

2. Run the Teleoperation Script • Open a terminal or command prompt. • Navigate to the directory where the script is located. •Run the Code.

3. Control the Robot Once the script is running, use the following keyboard controls to operate the robot: Key Action: W: Move forward S: Move backward A: Turn left D: Turn right Q: Quit the program • The script initializes a PID controller for both motors to ensure smooth operation. • It automatically detects the correct USB port for communication with the SMD module.

4. Verify Motion and Response • When pressing the movement keys, observe the robot’s response. • Check if the movements are smooth and consistent. • If any delays or unexpected behaviors occur, review the USB connection and the PID parameters.

5. Check for Errors • If the script fails to detect the USB port, it will display No suitable port found. Exiting... • Any communication or motor control issues will be printed as error messages in the terminal.

6. Stopping and Exiting • When pressing Q, the script will stop the motors and disable torque before exiting safely. • If the robot does not stop as expected, manually disconnect the power or reset the system.

Codes

from pynput import keyboard
import time
from smd.red import *
from serial.tools.list_ports import comports
from platform import system
class PIDController:
    def __init__(self, kp, ki, kd):
        self.kp = kp
        self.ki = ki
        self.kd = kd
        self.previous_error = 0
        self.integral = 0

    def calculate(self, error, delta_time):
        self.integral += error * delta_time
        derivative = (error - self.previous_error) / delta_time if delta_time > 0 else 0
        output = (self.kp * error) + (self.ki * self.integral) + (self.kd * derivative)
        self.previous_error = error
        return max(min(output, 100), -100)  
    
    
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",
        ]
    }
    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, [])):
                print("Connected!")
                return port
        print("Available ports:")
        for port, desc, hwid in ports:
            print(f"Port: {port}, Description: {desc}, HWID: {hwid}")
    else:
        print("No ports detected!")
    return None


def teleoperate_smd():
    print("Use W/A/S/D to control the robot. Press Q to quit.")

    port = USB_Port()
    if not port:
        print("No suitable port found. Exiting...")
        return

    try:
        smd = Master(port)
        smd.attach(Red(0))  # Left motor (ID 0)
        smd.attach(Red(1))  # Right motor (ID 1)

        smd.enable_torque(0, 1)
        smd.enable_torque(1, 1)

        left_pid = PIDController(kp=24.96, ki=0.00, kd=19.10)
        right_pid = PIDController(kp=46.97, ki=0.00, kd=18.96)

        base_speed = 100  
        turning_speed = 100  # Speed for turning
        last_time = time.time()

        def on_press(key):
            nonlocal last_time

            try:
                # Calculate time difference
                current_time = time.time()
                delta_time = current_time - last_time
                last_time = current_time

                if hasattr(key, 'char'):
                    if key.char == 'w':  # Move forward
                        print("Move Forward")
                        error = base_speed
                        left_speed = left_pid.calculate(error, delta_time)
                        right_speed = right_pid.calculate(error, delta_time)
                        # Send commands to both motors simultaneously
                        smd.set_duty_cycle(0, -left_speed)  # Left motor forward
                        smd.set_duty_cycle(1, right_speed)  # Right motor forward
                    elif key.char == 's':  # Move backward
                        print("Move Backward")
                        error = -base_speed
                        left_speed = left_pid.calculate(error, delta_time)
                        right_speed = right_pid.calculate(error, delta_time)
                        # Send commands to both motors simultaneously
                        smd.set_duty_cycle(0, -left_speed)  # Left motor backward
                        smd.set_duty_cycle(1, right_speed)  # Right motor backward
                    elif key.char == 'a':  # Turn left
                        print("Turn Left")
                        # Send commands to both motors simultaneously
                        smd.set_duty_cycle(0, 0)  # Left motor stopped
                        smd.set_duty_cycle(1, turning_speed)  # Right motor forward
                    elif key.char == 'd':  # Turn right
                        print("Turn Right")
                        # Send commands to both motors simultaneously
                        smd.set_duty_cycle(0, -turning_speed)  # Left motor forward
                        smd.set_duty_cycle(1, 0)  # Right motor stopped
                    elif key.char == 'q':  # Quit
                        print("Exiting...")
                        return False
            except AttributeError:
                pass

        def on_release(key):
            # Stop both motors simultaneously
            smd.set_duty_cycle(0, 0)
            smd.set_duty_cycle(1, 0)

        # Start keyboard listener
        with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
            listener.join()

    except Exception as e:
        print(f"Error: {e}")
    finally:
        # Stop both motors simultaneously during cleanup
        smd.set_duty_cycle(0, 0)
        smd.set_duty_cycle(1, 0)
        smd.enable_torque(0, 0)
        smd.enable_torque(1, 0)
        smd.close()
        print("SMD connection closed.")

teleoperate_smd()

Connect the SMD to the PC or Arduino board using or .

Connect the 100 RPM with Encoder to the motor ports of the SMD using an RJ-45 cable.

SMD Red
Purchase Here
SMD USB Gateway
Purchase Here
Arduino Gateway Module
Purchase Here
BDC Motor
Purchase Here
SMD
Ultrasonic Distance Sensor Module
BDC Motor
USB Gateway Module
Arduino Gateway Module
BDC Motor