Giter Site home page Giter Site logo

abishevs / wifi-car-with-raspberry-pi4 Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 2.0 238 KB

Flask app with raspb camera view to control and see arduino based RC car from a browser.

Python 16.33% JavaScript 41.47% CSS 12.64% HTML 17.56% C++ 12.00%
flask python arduino-uno

wifi-car-with-raspberry-pi4's Introduction

If venv (virutal envierement) is not installed.

sudo apt install python3.10-venv

if just cloned make an virtual envierament

python3 -m venv ./flask-env

start virtual envierement.

source flask-env/bin/activate

then install dependencies

pip install -r requirements.txt

To deactivate type

deactivate

Start the server with debug mode set to True

python3 flask-ard-car.py

To update requirements.txt type this

pip freeze > requirements.txt

Conection frontend to backend

  • Using ajax and javascript to send data on every button click or keystroke press.
  • Keystrokes(wasd and arrows, space or escape for stop) P.S speed up and down not implemnted yet

Future fix of delay from frontend

Use socket.io and get bi-direcation connection to the server. This way sending data will be very low latency.

wifi-car-with-raspberry-pi4's People

Contributors

abishevs avatar shadowstorm005 avatar

Watchers

 avatar

wifi-car-with-raspberry-pi4's Issues

video lags

i see video on page but it is bit too laggy.
so i tried to rewrite two parts of camera.py:

from picamera.array import PiRGBArray
from picamera import PiCamera
class VideoCamera(object):
    def __init__(self, flip = False, file_type = ".jpg", photo_string = "photo-taken"):
        #self.vs = PiVideoStream(resolution=(640, 480), framerate=30)
        self.vs = PiCamera(resolution=(640, 480), framerate=30)
        self.rawCapture = PiRGBArray(self.vs)
        
        #self.vs.start()
        #self.vs = PiVideoStream().start()

and

def get_frame(self):
        #frame = self.flip_if_needed(self.vs.read())
        for frame in self.vs.capture_continuous(self.rawCapture, format="bgr"):
            #ret, jpeg = cv.imencode(self.file_type, frame)
            self.rawCapture.truncate(0) 
            self.image = frame.array
            ret, jpeg = cv.imencode(self.file_type, self.image)            
            #self.previous_frame = jpeg
            return jpeg.tobytes()

dont know if it start working a bit faster...
may be a better solution is io.BytesIO()
https://stackoverflow.com/questions/40065328/picameravalueerror-incorrect-buffer-length-for-resolution-1920x1080

async key strokes from website

hi!
thanks for code. i use it in raspberry pi zero 2.

as far as i understand the main logic of control is here:

def retrieve_data():
    id = request.args.get('id', 0)
    id = int(id)
    print(f"Recieved from the web id: {id}")
    if 1 <= id <= 5:
        write_to_arduino(id)

i have changed for my case this way (as i have no arduino and made direct connection to motor driver):

def retrieve_data():
    id = request.args.get('id', 0)
    id = int(id)
    print(f"Recieved from the web id: {id}")
    if 1 <= id <= 5:
        #write_to_arduino(id)
        if id==4:
            setServoAngle(servo, 140)
        if id==5:
            setServoAngle(servo, 90)
        if id==1:
            mov.Forward(speed)
        if id==2:
            mov.Backward(speed)
        if id==3:
            mov.Stop()

but as i see there is synchronous code and when one key pressed there is no way to press another at the same time.
are you planning to add something async?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.