V-rep planar one-line and fourbar linkage simulation
One-link Robot Velocity Control
One-link manipulator Python3 remote API program:
Joint Properties -
Torque/Force Mode.
Moter enabled with Maximum torque setup and zero target velocity.
Joint ObjectName: Revolute_joint
import vrep import sys # child threaded script: # 內建使用 port 19997 若要加入其他 port, 在 serve 端程式納入 #simExtRemoteApiStart(19999) vrep.simxFinish(-1) clientID = vrep.simxStart('127.0.0.1', 19997, True, True, 5000, 5) if clientID!= -1: print("Connected to remote server") else: print('Connection not successful') sys.exit('Could not connect') errorCode,Revolute_joint_handle=vrep.simxGetObjectHandle(clientID,'Revolute_joint',vrep.simx_opmode_oneshot_wait) if errorCode == -1: print('Can not find left or right motor') sys.exit() errorCode=vrep.simxSetJointTargetVelocity(clientID,Revolute_joint_handle,2, vrep.simx_opmode_oneshot_wait) while True: choice = input("(e to exit, p to pause and enter to exec)>") if choice == "e": print("exiting") vrep.simxStopSimulation(clientID, vrep.simx_opmode_oneshot_wait) break elif choice == "p": vrep.simxPauseSimulation(clientID, vrep.simx_opmode_oneshot_wait) else: vrep.simxStartSimulation(clientID, vrep.simx_opmode_oneshot_wait)
One-link Robot Position Control
One-link manipulator Python3 remote API program:
Joint Properties -
Torque/Force Mode.
Moter enabled with Maximum torque setup and zero target velocity.
Joint ObjectName: Revolute_joint
import vrep import sys, math # child threaded script: # 內建使用 port 19997 若要加入其他 port, 在 serve 端程式納入 #simExtRemoteApiStart(19999) vrep.simxFinish(-1) clientID = vrep.simxStart('127.0.0.1', 19997, True, True, 5000, 5) if clientID!= -1: print("Connected to remote server") else: print('Connection not successful') sys.exit('Could not connect') errorCode,Revolute_joint_handle=vrep.simxGetObjectHandle(clientID,'Revolute_joint',vrep.simx_opmode_oneshot_wait) if errorCode == -1: print('Can not find left or right motor') sys.exit() deg = math.pi/180 #errorCode=vrep.simxSetJointTargetVelocity(clientID,Revolute_joint_handle,2, vrep.simx_opmode_oneshot_wait) def setJointPosition(incAngle, steps): for i in range(steps): errorCode=vrep.simxSetJointPosition(clientID, Revolute_joint_handle, i*incAngle*deg, vrep.simx_opmode_oneshot_wait) # 每步 10 度, 轉兩圈 setJointPosition(10, 72) # 每步 1 度, 轉兩圈 #setJointPosition(1, 720) # 每步 0.1 度, 轉720 步 #setJointPosition(0.1, 720) ''' 三軸同動時 simxPauseCommunication(clientID,1); simxSetJointPosition(clientID,joint1Handle,joint1Value,simx_opmode_oneshot); simxSetJointPosition(clientID,joint2Handle,joint2Value,simx_opmode_oneshot); simxSetJointPosition(clientID,joint3Handle,joint3Value,simx_opmode_oneshot); simxPauseCommunication(clientID,0); '''
Fourbar Linkage Velocity Control
the First Joint properties -
Torque/Force mode with motor enabled and target velocity 120 deg/s and maximum torque 50 N*m.
Joint ObjectName: Revolute_joint
All other joints with Torque/Force mode without motor enabled.
import vrep import sys # child threaded script: # 內建使用 port 19997 若要加入其他 port, 在 serve 端程式納入 #simExtRemoteApiStart(19999) vrep.simxFinish(-1) clientID = vrep.simxStart('127.0.0.1', 19997, True, True, 5000, 5) if clientID!= -1: print("Connected to remote server") else: print('Connection not successful') sys.exit('Could not connect') errorCode,Revolute_joint_handle=vrep.simxGetObjectHandle(clientID,'Revolute_joint',vrep.simx_opmode_oneshot_wait) if errorCode == -1: print('Can not find left or right motor') sys.exit() errorCode=vrep.simxSetJointTargetVelocity(clientID,Revolute_joint_handle,2, vrep.simx_opmode_oneshot_wait) while True: choice = input("(e to exit, p to pause and enter to exec)>") if choice == "e": print("exiting") vrep.simxStopSimulation(clientID, vrep.simx_opmode_oneshot_wait) break elif choice == "p": vrep.simxPauseSimulation(clientID, vrep.simx_opmode_oneshot_wait) else: vrep.simxStartSimulation(clientID, vrep.simx_opmode_oneshot_wait)
Fourbar Linkage Position Control
V-rep Fourbar linkage remote API program:
the First Joint properties -
Passive mode with Hybrid operation.
Position control (PID) with proportional parameter 0.1 without I and D controls.
Joint ObjectName: Revolute_joint
All other joints properties -
Inverse kinematics mode with Hybrid operation.
Position control (PID) with proportional parameter 0.1 without I and D controls.
import vrep, math import sys # child threaded script: #simExtRemoteApiStart(19999) vrep.simxFinish(-1) clientID = vrep.simxStart('127.0.0.1', 19997, True, True, 5000, 5) if clientID!= -1: print("Connected to remote server") else: print('Connection not successful') sys.exit('Could not connect') errorCode,Revolute_joint_handle=vrep.simxGetObjectHandle(clientID,'Revolute_joint',vrep.simx_opmode_oneshot_wait) deg = math.pi/180 if errorCode == -1: print('Can not find left or right motor') sys.exit() #errorCode=vrep.simxSetJointTargetVelocity(clientID,Revolute_joint_handle,2, vrep.simx_opmode_oneshot_wait) def setJointPosition(incAngle, steps): for i in range(steps): errorCode=vrep.simxSetJointPosition(clientID, Revolute_joint_handle, i*incAngle*deg, vrep.simx_opmode_oneshot_wait) # 每步 10 度, 轉兩圈 setJointPosition(10,72)
與上述四連桿位置控制流程相同, 但是由 Python3 remote API 程式負責控制 V-rep 的模擬啟動與模擬終止.
import vrep, math import sys # child threaded script: #simExtRemoteApiStart(19999) vrep.simxFinish(-1) clientID = vrep.simxStart('127.0.0.1', 19997, True, True, 5000, 5) #啟動模擬 vrep.simxStartSimulation(clientID, vrep.simx_opmode_oneshot) if clientID!= -1: print("Connected to remote server") else: print('Connection not successful') sys.exit('Could not connect') errorCode,Revolute_joint_handle=vrep.simxGetObjectHandle(clientID,'Revolute_joint',vrep.simx_opmode_oneshot_wait) deg = math.pi/180 if errorCode == -1: print('Can not find left or right motor') sys.exit() #errorCode=vrep.simxSetJointTargetVelocity(clientID,Revolute_joint_handle,2, vrep.simx_opmode_oneshot_wait) def setJointPosition(incAngle, steps): for i in range(steps): errorCode=vrep.simxSetJointPosition(clientID, Revolute_joint_handle, i*incAngle*deg, vrep.simx_opmode_oneshot_wait) #終止模擬 vrep.simxStopSimulation(clientID, vrep.simx_opmode_oneshot_wait) # 每步 10 度, 轉兩圈 setJointPosition(10, 72)
兩軸同動資料傳送:
import vrep import sys, math # child threaded script: # 內建使用 port 19997 若要加入其他 port, 在 serve 端程式納入 #simExtRemoteApiStart(19999) vrep.simxFinish(-1) clientID = vrep.simxStart('127.0.0.1', 19997, True, True, 5000, 5) if clientID!= -1: print("Connected to remote server") else: print('Connection not successful') sys.exit('Could not connect') errorCode,Revolute_joint_handle=vrep.simxGetObjectHandle(clientID,'Revolute_joint',vrep.simx_opmode_oneshot_wait) errorCode0,Revolute_joint_handle0=vrep.simxGetObjectHandle(clientID,'Revolute_joint0',vrep.simx_opmode_oneshot_wait) if errorCode == -1: print('Can not find left or right motor') sys.exit() deg = math.pi/180 #vrep.simxStartSimulation(clientID, vrep.simx_opmode_oneshot) for i in range(36): vrep.simxSynchronous(clientID,True) vrep.simxPauseCommunication(clientID,True) vrep.simxSetJointPosition(clientID, Revolute_joint_handle, 10*deg, vrep.simx_opmode_oneshot) vrep.simxSetJointPosition(clientID, Revolute_joint_handle0, 10*deg, vrep.simx_opmode_oneshot) vrep.simxPauseCommunication(clientID, False) vrep.simxSynchronous(clientID, False) vrep.simxSynchronous(clientID,True) vrep.simxPauseCommunication(clientID,True) vrep.simxSetJointPosition(clientID, Revolute_joint_handle, -10*deg, vrep.simx_opmode_oneshot) vrep.simxSetJointPosition(clientID, Revolute_joint_handle0, -10*deg, vrep.simx_opmode_oneshot) vrep.simxPauseCommunication(clientID, False) vrep.simxSynchronous(clientID, False)