專題報告整理

多連桿提球機構,運行準確,但若在模擬上出現錯誤,因為尺寸合成的問題,會出現牽一髮而動全身的現象,使得在設計上會出現不少問題;而且一次行程中只能運送少量貨物,在設計跟效率上並不是這麼的方便。   本專題利用一個輸入點來帶動許多輸出點,且本身也可被視為一個有無限多連桿的多連桿機構,並且一次可帶動許多輸出點,可以簡略許多的設計時間及提升工作效率。   我們利用線上的電腦輔助設計軟體來進行設計,並用電腦上的軟體模擬,再使用外部程式去控制,使得可以一目了然直至目前運送了多少貨物。

Multiple links ball lifting mechanism, they are accurate, but if the simulation go wrong, there will be a lot of trouble, because of size synthesis, and multiple links ball lifting mechanism can only deliver a few cargo in one stroke, so it’s not very efficiency for design and work.

Our project is using one input to be a pivot to drive all output, and this mechanism can be seen as a multiple links which has unlimited links and deliver several cargo in one stroke, can reduce the consume of time on designing, also rise the efficiency of work.

We use the online CAD software to design, simulate on PC, and control by the external program, let the users can understand 1how many cargo has been deliver easily.

目前已加上外部控制程式來控制並計算提球機構。

學員自身所設計的提球機構,球速不快,讓計數器會感測一顆球但數值顯示23,與學長討論後已解決問題。

# -*- coding: utf-8 -*-

"""
Module implementing Dialog.
"""
# 從 PyQt5.QtWidgets 模組中導入 QDialog 類別
from PyQt5.QtWidgets import QDialog
# 從同目錄中的 Ui_Dialog.py 模組導入 Ui_Dialog 類別
from .Ui_Dialog import Ui_Dialog

# for V-rep
# 從 remoteapi 目錄中導入 vrep.py 模組
from remoteapi import vrep
import sys
# 導入 threading, 用於建立執行緒
import threading
import time


class Dialog(QDialog, Ui_Dialog):
    """
    Class documentation goes here.
    """
    def __init__(self, parent=None):
        """
        Constructor

        @param parent reference to the parent widget
        @type QWidget
        """
        super(Dialog, self).__init__(parent)
        self.setupUi(self)
        # count, clientID, very_beginning, make 與 pill2kill 都是類別的成員屬性
        self.count = 0
        self.clientID = 0
        self.very_beginning = True
        # 以 self.start_thread 為標的, 建立執行緒
        self.make = threading.Thread(target=self.start_thread)
        self.pill2kill = threading.Event()
        # 從 Ui_Dialog 繼承而來的成員物件
        self.display.setText(str(self.count))
        # 為三個 press button 建立 signals 與 slots 對應
        self.start.clicked.connect(self.start_motor)
        self.stop.clicked.connect(self.stop_motor)
        self.pause.clicked.connect(self.pause_motor)

    # 啟動轉動馬達的 slot, 也就是按下 self.start 按鈕後將執行的對應方法
    def start_motor(self):
        # 利用執行緒執行 start, 執行緒只能啟動一次的判斷成員變數 self.very_beginning
        if self.very_beginning:
            # 啟動執行緒
            self.make.start()
            self.very_beginning = False
        else:
            # 暫停後, 重啟執行緒
            self.pill2kill.set
            #啟動模擬
            vrep.simxStartSimulation(self.clientID, vrep.simx_opmode_oneshot)

     # 停止馬達執行方法
    def stop_motor(self):
        # 按下停止鍵, 將會停止模擬, 重新回到原始設定畫面
        vrep.simxStopSimulation(self.clientID, vrep.simx_opmode_oneshot_wait)

    # 暫停執行處理方法
    def pause_motor(self):
        # 暫停執行緒, 暫停模擬
        #time.sleep(2)
        # 暫停執行緒
        self.pill2kill.clear()
        # 暫停模擬
        vrep.simxPauseSimulation(self.clientID, vrep.simx_opmode_oneshot_wait)

    # 啟動執行緒的對應方法
    def start_thread(self):
        # child threaded script: 
        # 內建使用 port 19997 若要加入其他 port, 在  serve 端程式納入
        #simExtRemoteApiStart(19999)
        a = []
        vrep.simxFinish(-1)

        self.clientID = vrep.simxStart('127.0.0.1', 19997, True, True, 5000, 5)

        #啟動模擬
        vrep.simxStartSimulation(self.clientID, vrep.simx_opmode_oneshot)

        if self.clientID!= -1:
            print("Connected to remote server")
        else:
            print('Connection not successful')
            sys.exit('Could not connect')

        errorCode1, Revolute_joint_handle = vrep.simxGetObjectHandle(self.clientID,'Revolute_joint',vrep.simx_opmode_oneshot_wait)
        errorCode2, sensorHandle = vrep.simxGetObjectHandle(self.clientID,'Finish',vrep.simx_opmode_oneshot_wait)

        if errorCode1 == -1:
            print('Can not find left or right motor')
            sys.exit()

        status = True
        while vrep.simxGetConnectionId(self.clientID) != -1:
            params = vrep.simxReadProximitySensor(self.clientID, sensorHandle, vrep.simx_opmode_streaming)
            if params[0] == vrep.simx_return_ok:
                print(params)
                if params[1] and (params[3] > 0):
                    if status:
                        a.append(params[3])
                        print(params[1])
                        self.count += 1
                        print("通過球總數:", self.count)
                        # 將 self.count 顯示在 display
                        self.display.setText(str(self.count))
                        status = False
                else:
                    status = True


            # 設定馬達的轉速
            vrep.simxSetJointTargetVelocity(self.clientID, Revolute_joint_handle, -0.1, vrep.simx_opmode_oneshot_wait)

        #終止模擬
        vrep.simxStopSimulation(self.clientID, vrep.simx_opmode_oneshot_wait)

書面資料即將編寫完成

專題PPT


Comments

comments powered by Disqus