Move Robot Car

                                                    Move Robot Car


The test program 


home/john/Adeept_4WD_Smart_Car_for_RPi/Server/Server_OrdinaryWheel 


Worked


https://storage.googleapis.com/uconnstamford2025/Adeept/Lesson%2010%20Control%20the%20DC%20Motor%20to%20Work%20for%20Ordinary%20Wheels.pdf


import time

import Motor_Ordinary as mo


def forward(speed=60):

    mo.Motor(1, 1, speed)

    mo.Motor(2, 1, speed)

    mo.Motor(3, 1, speed)

    mo.Motor(4, 1, speed)


def turn_left(speed=60):

    # Left side backward (-1), Right side forward (1)

    mo.Motor(1, -1, speed)

    mo.Motor(2, -1, speed)

    mo.Motor(3, 1, speed)

    mo.Motor(4, 1, speed)


def turn_right(speed=60):

    # Left side forward (1), Right side backward (-1)

    mo.Motor(1, 1, speed)

    mo.Motor(2, 1, speed)

    mo.Motor(3, -1, speed)

    mo.Motor(4, -1, speed)


try:

    print("Driving forward...")

    forward(60)

    time.sleep(2)


    mo.motorStop()

    time.sleep(0.5)


    print("Turning left...")

    turn_left(60)

    time.sleep(1)


    mo.motorStop()

    time.sleep(0.5)


    print("Turning right...")

    turn_right(60)

    time.sleep(1)


    print("Done.")

except KeyboardInterrupt:

    pass

finally:

    mo.destroy()



Run it from your terminal:

Bash

python drive_test.py

Quick Adjustments

  • If it turns the wrong way (left instead of right): Swap the 1 and -1 values inside turn_left() and turn_right().

  • If only one side spins or it spins in place when going forward: Check which channels (1–4) correspond to your Left vs. Right wheels and update the channel numbers in turn_left() and turn_right() accordingly.

  • Speed: 60 (60% power) is a safe starting speed for indoor testing; you can adjust it anywhere from 0 to 100.

change program to only move forward 1 foot 


Because the standard TT DC motors on the Adeept 4WD Smart Car do not have wheel encoders, distance is controlled by speed and time.

Update drive_test.py with the following code, which removes the turns and drives forward for a short, calibrated duration:

Python

import time

import Motor_Ordinary as mo


SPEED = 60       # Power (0-100)

DURATION = 0.8   # Seconds (adjust this to calibrate for 1 foot)


def forward(speed):

    mo.Motor(1, 1, speed)

    mo.Motor(2, 1, speed)

    mo.Motor(3, 1, speed)

    mo.Motor(4, 1, speed)


try:

    print("Driving forward 1 foot...")

    forward(SPEED)

    time.sleep(DURATION)

    mo.motorStop()

    print("Done.")

except KeyboardInterrupt:

    pass

finally:

    mo.destroy()


No comments:

Post a Comment

3D Printing

  I wanted to let you know that the lab's 3D printers, the Prusas and the Flashforge are now available for printing. Please keep in mind...