Pan-Tilt with Joystick Module

The โ€œPan-Tilt Control Systemโ€ project is a hardware and software endeavor that integrates two servo motors, two SMD servo modules, a joystick module, and an SMD Motor Driver to create a flexible and responsive control mechanism. This project enables users to manipulate the position of a connected device in both horizontal (pan) and vertical (tilt) axes using the joystick module, allowing for precise and intuitive control over the deviceโ€™s orientation.

Project Media:

Project Key Components:

  1. SMD Motor Driver:

    • The SMD Motor Driver serves as the interface between the Python script and the components, interpreting commands to control the movement of the RGB LED and the activation of the Buzzer.

  2. SMD Servo Module:

    • These modules serve as interfaces between the Python script and the servo motors, translating control signals to precise movements in the pan and tilt axes.

  3. Joystick Module:

    • The joystick module provides intuitive manual control inputs, allowing users to dictate the desired pan and tilt positions of the connected device.

  4. Python Script:

    • The Python script is the central component of the application. It communicates with the Joystick Module and controls the Servo Motors through the SMD Servo Module and the SMD Motor Driver.

Project Key Features:

  1. Flexible Position Control: The Pan-Tilt system provides users with the capability to dynamically adjust the orientation of the connected device in both the horizontal and vertical planes, offering enhanced flexibility in positioning.

  2. Intuitive Manual Control: Through the integration of the joystick module, users can intuitively dictate the pan and tilt angles, allowing for precise manual control over the system.

Project Wiring Diagram:

Getting Started:

  1. Hardware Setup:

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

    • Connect the SMD servo modules to the servo motors, ensuring secure and accurate connections.

    • Integrate the joystick module into the setup, establishing the necessary input interface for controlling the pan-tilt system.

  2. Run the Application:

    • Execute the Python script, initiating the "Pan-Tilt" application.

    • Manipulate the joystick module to observe real-time changes in the orientation of the connected device, verifying the functionality of the pan-tilt mechanism.

  3. Customize Security Thresholds:

    • Adjust the control settings within the Python script to tailor the responsiveness and range of motion for the pan and tilt axes.

    • Experiment with different input interfaces or control mechanisms to adapt the system to specific application requirements.

Project Codes:

from smd.red import*
import numpy as np

port  = "COM5"

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

print(m.get_driver_info(0))
print(m.scan_modules(0))


#Indefinite loop for motin
while True:
    a = m.get_joystick(0,1) #Read the instantaneous joystick position to variable a
    #print(a)  #for debug

    print(a)
    if(a == None):
        print('smd baglantisi :' , m.get_driver_info(0))
   
    
    else:
        a[0] = a[0] + 20
        if a[0] < 0:
            a[0] = np.interp(a[0], (-80, 0), (-100, 0))
        else:
            a[0] = np.interp(a[0], (0,120), (0, 100))


        print(a[1])
        print(a[0])
        m.set_servo(0,1,int(np.interp(a[0], (-100, 100), (0, 180)))) #set the servo angle for pan axis
        m.set_servo(0,3,int(np.interp(a[1], (-100, 100), (0, 180)))) #set the servo angle for tilt axis


Last updated