JBullet Basic question

Official Python bindings with a focus on reinforcement learning and robotics.
Post Reply
mikenofx
Posts: 3
Joined: Tue Jan 30, 2018 2:37 pm

JBullet Basic question

Post by mikenofx » Tue Jan 30, 2018 2:46 pm

Hello, im new to Bullet library .

I use JBullet for an augmented reality application in android based in vuforia library (AR library) .Basically i track an image target and i want this target to be my ground in the app .I used a StaticPlaneShape as a collision shape ,but i searched on the internet and found that static plane shapes cant "change" their orientation and rotation etc. but i want to change them ( im trying to have a ball fall in the target and roll it around by tilting the target .
1)Is there a proper way to do it with this collision shape?
2)Maybe i have it wrong in my mind
3)Any documentation for another collision shape or another way to do it would be good

Thank you very much !

runnin_fool
Posts: 5
Joined: Tue Mar 08, 2016 9:17 pm

Re: JBullet Basic question

Post by runnin_fool » Wed Jan 31, 2018 7:56 pm

Hi mikenofx,

I'm sorry I'm not in a position to answer your question, but as a newcomer myself and also using JBullet, I'll be curious to see the answer.

I'm wondering if you have a sense of the performance difference between JBullet and the C++ version?

Thanks.

mikenofx
Posts: 3
Joined: Tue Jan 30, 2018 2:37 pm

Re: JBullet Basic question

Post by mikenofx » Thu Feb 01, 2018 4:14 pm

No i have no sense , im new too :P

User avatar
Erwin Coumans
Site Admin
Posts: 4110
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA
Contact:

Re: JBullet Basic question

Post by Erwin Coumans » Wed Feb 07, 2018 3:55 am

Never heard about JBullet, what is it?

This is a forum for PyBullet, the Python module, which is much more than just Python bindings for Bullet: it also adds rendering, VR, inverse kinematics, inverse dynamics, rendering (CPU and OpenGL) etc. See the PyBullet quickstart guide.

mikenofx
Posts: 3
Joined: Tue Jan 30, 2018 2:37 pm

Re: JBullet Basic question

Post by mikenofx » Mon Feb 26, 2018 3:57 pm

I thought it was the Java Version of the Bullet Physics library , thats why i posted the question here (i cant find a forum for jbullet)

runnin_fool
Posts: 5
Joined: Tue Mar 08, 2016 9:17 pm

pyBullet in C# - am I on the right track?

Post by runnin_fool » Fri Mar 16, 2018 5:34 am

Apologies for misusing the forum, Erwin. For reference, I picked up JBullet from http://jbullet.advel.cz/ It's described as a port of 2.72.

I was drawn to JBullet because I was working in Java and new to Bullet; an out-of-date version, and the expected performance hit was less important than being able to explore functionality. It was a useful, though limited, exercise.

My current project is in C# and I'm am hopeful that pyBullet, in fact, will be the answer to integrating Bullet into my application. Firstly, my interest is in articulated motion - legged characters executing different gaits. I am not a C++/dev environment expert (and not particularly interested in diverting from my research to become one) and getting access to Bullet in VSC# has been a so far unsuccessful challenge. Following the BulletSharp instructions on https://andrestraks.github.io/BulletSharp/ I have successfully compiled Bullet but been unsuccessful compiling BulletSharp: "C3821...managed type or function cannot be used in an unmanaged function" Some research indicates that the underlying issue has to do with byte alignments in stack frames... solution unclear, and, again, not where I'd like to be spending my time.

The documentation at the link you provided looks substantial - thanks for that - and the various posts about success using pyBullet from C# in Unity are encouraging. I'll take a run at this in the next few days and will post notes here about the experience. Any advice?

runnin_fool
Posts: 5
Joined: Tue Mar 08, 2016 9:17 pm

pyBullet in VisualStudio C#

Post by runnin_fool » Sat Mar 17, 2018 4:27 am

The pyBullet installation went smoothly but for one issue: a missing executable in my environment, rc.exe. This was easily corrected following the instructions in https://stackoverflow.com/questions/143 ... -to-rc-exe Solution 20 was most useful - modified for me because I'm on Windows 10.

I now have Bullet Physics available from Python 3.5.

However, I need a bridge to reach it from VSC#. A bridge from C# in Unity to Python has been generated and demonstrated, but appears to be specific to Unity. IronPython is the standard C# to Python bridge for VisualStudio, but the python version lags: it's for Python 2.7.

At the moment, I have full access to Bullet from a Python 3.5 environment, and full access to Python 2.7 from VSC#, but no live path from C# to Bullet. (I can run Python 3.5 as an external command from C#, but to do anything useful I really need a live connection.)

The pyBullet module, having been developed for Python 3.5, is incompatible with Python 2.7, so I can't just bring the module into the IronPython environment. (Tried it and get complaints about a "__future__" module, which to this Python light-weight is interpreted as a Python incompatibility, end of story.)

