Operating the Robot car

                                  Operating the Robot car 


To operate the Robot car we need top make sure that the machine is connected to the internet.


At UCONN before we can connect to the internet we need to click on accept from the browser.


Before a machine connects to the internet it needs an ip address.


IP addresses can either be permanently set or use DHCP to obtain an address.


DHCP stands for Dynamic Host Configuration Protocol. It is a network management protocol used to automatically assign an IP address and other network configuration parameters (such as the subnet mask, default gateway, and DNS servers) to each device on a network so they can communicate with other networks and the internet.

How DHCP Works (The DORA Process)

When a device connects to a network, it uses a four-step process known as DORA to lease its network settings from a DHCP server (typically your home router or a corporate network server):

Discover (DHCPDISCOVER): The new device broadcasts a message onto the network asking, "Is there a DHCP server out there?"

Offer (DHCPOFFER): The DHCP server hears the request and responds with an IP address "offer" from its pool of available addresses.

Request (DHCPREQUEST): The device responds, letting the server know it accepts that specific IP address.

Acknowledgment (DHCPACK): The server sends a final acknowledgment containing the lease duration and configuration details, officially assigning the IP address to the device.

Why DHCP Matters

Automation: Without DHCP, every single device (laptops, phones, smart TVs, IoT devices) would need a static IP address manually configured by hand, which would be tedious and prone to human error (like IP address conflicts).

Efficiency: IP addresses are leased for a set period. If a device disconnects from the network and doesn't return, its IP address automatically returns to the pool to be reused by someone else.

DHCP vs. Static IP

Dynamic IP (DHCP): Automatically assigned and changes periodically. Ideal for everyday consumer devices, smartphones, and guest laptops.

Static IP: Manually configured and permanent. Ideal for network infrastructure (like routers, switches, and printers) or servers (like databases and web servers) that other devices need to find consistently.


To ensure that we can connect to a wireless network we would need to connect our Raspberry PI to local I/O devices using ports



The HDMI port will connect to a monitor


One USB port connects to mouse


Second USB port connects to a keyboard


Power cable connected 


Micro sd card configured with Linux and Adeept python code


User adeept password engr1166

When machine is up need to configure the network connection


Left hand side of screen looks like waves


When we are connected need to get the ipaddress


adeept@raspberrypi:~ $ hostname -I

192.168.1.92 2600:480a:33b1:1e00::8c58 2600:480a:33b1:1e00:f85d:cc01:46cd:d3ec

adeept@raspberrypi:~ $ 


Once connected we can use putty to connect.



Download on local machine


https://putty.org/index.html


Then install



Once Putty is installed we bring up the application


Use ipaddress of Raspberry PI to connect


For one Raspberry PI the User adeept password engr1166


have adeept libraries loaded on a raspberry pi now I want to get the smartcar 4WD to move straight 2 feet 


To make your Adeept 4WD smart car move straight for a specific distance (like 2 feet), you will typically use a Python script that calls the motor functions provided by the Adeept libraries, paired with a timed delay (time.sleep()).

Because standard Adeept kits rely on DC motors without built-in high-precision encoders, distance is controlled by timing how long the motors run.

Here is how to write a simple script to accomplish this.

Step-by-Step Implementation

Open your terminal or SSH into your Raspberry Pi.

Navigate to your project directory where the Adeept server or motor control files reside (for example, cd Adeept_4WD_Smart_Car_Kit_for_RPi/server or similar depending on your exact kit version).

$ cd 

Adeept_4WD_Smart_Car_for_RPi/

$ ls

Client    initPosServos.py  Server                  setup_OrdinaryWheels.py

Examples  README.md         setup_MecanumWheels.py  wifi_hotspot_manager.sh

 $ cd Server/

$ ls

Server_MecanumWheels  Server_OrdinaryWheels

$ cd Server_OrdinaryWheels/

