SunFounder Smart Video Car Kit for Raspberry Pi

repository·master·Indexed 41 days ago

https://github.com/sunfounder/sunfounder_smart_video_car_kit_for_raspberrypi

An educational robotics platform for Raspberry Pi featuring motor and servo control via PCA9685 and real-time video streaming. It utilizes a Client/Server architecture with a Django-based HTML server for remote control via PC or Android devices, and integrates mjpg-streamer for video delivery.

Tokens
6.8K
Snippets
29
Records
42
Agent score
99%

What's inside SunFounder Smart Video Car Kit

  1. Overview of the Sunfounder Smart Video Car Client

    master

    The Sunfounder Smart Video Car Client is a Python-based application designed to interface with the Smart Video Car Kit for Raspberry Pi. It acts as the client-side component for controlling or interacting with the car's features.

    Important Operational Requirement: You must start and run the server routine on the car before attempting to run the client routine. The client will not function correctly without an active server connection.

  2. Understand the Smart Video Car Kit architecture

    master

    The SunFounder Smart Video Car Kit operates on a Client/Server (C/S) architecture:

    • Server (Raspberry Pi): Runs the TCP server program to directly control the car hardware. It also uses MGPJ-streamer to acquire and deliver real-time video data.
    • Client (PC/Android): Runs a TCP client program to send control commands to the Raspberry Pi.

    Important: You must always run the server routine on the Raspberry Pi before starting any client routine on a PC or mobile device.

  3. Control the Smart Video Car via the Android app

    master

    Once the server is running and connected to the app, you can use the following controls:

    • Driving Direction: Tilt your phone like a steering wheel to control the car's direction.
    • Forward/Backward: Use the up/down arrows on the left side of the app interface.
    • Camera Pan/Tilt: Use the up/down/left/right arrows on the right side of the app interface.
    • Camera Reset: Tap the middle dot to return the camera to its default position.
    • Motor Speed: Adjust the bar located under the camera view to change the motor speed.
    • Calibration: Tap the dot in a circle at the corner to begin calibrating the car's turning and the pan-tilt mechanism. You can click multiple times or type in specific values for fine-tuning.
  4. How to use the Html Server APIs

    master

    The Html Server API is a simple HTTP GET-based interface. It does not use JSON or data uploads. To issue a command, perform a GET request to the Raspberry Pi's IP address on port 8000 followed by the specific API endpoint.

    You can control the car by typing the URL directly into a web browser's address bar or by using an HTTP client to make GET requests.

    http://[Raspberry Pi IP address]:8000/[api_endpoint]
  5. Set up the HTML server on Raspberry Pi

    master

    The HTML server is a Django-based application that allows you to control the Smart Video Car and view real-time camera video via an Android app. The server must be running on the Raspberry Pi to communicate with the mobile device.

    Follow these steps to install and run the server:

    1. Install Django: Use pip to install the Django framework on your Raspberry Pi.
    2. Run the Server: Navigate to the Sunfounder_Smart_Video_Car_Kit_for_RaspberryPi/http_server/ directory and start the Django development server, binding it to all network interfaces on port 8000.
    3. Connect via App: Open the SunFounder Smart Video Car app on your Android phone, enter your Raspberry Pi's IP address, and click FORWARD (the right arrow) to establish the video stream.
    # 1. Install Django
    sudo pip install django
    
    # 2. Run the server (from the http_server directory)
    sudo python manage.py runserver 0.0.0.0:8000
  6. Overview of uvc_stream command line application

    master
    The uvc_stream command line application streams JPEG files over an IP-based network from a webcam to various viewers such as Firefox, Cambozola, Videolanclient, or Windows Mobile devices running TCPMP-Player. It is specifically designed for embedded devices with limited RAM and CPU resources. It leverages Linux-UVC to allow supported cameras to produce JPEG data directly, enabling high-performance M-JPEG streams even on low-power hardware.
  7. Start mjpg-streamer with UVC input and HTTP output

    master

    To stream video from a USB webcam (UVC) to a web interface, use the mjpg_streamer binary with the input_uvc.so input plugin and the output_http.so output plugin. You must set LD_LIBRARY_PATH to the current directory so the executable can find the shared object (.so) plugins.

    Basic command:

    export LD_LIBRARY_PATH="$(pwd)"
    ./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -w ./www"
    #!/bin/sh
    export LD_LIBRARY_PATH="$(pwd)"
    ./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -w ./www"
  8. Install the input_gspcav1 plugin

    master

    The input_gspcav1 plugin is designed for spca5xx based webcams with raw JPEG features. It includes an embedded JPEG decoder/encoder for a small footprint on embedded devices and uses libsdl to support the Linux framebuffer (allowing use without a running Xserver).

    Prerequisites

    You must have sdl installed with headers to compile spcaview.

    Compilation and Installation

    Run the following commands from the source directory:

    • Full installation (includes spcaview, spcaserv, and spcacat):
      make
      sudo make install
    • Install only the streaming server (spcaserv):
      sudo make install_spcaserv
    • Install only the picture grabber (spcacat):
      sudo make install_spcacat
    • Clean build files:
      make clean
    make
    sudo make install
  9. Security recommendations for uvc_stream

    master
    It is strongly recommended not to open the uvc_stream server directly to the internet. Instead, use it as an input to the motion program running within a DMZ. This approach leverages the security community's oversight of the motion project. Note that motion's advanced features (motion detection, avifile writing) require additional system resources.