G36_maid
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # 物件導向期末專題-加速規應用於交通工具 物件導向期末專題 成員:林明威 林彥鈞 鍾詠傑 黃少遠 服務單位 Email ## 摘要 目標:交通工具是人們生活不可或缺的一部分,不但與生活息息相關,防範交通事故也是重要公共議題。本專題目的為利用raspberry pi與加速規測量交通工具的即時加速度並實時檢測,並探討其影響因素。 方法:以樹梅派上的加速規偵測器傳送資料到實驗室電腦資料庫,再透過程式抓資料到Grafana上,最後以網頁呈現Grafana資料。 結果: 結論: 關鍵詞:物件導向程式、樹梅派、資料庫、智慧製造 other 交通部今公布110年度道路交通事故統計,共計發生35萬6779件事故、造成2990人死亡及47萬4376人受傷。可見交通工具安全十分重要。 ## 軟體功能介紹 ## 程式架構介紹 ![](https://i.imgur.com/mCJogwl.png) 資料取得: 使用感測器連接一微處理器取得資料,此感測器需要配合應用環境選擇, 微處理器部分,助教推薦使用Arduino或樹莓派Raspberry pi,上手容易,泛用性高並且網上教學繁多。 微處理器需要進行的工作有二: 1. 接收感測器資料: 利用Arduino或樹莓派上的GPIO 腳位接取資料。 2. 傳送資料: 透過泛用的http請求將資料送往儲存伺服器。 編輯程式方面,Aruido可利用本身的Arduino IDE進行 而樹莓派可以當作他是一台小電腦,比Arduino性能更好,但使用前需要先裝好系統,樹莓派GPIO腳位相關程式教學網路上應該一抓一大把 資料儲存: 獲得資料後,為了將資料保存起來並進行後續運用,為此需要架設一伺服器。 本次專題使用了實驗室的電腦作為伺服器,將資料存在node.js server上的PostgresSQ並加上TimeScaleDB extension來實現時序資料庫處理 這次專題資訊與時間相關性高,選擇使用時序資料庫處理。 雲端伺服器需要進行的工作有三: 1. 接收資料: 接收http請求功能 2. 儲存資料庫: 須能連結資料庫將資料存入 3. 開放接口: 為了後續資料呈現等相關應用,需開放造訪資料庫的接口 資料呈現: 為了方便人員對歷史資料進行分析或觀察,將資料圖表化是最為常見的手段,本次使用Grafana圖表功能,從資料庫撈出資料化成圖表。 至此,遠端監控架構已初步完成,監控人員僅需觀察圖表便可了解觀測目標當前狀況,不必現場觀察目標。最後,為了進一步減輕人員負擔,對資料進行異常判斷,當異常發生時自動通報,本次使用line notify通報,line在全台灣是數一數二高普及率的軟體,做為通報手段再適合不過。 ## 程式設計技巧分析 ``` # mpu6050介紹: # https://blog.gtwang.org/iot/raspberry-pi-mpu6050-six-axis-gyro-accelerometer-1/ # mpu6050套件: # https://github.com/m-rtijn/mpu6050 # Python多線程: # https://docs.python.org/3/library/threading.html import time from mpu6050 import mpu6050 import requests from threading import Thread import math url = 'http://140.122.103.145:8191/gsensor/log' sensor = mpu6050(0x68) x = 0 y = 0 z = 0 count = 0 ###dT dT=0.1 Vx=0 Vy=0 def cal(): global x, y, z, count # 多線程取全域變數使用global accelerometer_data = sensor.get_accel_data(g = True) # 累積加速度(不考慮方向) x += abs(accelerometer_data['x']) y += abs(accelerometer_data['y']) z += abs(accelerometer_data['z']) count += 1 #計算速度 Vx+=accelerometer_data['x']*dT Vy+=accelerometer_data['y']*dT V=math.sqrt(Vx*Vx+Vy*Vy) def req(): global x, y, z, count # 多線程取全域變數使用global # 計算平均加速度(不考慮方向) myobj = { 'x': x / count, 'y': y / count, 'z': z / count, #速度欄位 'Vx':Vx, 'Vy':Vy, 'V':V } print(count, myobj) x = 0 y = 0 z = 0 count = 0 # 將平均值使用Rest API的POST方式傳至server post = requests.post(url, json = myobj) print(post) def cal_thread(): while True: # 在wihle迴圈中使用多線程確保每0.1秒會讀取一次感測值 Thread(target=cal).start() time.sleep(0.1) def req_thread(): while True: time.sleep(1) # 在wihle迴圈中使用多線程確保每秒會觸發回傳 Thread(target=req).start() # 定義多線程並開始執行 thread_arr = [Thread(target=cal_thread), Thread(target=req_thread)] for thread in thread_arr: thread.start() # 最終結果會在各自的線程中依照sleep的間隔獨立執行各自的任務 ``` ## 優缺點分析及改進方式 ## 新增功能 LINE Bot 和相機 弄積分 ## 結論

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully