Acrome-SMD Docs
All Acrome ProductsReferencesBlogCase StudiesContact Us
  • ACROME SMD
  • Electronics
    • 🔴SMD Red
      • Coding Guide
      • Robot with Raspberry Pi Setup Guide
      • Robot with Arduino Setup Guide
      • 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
    • 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. Interactive

Pan-Tilt with Joystick Module

PreviousSnake Game With JoystickNextJoystick Mouse Control

Last updated 3 months ago

The Pan-Tilt Control System is a project that is widely used in many areas. It contains the , two servo motors, two . The two servo motors provide a 2 DOF movement to the mechanism, one is horizontal (pan) and the other one is vertical (tilt) DOFs. These movement axes can be controlled through the . A webcam or a can be connected to the Pan-Tilt Control System.

About Tools and Materials:

()

Step 1: Hardware & Software Overview

Project Key Components

Project Key Features

  • Flexible Position Control The Pan-Tilt Control System allows the user to control the mounted object in a flexible vay due to two servo motors and the precise motor driving capability of the SMD.

Step 2: Assemble

Getting Started

  1. Hardware Setup

    • Attach the servo motors to the designated axes for pan (horizontal) and tilt (vertical) movements.

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

Project Wiring Diagram

Step 3: Run & Test

  1. Run the Script

    • Execute the script, initiating the Pan-Tilt Control System application.

    • Move the joystick to see how the system works when different axes of joystick are used.

Codes

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

baudrate = 115200          # Baud rate of communication
ID = 0                     # ID of the SMD
joystick_id = 5            # ID of the joystick module
servo_pan_id = 5           # ID of the pan servo
servo_tilt_id = 5          # ID of the tilt servo


def USB_Port():
    """
    Scans and identifies a compatible USB port for the current operating system.

    Returns:
        str: The detected USB port or None if no suitable port is found.
    """
    # Get a list of available ports
    ports = list(comports())

    # Known USB port names for different operating systems
    usb_names = {
        "Windows": ["USB Serial Port"],  # Names specific to Windows
        "Linux": ["/dev/ttyUSB"],        # Names specific to Linux
        "Darwin": [                      # Names specific to macOS
            "/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",
        ]
    }

    # Detect the operating system
    os_name = system()
    print(f"Operating System: {os_name}")

    if ports:
        for port in ports:
            # Check if the port matches any known USB names
            if any(name in port.device or name in port.description for name in usb_names.get(os_name, [])):
                print(f"USB device detected on port: {port.device}")
                return port.device  # Return the first matching port
        # If no suitable port is found, print the list of available ports
        print("No suitable USB device found. Available ports:")
        for port in ports:
            print(f"Port: {port.device}, Description: {port.description}, HWID: {port.hwid}")
    else:
        print("No ports detected!")
    return None


try:
    # Find and initialize the USB port
    SerialPort = USB_Port()
    if not SerialPort:
        raise Exception("No compatible USB port found. Please check your connection.")

    # Initialize the SMD module
    master = Master(SerialPort, baudrate)       # Defines the USB gateway module
    master.attach(Red(ID))                      # Gives access to the SMD of specified ID
    print("Driver Info:", master.get_driver_info(ID))  # Print driver information
    print("Connected Modules:", master.scan_modules(ID))  # Scan and display connected modules

    # Main loop for joystick control
    while True:
        joystick_position = master.get_joystick(ID, joystick_id)  # Read joystick position
        if joystick_position is None:
            print("SMD connection issue:", master.get_driver_info(ID))
        else:
            # Adjust joystick X-axis value
            joystick_position[0] += 20
            if joystick_position[0] < 0:
                joystick_position[0] = np.interp(joystick_position[0], (-80, 0), (-100, 0))
            else:
                joystick_position[0] = np.interp(joystick_position[0], (0, 120), (0, 100))

            # Print joystick positions for debugging
            print("Joystick Y:", joystick_position[1])
            print("Joystick X:", joystick_position[0])

            # Set servo angles based on joystick position
            pan_angle = int(np.interp(joystick_position[0], (-100, 100), (0, 180)))
            tilt_angle = int(np.interp(joystick_position[1], (-100, 100), (0, 180)))
            master.set_servo(ID, servo_pan_id, pan_angle)  # Pan axis servo control
            master.set_servo(ID, servo_tilt_id, tilt_angle)  # Tilt axis servo control

except Exception as e:
    print(f"Error: {e}")

()

2x ()

()

()

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 control the two servo motors by the in 2 different axes.

The Servo Module drives the servo motor that is connected to it. It can be controlled through the .

The allows the user to control the two servo motors, thus, two axes simultaneously.

The enhances the Pan-Tilt System by enabling real-time object detection and tracking. Mounted on the tilt axis, it measures distances and can trigger alerts for nearby obstacles.

The SMD library is at the heart of the application. It communicates with the SMD using a specific communication protocol, sending commands to read the and send the servo motor control inputs to the Servo Modules.

Intuitive Manual Control Through the , the users can intuitively control the 2 DOF Pan-Tilt Control System.

Connect the SMD to the PC or Arduino board using .

Connect the and two to the SMD using an RJ-45 cable.

Connect the each servo motor to the .

SMD USB Gateway
Purchase Here
Servo Module
Purchase Here
Joystick Module
Purchase Here
Ultrasonic Distance Sensor
Purchase Here
SMD
Joystick Module
Servo Modules
Servo Module
SMD libraries
Joystick Module
Joystick Module
Ultrasonic Distance Sensor
Ultrasonic Distance Sensor
SMD Libraries
Joystick Module
Joystick Module
USB Gateway Module
Joystick Module
Servo Modules
Servo Modules
Joystick Module
Servo Modules
Joystick Module
Ultrasonic Distance Sensor Module
SMD Red
Purchase Here