產品協同設計第三組

第十五週-影像辨識多個球員踢球 << Previous Next >> 結案報告

系統功能問題與討論

問題:

第十三週-影像辨識機器對打

如果球打到桿子後方會無法回擊

解決方法:

更改判斷球位置的方式如第十四週內容

問題:

無法判別多根桿子

原因:

程式會尋找所有藍色物件的質心

解決方法:

更改尋找物件方式

由原本的找尋藍色物件改成尋找藍色物件的輪廓

問題:

由於尋找物件輪廓順序是隨機的

所以無法直接給予相對應物件座標位置

解決方法:

新增以下判斷式來設定各物件位置變數

# 只取奇數項
ret_blue_odd = ret_blue[::2]
for i in range(len(ret_blue_odd)):
    if ret_blue_odd[i][1] >=13 and ret_blue_odd[i][1] <=20:
        blue00 = (ret_blue_odd[i][0], ret_blue_odd[i][1])
                 
    elif ret_blue_odd[i][1] >= 57 and ret_blue_odd[i][1] <=64:
        if ret_blue_odd[i][0] < ret_blue_odd[i+1][0]:
            blue01 = (ret_blue_odd[i][0], ret_blue_odd[i][1])
        elif ret_blue[i][0] >= ret_blue[i+1][0]:
            blue02 = (ret_blue_odd[i][0], ret_blue_odd[i][1])
# blue00 is first rod object position
# blue01 is  second rod and left object position
# blue02 is second rod and right object position

問題:

同時按下兩個鍵會造成衝突

解決方法 :

將兩桿子操作按鍵,使用try except分開寫成兩段程式

try:
if keyboard.is_pressed('v'):
vrep.simxSetJointTargetVelocity(clientID,BRev_handle,B_KickBallVel,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('b'):
vrep.simxSetJointTargetVelocity(clientID,BRev_handle,R_KickBallVel,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('z'):
vrep.simxSetJointTargetVelocity(clientID,BMo_handle,0.2,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('x'):
vrep.simxSetJointTargetVelocity(clientID,BMo_handle,0,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('c'):
vrep.simxSetJointTargetVelocity(clientID,BMo_handle,-0.2,vrep.simx_opmode_oneshot_wait)
except:
break 
try:
if keyboard.is_pressed('o'): 
vrep.simxSetJointTargetVelocity(clientID,RRev_handle,R_KickBallVel,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('p'): 
vrep.simxSetJointTargetVelocity(clientID,RRev_handle,B_KickBallVel,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('y'): 
vrep.simxSetJointTargetVelocity(clientID,RMo_handle,0.2,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('u'): 
vrep.simxSetJointTargetVelocity(clientID,RMo_handle,0,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('i'): 
vrep.simxSetJointTargetVelocity(clientID,RMo_handle,-0.2,vrep.simx_opmode_oneshot_wait)
except:
break


問題:

操作按鍵過多,導致控制困難

解決方法 :

取消暫停鍵

改成按下按鍵作動 放開則停止

修改前 :

if keyboard.is_pressed('y'): #桿子向左移
vrep.simxSetJointTargetVelocity(clientID,RMo_handle,0.1,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('u'): #桿子停止作動
vrep.simxSetJointTargetVelocity(clientID,RMo_handle,0,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('i'): #桿子向右移
vrep.simxSetJointTargetVelocity(clientID,RMo_handle,-0.1,vrep.simx_opmode_oneshot_wait)



修改後 :

if keyboard.is_pressed('u'): #桿子向左移
vrep.simxSetJointTargetVelocity(clientID,RMo_handle,0.1,vrep.simx_opmode_oneshot_wait)
elif keyboard.is_pressed('i'): #桿子向右移
vrep.simxSetJointTargetVelocity(clientID,RMo_handle,-0.1,vrep.simx_opmode_oneshot_wait)
else:
vrep.simxSetJointTargetVelocity(clientID,RMo_handle,0,vrep.simx_opmode_oneshot_wait)


第十五週-影像辨識多個球員踢球 << Previous Next >> 結案報告