$ sudo python -m pip install --break-system-packages 'gpiod>=2.2.2,<3' 'Adafruit-Blinka-Raspberry-Pi-PWM>=1.0.2' 'rpi_ws281x>=4.0.0'

Command Breakdown


sudo: Runs the command with root (administrator) privileges, which is required to write files into system-wide Python directories (/usr/local/lib/...).


python -m pip: Tells the Python interpreter to execute the package manager (pip) as an active module. Using -m ensures you install packages into the exact version of Python currently running.


install: The core pip command used to download and set up Python packages from the Python Package Index (PyPI).


--break-system-packages: An override flag required on modern Raspberry Pi OS versions (Debian Bookworm/Trixie). It bypasses the PEP 668 safety lock that normally blocks global pip installations to protect system stability.


'gpiod>=2.2.2,<3': Installs the modern Linux GPIO character device library (libgpiod Python bindings), restricted to versions at or above 2.2.2 but strictly below 3.0.


'Adafruit-Blinka-Raspberry-Pi-PWM>=1.0.2': Installs Adafruit's hardware PWM compatibility library for Raspberry Pi, enabling precise pulse-width modulation control for motors and servos.


'rpi_ws281x>=4.0.0': Installs the low-level driver library used to control addressable WS281x RGB LED strips (such as the status or headlight LEDs on your Adeept smart car).


Create a new test script (e.g., move_straight.py) using a text editor like nano:


import time

import Move


def move_straight_2_feet():

    print("Moving forward straight for 2 feet...")

    # Initialize motor driver pins and PWM

    Move.setup()


    # Drive forward at speed 60 with no steering offset

    Move.move(60, 'forward', 'no')


    # Run for a set duration (adjust time for 2 feet distance)

    time.sleep(2.0)


    # Stop motors and clean up GPIO resources

    Move.motorStop()

    Move.destroy()


if __name__ == '__main__':

    try:

        move_straight_2_feet()

    except KeyboardInterrupt:

        Move.destroy()


Here is a clear breakdown of what each section of this script does:

Overview

This script uses Python and the Adeept Move module to drive your 4WD smart car straight forward at a set speed for 2.0 seconds, and then safely shuts down and stops the motors.

Section-by-Section Breakdown

Imports

Python

import time

import Move


time: Python's built-in module used to create timed pauses (time.sleep).

Move: Adeept's custom control library that talks to the hardware driver board (PCA9685) to control the motors.

Function Definition & Initialization

Python

def move_straight_2_feet():

    print("Moving forward straight for 2 feet...")

    # Initialize motor driver pins and PWM

    Move.setup()

Defines a function named move_straight_2_feet().

Move.setup(): Prepares the hardware, turning on the I2C communication and motor driver board so it is ready to accept movement commands.

Commanding Movement

Python

# Drive forward at speed 60 with no steering offset

    Move.move(60, 'forward', 'no')


Move.move(speed, direction, turn): Adeept's high-level helper function.

60 sets the motor power level (from 0 to 100), 'forward' tells all four wheels to spin forward, and 'no' specifies that no differential turning offset should be applied.

Timed Travel & Stopping

Python

# Run for a set duration (adjust time for 2 feet distance)

    time.sleep(2.0)


# Stop motors and clean up GPIO resources

Move.motorStop()

Move.destroy()


time.sleep(2.0): Pauses the script for 2 seconds while the car physically rolls forward. (You can adjust this number up or down to dial in the exact 2-foot distance).

Move.motorStop(): Cuts power to all motors.

Move.destroy(): Safely resets the GPIO pins and releases hardware resources.

Safe Execution Guard

Python

if __name__ == '__main__':

    try:

        move_straight_2_feet()

    except KeyboardInterrupt:

        Move.destroy()


Ensures the script executes when run directly from the terminal.

The try...except KeyboardInterrupt block catches a Ctrl+C keystroke, ensuring that Move.destroy() is called immediately to stop the motors if you need to abort the program mid-run.


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...