Coder Social home page Coder Social logo

autosteer's Introduction

Autosteer

The Autosteer project is a python script designed to automatically steer a vehicle in farming simulator.

Grabbing Window as Screenshot

import win32gui
https://pypi.org/project/win32gui/

Filtering Road Lines

The script uses scikit-image library to parse image data. The Filter threshold_yen is used to transform image to binary image.

contours = cv2.findContours(image, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
image = cv2.drawContours(org_img, contours[0], -1, (0,255,0), 3)

All contours that are not in the central area (vehicle) are used to generate line with linear regression

coeffs = np.polyfit(x_np, y_arr, degree)

Calculate Difference

Afterwards the horizontal distance between the middle point of the screen and the line is calculated with the function

calculate_difference_line

PID Control

The difference is then used as the input of a simple PID controller which then outputs the steering in x-direction to a virtual gamepad

from simple_pid import PID
https://pypi.org/project/simple-pid/
import vgamepad as vg
https://pypi.org/project/vgamepad/

Autosteer swath detection

Automatically follow a swath by steering a vehicle in farming simulator.

Get swath position

Rectangle ROI in center of screenshot, height offset to match the vehicle engine hood. Use maximum and minimum gradient on grayscale image to detect swath after blurring the image.

blur_gray = cv2.GaussianBlur(img_gray_res,(kernel_size, kernel_size),0)
up = np.argmax(np.gradient(avg))
down = np.argmin(np.gradient(avg))

The following graph shows the intensity change of the pixels in a given line. Light blue line is the image center. Red line is the swath center calculated from both blue lines.

Calculate distance of swath to the center of the image.

PID Control

Use PID controller to control the distance between swath and center of image to zero.

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.