@@ -0,0 +1,2140 @@
+# -*- coding: utf-8 -*-%0A%0Atry:%0A    import vrep%0Aexcept:%0A    print '--------------------------------------------------------------'%0A    print '%22vrep.py%22 could not be imported. This means very probably that'%0A    print 'either %22vrep.py%22 or the remoteApi library could not be found.'%0A    print 'Make sure both are in the same folder as this file,'%0A    print 'or appropriately adjust the file %22vrep.py%22'%0A    print '--------------------------------------------------------------'%0A%0Aimport time%0Aimport math%0Aimport sys%0Aimport random%0A%0Arandom.seed()%0A%0AclientID = -1%0A%0Adef start_simulator():%0A    global clientID%0A%0A    print 'Program started'%0A    vrep.simxFinish(-1)%0A    clientID = vrep.simxStart('127.0.0.1', 19999, True, True, 5000, 5)%0A%0A    if clientID != -1:%0A        print 'Connected to remote API server'%0A    else:%0A        print 'Failed connecting to remote API server'%0A        sys.exit('Program Ended')%0A%0Adef error_check(res):%0A    global clientID%0A%0A    if res != vrep.simx_return_ok:%0A        print 'Failed to get sensor Handler'%0A        vrep.simxFinish(clientID)%0A        sys.exit('Program ended')%0A%0Adef main():%0A    global clientID%0A%0A    res, objs = vrep.simxGetObjects(clientID, vrep.sim_handle_all, vrep.simx_opmode_oneshot_wait)%0A    error_check(res)%0A    res, JointDynamic = vrep.simxGetObjectHandle(clientID, %22joint%22 , vrep.simx_opmode_oneshot_wait)%0A    error_check(res)%0A    res, Potentiometer = vrep.simxGetObjectHandle(clientID, %22Potentiometer%22, vrep.simx_opmode_oneshot_wait)%0A    error_check(res)%0A%0A    time.sleep(1.0)%0A%0A    #set joint truqe%0A    vrep.simxSetJointForce(clientID, JointDynamic, 4.8, vrep.simx_opmode_oneshot)%0A%0A    while True:%0A        #Get Potentiometer%0A        res, pos = vrep.simxGetJointPosition(clientID, Potentiometer, vrep.simx_opmode_oneshot)%0A        print %22Potentiometer: %25lf%5Bdeg%5D%22 %25 math.degrees(pos)%0A        %0A        #Decide about joint velocities:%0A        linearVelocity  = random.random() * random.choice((-20, 20))%0A        %0A        vrep.simxSetJointTargetVelocity(clientID, JointDynamic, linearVelocity, vrep.simx_opmode_oneshot)%0A        %0A        time.sleep(0.001)%0A%0Aif __name__ == '__main__':%0A    start_simulator()%0A    main()%0A%0A

add sample_random.py