Page 1 of 1

Python Regular API Joint Force is None

Posted: 28 Jan 2024, 14:01
by Suneet_S
Hi everyone,
I'm new to Coppeliasim. I am using Python and Regular API to train an RL agent to fly a quadcopter in Coppeliasim. I am able to connect to the simulator and set and get the Object positions using the sim.getObjectPosition method (which tells me that my python code is connected to the simulator). But when I am trying to set the Joint Force using the method sim.setJointTargetForce and use the method sim.getJointForce I am getting the output as None.

Another thing I tried is to set the joint target velocity using sim.setJointTargetVelocity method. Though the velocity is being set (checked using the method sim.getJointVelocity), the quadcopter does not seem to fly or lift off the ground.

Can anyone help me with this? Do I need to set any environment variable?

Following is the code which I am using:

Code: Select all

self.propellerHandle0 = self.sim.getObject("/Quadcopter/joint")
self.sim.setJointTargetVelocity(self.propellerHandle0, 100, [])
simStep()
print(self.sim.getJointVelocity(self.propellerHandle0))

Re: Python Regular API Joint Force is None

Posted: 29 Jan 2024, 20:26
by coppelia
Hello,

usually, if you measure some dynamic data within the very first simulation step, before the dynamics engine was called once, you won't get any data, which is normal. Also, if your joint is not dynamically enabled, you also won't get any data (is there a little bouncing ball next to your joint in the scene hierarchy? Image).

Have a look at the demo scene scenes/motorControllerExamples-lua.ttt to try those commands in the statusbar: e.g. select one joint, then type: sim.getJointForce(SEL1)

Cheers

Re: Python Regular API Joint Force is None

Posted: 05 Apr 2024, 12:17
by jumppy
Yes, you save me hell lots of time. I am using the zmq remote API, and I'm reading the current force in every loop, and then determining a valid control to the system. The program crashes everytime, and I am scratching my hair off...
The reason is right as you mentioned, control first, read second.

Re: Python Regular API Joint Force is None

Posted: 08 Apr 2024, 15:24
by coppelia
Starting with CoppeliaSim V4.7, sim.getJointForce will simply return 0.0 instead of previously None.

Cheers