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

Basic Motor Torque Control Application

PreviousBasic Motor Position Control ApplicationNextMotor Rotation Based on Joystick Counting

Last updated 23 days ago

In this application, you will learn how to control the torque (current) of a brushed DC motor using the Torque Mode of the SMD Red module. You will input a torque value between -100 and 100, and observe the motor’s response. This control mode is particularly useful for applications that require force feedback, current-limited motion, or haptic interaction.

About Tools and Materials:

()

()

()

()

Step 1: Hardware & Software Overview

Project Key Components

  1. : Drives the DC motor and manages current control via internal PID loop.

  2. : Converts electrical energy into mechanical torque.

Project Key Features

  1. Real-time torque input via command line

  2. Bidirectional torque control (±100)

  3. Live current measurement feedback

  4. PID-based torque regulation

Step 2: Assemble

Getting Started

Hardware Setup

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

Project Wiring Diagram

Step 3: Run & Test

Run the Script

You will be prompted to enter a torque value in the range of -100 to 100. The motor will apply the specified current, and the system will print both the target and actual measured torque.

Codes

from smd.red import *  # Import the SMD Red Python library
from serial.tools.list_ports import comports  # Used to detect available serial (COM) ports
from platform import system  # Used to identify the current operating system
import time  # For time delays

# Function to automatically detect the correct USB port where SMD Red is connected
def USB_Port():
    ports = list(comports())  # Get list of all serial ports
    usb_names = {
        "Windows": ["USB Serial Port"],
        "Linux": ["/dev/ttyUSB"],
        "Darwin": ["/dev/cu."]  # macOS serial devices typically start with /dev/cu.
    }
    os_name = system()
    for port, desc, _ in ports:
        # Return the first matching port based on platform-specific device names
        if any(name in port or name in desc for name in usb_names.get(os_name, [])):
            return port
    return None  # If no matching port is found, return None

# Main function that sets up and runs the torque control loop
def main():
    port = USB_Port()
    if not port:
        print("No port found.")  # Exit if no SMD Red is detected
        return

    master = Master(port)  # Create a Master object to communicate with the SMD Red
    motor_id = 1  # Set the motor ID (default is 1)

    # Attach the SMD Red module and configure it
    master.attach(Red(motor_id))  # Attach the motor
    master.set_shaft_cpr(motor_id, 6533)  # Set encoder resolution (not used in torque mode, but good practice)
    master.set_shaft_rpm(motor_id, 100)  # Set motor's nominal speed (not critical for torque mode)
    
    # Set torque control parameters (PID: P=3.0, I=0.1, D=0.0)
    master.set_control_parameters_torque(motor_id, 3.0, 0.1, 0.0)

    # Enable Torque mode
    master.set_operation_mode(motor_id, OperationMode.Torque)

    # Enable the motor torque output
    master.enable_torque(motor_id, True)

    # Loop to continuously read user input and set torque
    while True:
        try:
            # Read torque input from user
            current = float(input("Enter desired torque current (-100 to 100): "))
            
            # Send torque value to the motor
            master.set_torque(motor_id, current)

            # Read and print actual measured current from the motor
            measured = master.get_torque(motor_id)
            print(f"Set: {current:.2f}, Measured: {measured:.2f}\n")

            time.sleep(0.2)  # Small delay for stability
        except KeyboardInterrupt:
            # On Ctrl+C, safely disable torque and exit the loop
            master.enable_torque(motor_id, False)
            break

# Entry point of the script
if __name__ == "__main__":
    main()
#include <Acrome-SMD.h>
#define BAUDRATE 115200         // Serial communication speed
#define ID 1                    // ID of the SMD Red module

Red master(ID, Serial, BAUDRATE);  // Create SMD Red object
int currentLimit = 100;            // Max allowed current
bool torqueEnabled = true;         // Motor torque status

void setup() {
  Serial.begin(115200);            // Start serial monitor
  master.begin();                  // Initialize communication with SMD Red
  master.setOperationMode(TorqueControl);  // Set operation mode to Torque Control
  master.torqueEnable(1);         // Enable motor torque
}

void loop() {
  // Read joystick X and Y values from module 1
  int joystickX = master.getJoystickX(1);
  int joystickY = master.getJoystickY(1);

  // Adjust current limit based on joystick direction
  if (joystickX > 50 || joystickY > 50) {
    currentLimit++;
  } else if (joystickX < -50 || joystickY < -50) {
    currentLimit--;
  }

  // Send torque setpoint to motor
  master.setpoint(3, currentLimit - 50);  // Adjust for offset
  int current = master.getTorque();       // Read current draw from motor

  // Debug output
  Serial.print("Motor Current: "); Serial.println(current);
  Serial.print("Current Limit: "); Serial.println(currentLimit);

  // Safety: Disable motor if current exceeds limit
  if (current >= currentLimit) {
    master.torqueEnable(0);  // Disable torque
    torqueEnabled = false;
    Serial.println("Motor disabled due to overcurrent!");
  }

  delay(100);  // Small delay for stability
}

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

Connect the 100 RPM with Encoder to the motor ports of the SMD Red.

SMD Red
Purchase Here
SMD USB Gateway
Purchase Here
Arduino Gateway Module
Purchase Here
BDC Motor
Purchase Here
SMD Red
BDC Motor
USB Gateway Module
Arduino Gateway Module
BDC Motor