How to control RG2 without using a script?

Typically: "How do I... ", "How can I... " questions
Post Reply
Eureka_yiang
Posts: 19
Joined: 20 Jun 2022, 07:05

How to control RG2 without using a script?

Post by Eureka_yiang »

Hi,
I want to control RG2 directly through the zmqRemoteApi in python, rather than indirectly through functions in scripts.
First, I get the Handle of openCloseJoint through motorHandle=sim.getObject('./openCloseJoint').
Then, I use sim.setJointTargetForce(motorHandle,20) and sim.setJointTargetVelocity(motorHandle,-0.05) to close the RG2.
I printed motorHandle in script and python separately, and the result was the same:57.
However, When python executes sim.setJointTargetForce(motorHandle,20) and sim.setJointTargetVelocity(motorHandle,-0.05), nothing happens to RG2.
So I want to know how I can achieve my goal.
Thank a lot!

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: How to control RG2 without using a script?

Post by coppelia »

Hello,

are you sure the simulation is running? If not, then nothing will happen, since those instructions are forwarded to the physics engine (and the physics engine is only initialized after simulation started).

Cheers

Eureka_yiang
Posts: 19
Joined: 20 Jun 2022, 07:05

Re: How to control RG2 without using a script?

Post by Eureka_yiang »

Hi,
I am sure that my simulation is running, becasure my UR5 in scene can move to target position.
I recreated a simple scene with just one RG2, and the python code is follow:
  • from zmqRemoteApi import RemoteAPIClient
    import os
    if __name__ == '__main__':
    client = RemoteAPIClient()
    sim = client.getObject('sim')
    sim.loadScene('G:/PHD_PROJECT/coppeliasim_scene/111.ttt')
    rg2 = sim.getObject('./RG2')
    motorHandle = sim.getObject('./openCloseJoint')
    centerJoint = sim.getObject('./centerJoint')
    client.setStepping(True)
    sim.startSimulation()
    motorVelocity = 0.05
    motorForce = 20
    v = -motorVelocity
    sim.setJointTargetForce(motorHandle, motorForce)
    sim.setJointTargetVelocity(motorHandle, v)
    sim.stopSimulation()
This one doesn't work either.
Please help me point out the problem.
Thaks a lot.

coppelia
Site Admin
Posts: 10339
Joined: 14 Dec 2012, 00:25

Re: How to control RG2 without using a script?

Post by coppelia »

Calling:

Code: Select all

client.setStepping(True)
will require you to call for each simulation step:

Code: Select all

client.step()
Make sure to have a look at the simple example in programming/zmqRemoteApi/client/python/simpleTest.py

Cheers

Eureka_yiang
Posts: 19
Joined: 20 Jun 2022, 07:05

Re: How to control RG2 without using a script?

Post by Eureka_yiang »

Hi,

Thank you very much, and it can work now!

Thanks!

Post Reply