Python Regular API Joint Force is None

Typically: "How do I... ", "How can I... " questions
Post Reply
Suneet_S
Posts: 1
Joined: 28 Jan 2024, 13:08

Python Regular API Joint Force is None

Post 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))

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

Re: Python Regular API Joint Force is None

Post 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

jumppy
Posts: 3
Joined: 31 May 2016, 01:41

Re: Python Regular API Joint Force is None

Post 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.

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

Re: Python Regular API Joint Force is None

Post by coppelia »

Starting with CoppeliaSim V4.7, sim.getJointForce will simply return 0.0 instead of previously None.

Cheers

Post Reply