Raspberry Pi plays timberman for me.

Source: Internet
Author: User

Project Reason and summary

Mobile phone Timberman game is challenged by friends, helpless can only reach more than 300 points, whim to do an automated system to replace people to operate, overtake friends record
Timberman game rules are simple, it should be easy to make a system to automate the operation, and the machine is machine after all, relying on the algorithm to make the judgment is basically not wrong.
But practice down, encountered a lot of problems, and eventually the system did not run according to the ideal situation, for the following reasons
1. Raspberry Pi processing speed is not ideal, can not be instantaneous to obtain the results of the operation
2. There is only Shenghui MG995 servo, it is overqualified, the Raspberry Pi can not be very good to drive, nor to purchase a separate equipment for him
3. The work of a conventional capacitive pen is dependent on the capacitance of the hand-passing
4. Prepare to prepare for the graduation project, this little thing can only be shelved temporarily
Wait for a more powerful Raspberry Pi in the Future 2, then restart the small project, the following simple record this little thing

Equipment pictures

Implementation ideas
    1. Get images
    2. Cutting
    3. Grayscale
    4. Compare with standard charts
    5. Judging similarity degree
    6. Respond
Tools
    • Raspberry Pi and Webcam
    • A stable platform for support
    • Python Imaging Library Libraries (abbreviated as PIL library)
Source

Source code is very simple, are directly call PIL library functions directly run, steering gear because of hardware problems debugging is not very perfect, waiting for the future with new equipment to improve

#!/usr/bin/python#coding: UTF8Import Mathimport Osimport Operatorimport TimeImport Signalimport atexit#import CV2.CV as CVImport Rpi.gpio asGPIO fromPIL Import Imageatexit.register (gpio.cleanup) Servopin = OneGpio.setmode (GPIO). BOARD) Gpio.setup (Servopin, GPIO. Out, initial=false) p = GPIO. PWM (Servopin, -)#50HZ while(True): OS.system(' fswebcam-r 320x240-d/dev/video0-p yuyv-s 5/root/timberman/testpictire.jpg ') Time. Sleep (0.5) takeimg = Image.Open(' testpictire.jpg ')#打开图片Region = ( -, -, Max, -)#设置切割接线Ctake = Takeimg.crop (region)#切割Lctake = Ctake.Convert(' L ')#灰度化Lctake.save (' fintest.jpg ') Standimage = Image.Open(' lstand.jpg ') H1 = Lctake.histogram () H2 = Standimage.histogram () RMS = Math.sqrt(Reduce (operator.Add, the list (map (lambdaa, B: (a-B) * *2, H1, H2))/Len(H1))ifrms< +:#p = GPIO. PWM (servopin,50) #50HZP.start (0) forIinchRange0,181,5): P.changedutycycle (2.5+TenI the)#设置转动角度             Time. Sleep (0.02)#等该20ms周期结束P.changedutycycle (0)#归零信号    Else:#p = GPIO. PWM (servopin,50) #50HZP.start (0) forIinchRange181,0,-5): P.changedutycycle (2.5+TenI the)#设置转动角度             Time. Sleep (0.02)#等该20ms周期结束P.changedutycycle (0)#归零信号
Later need to improve items
    • Optimized code
    • Adjusting the controllability of the rudder
    • Set up a large number of standard graphs for different scenes, optimize each scene, increase the accuracy of judgment
    • Increase program run response speed even considering porting the project to a PC via Arduino control, computing
    • Look at how to gracefully let the capacitive pen work

Raspberry Pi plays timberman for me.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.