There is an IronPython 3.x in development. With synchronized Python levels, it should be possible to import the module.

In the meantime, is there a short path from my current situation to a live connection to (py)Bullet from C#?

runnin_fool
Posts: 5
Joined: Tue Mar 08, 2016 9:17 pm

Re: JBullet Basic question

Post by runnin_fool » Wed Mar 21, 2018 9:58 pm

My band-aid solution is to run a TCP server in Python (3.5) and send script snippets to it from my application running as a client. This gets me a live connection to a stateful Bullet instance, but it's far from ideal from an architectural point of view:

my application in C#
|
C# - Python scripting adaptation layer
|
TCP (strings)
|
Python.exec()
|
Python - C++ adaptation layer
|
C++ Bullet

where BulletSharp is:

my application in C#
|
native code adaptation layer
|
C++ Bullet

Seems a shame to waste some of the hard work done at the Bullet level to optimize performance. Not to mention the much more tedious debug environment. Nonetheless, it does provide a usable path. I'll do some performance measurements to quantify the cost of that longer path. I'm happy to share the code for the Python server and my (selective) adaptation layer if anyone's interested.

I look forward to testing the next revision of BulletSharp.

anthrax11
Posts: 68
Joined: Wed Feb 24, 2010 9:49 pm

Re: JBullet Basic question

Post by anthrax11 » Sat Mar 24, 2018 10:53 pm

Regarding the original question, if you need to move the ground, use a large BoxShape instead of the StaticPlaneShape. Use a mass of 0 and set the KinematicObject collision flag for the body to make it a static kinematic object (movable, but not affected by other bodies).

You'd have to measure the performance to say for sure, but I suspect the bottleneck for JBullet is just the speed of the physics engine code running in Java compared to C++. Java and .NET aren't designed to compete with C++ in performance. With BulletSharp, the simulation runs in C++, so the bottleneck might be reading the simulation state in .NET after running each simulation step.

In practice, you can probably push both quite far before you run into performance issues. The same optimization principles apply in any case: limit the number of objects, make use of simulation islands, choose the appropriate broad phase algorithm, etc.

I couldn't reproduce the C3821 error following the build instructions:
https://github.com/AndresTraks/BulletSh ... structions
You could try the P/Invoke version. Compiling it is a bit easier:
https://github.com/AndresTraks/BulletSh ... structions
Or use the pre-built binaries or the Nuget package.

Note that BulletSharp doesn't yet support the PyBullet functionality that Erwin mentioned ("VR, inverse kinematics, inverse dynamics, rendering (CPU and OpenGL)"). But it does support the entire core part of the Bullet library. Which functionality you need out of Bullet is not clear from the information above.

I haven't had much time to look into PyBullet and see what parts are relevant and how best to integrate them into BulletSharp, but it's on the radar.

runnin_fool
Posts: 5
Joined: Tue Mar 08, 2016 9:17 pm

Re: JBullet Basic question

Post by runnin_fool » Sun Apr 08, 2018 2:39 pm

Some insight into the costs of various design choices.

I've implemented a C# to pyBullet bridge via TCP, as described earlier, and have observed the following:

A NO-OP call round trip involving the top of the stack from C# down to the pyBullet interface, but no pyBullet call executed, registers 0 Ticks at the C# level.

For my relatively complex model, a block retrieval of link position+orientation states after a stepSimulation call (one C# call to get all links of the model) also registers 0 Ticks. Some measurements are 1 or 2 milliseconds, but that appears to be the result of time slicing between threads. Some of the calls could not be 0 (in fact, the majority are 0 if I disable my graphics updates) unless the basic operation was essentially 0. Reminder: 10000 C# Ticks = 1 mS.

In contrast, a call to stepSimulation takes approx. 20 mS. I've had to bump up numSolverIterations and numSubSteps to avoid an instability. No doubt I can do some optimizations to reduce the simulation cost, but the Bullet call will clearly still be the critical path in the system even if I can achieve an order of magnitude improvement with model and solver tweaks.

The bottom line is that using the layers I do to reach Bullet do not contribute significantly to performance. The real cost is in the discontinuity between my strongly-typed C# application environment and the (relatively) strongly-typed C++ bullet environment. The direct BulletSharp interface is definitely a better option in that regard.

Re. the BulletSharp build instructions, I quoted the page I did because it indicated specific choices for the various options you described - presumably a consistent set that the author had successfully built with and used - and screen shots that helped me verify that I was doing exactly what the author had (though in the end my build didn't succeed). A small suggestion (I realize this is volunteer work): when you run through your tests, you must have built various configurations to the point of exercising the resulting elements in a test C# application. In one or more of those states, it would be a relatively small effort to zip up the runnable VSC# project with libraries, references, etc. that someone less skilled in the art could just unzip, open in VS, and run....

Post Reply