ammo.js icon indicating copy to clipboard operation
ammo.js copied to clipboard

Possible to expose functions in b3RobotSimulatorClientAPI?

Open evandarcy opened this issue 5 years ago • 16 comments

@kripken I have already exposed some functions I need on my fork of ammo.js, it wasn't so hard as these functions were listed in the bullet API documentation so I could just copy and paste.

However, I came across a function that is not referenced in the Bullet API documentation called setJointMotorControl() in this program on line 35: https://github.com/bulletphysics/bullet3/blob/master/examples/RobotSimulator/MinitaurSetup.cpp

     for (int i = 0; i < numJoints; i++)
{
	b3RobotSimulatorJointMotorArgs controlArgs(CONTROL_MODE_VELOCITY);
	controlArgs.m_maxTorqueValue = 0;
	sim->setJointMotorControl(m_data->m_quadrupedUniqueId, i, controlArgs);
}

It seems like this function is declared in this file on line 542: https://github.com/bulletphysics/bullet3/blob/cdd56e46411527772711da5357c856a90ad9ea67/examples/SharedMemory/b3RobotSimulatorClientAPI_NoDirect.h

Is it even possible to add functions referenced in the RobotSimulator API to Ammo.js? If anybody can help me on this one, it would be awesome because I'm fairly stumped!

evandarcy avatar May 28 '19 23:05 evandarcy

I believe ammo.js is built off of Bullet 2.8.3 so you can only expose Bullet API from that version (not Bullet 3 as you have above).

willeastcott avatar May 29 '19 01:05 willeastcott

Hey Will! Do you know if there is a specific reason it hasn't been updated to use the latest Bullet (Version 2.88)?

I found this fork of Ammo that is supposedly using Bullet 3 (Version 2.8.5): https://github.com/WhitestormJS/AmmoNext

There are .cpp files in the AmmoNext repo above that reference the function setJointMotorControl() that I want. In theory is it possible to expose that function in the ammo.idl file? I would understand how to do it if it was a normal function with prefix "bt" but I'm just not sure how I would go about doing it for a function with prefix "b3" that is not referenced in API documentation.

evandarcy avatar May 29 '19 08:05 evandarcy

I don't know why @kripken hasn't updated to the latest 2.x version. I don't see a reason not to other than, hey, it just takes time. But updating to Bullet 3 could, I guess, cause some behavioral difference in the physics which might break some peoples' applications?

willeastcott avatar May 29 '19 14:05 willeastcott

Updating to 2.x is just time, yeah - I'm too busy myself, sorry. Would be great to see it done though!

kripken avatar May 31 '19 17:05 kripken

@kripken , I'd be happy to give it a go. How much work is actually involved, surely Emscripten does most of the heavy lifting right?

I've been trying to find a tutorial online on how to convert a library using Emscripten, I found one here: https://developers.google.com/web/updates/2018/03/emscripting-a-c-library , I did try to apply the same steps to bullet to no success.

Perhaps you could point me in the right direction or give me a procedure to follow?

Thanks!

evandarcy avatar May 31 '19 17:05 evandarcy

Basically, the procedure would be to replace the current bullet source files in this repo with the newer ones, then build and see how things go. If APIs change, then we'd need to also update the idl file, the examples, and the tests.

kripken avatar Jun 03 '19 17:06 kripken

So I have successfully managed to build using bullet3 and was able to expose a function from bullet3 that returns an API version and run in browser successfully.

Now I am trying to expose this "connect" function Screen Shot 2019-06-06 at 20 08 13

By placing this in the .idl file Screen Shot 2019-06-06 at 20 05 36

And I am trying to call it in a html file like so Screen Shot 2019-06-06 at 20 09 48

But I am getting the following error in browser Screen Shot 2019-06-06 at 20 10 20

Is this an error you recognise @kripken ?

evandarcy avatar Jun 06 '19 19:06 evandarcy

Not sure what that could be. The stack trace in a debug build might be more useful though.

kripken avatar Jun 06 '19 21:06 kripken

Rather confused..how do I go about doing a debug build?

evandarcy avatar Jun 06 '19 21:06 evandarcy

Probably simplest to edit make.py and add -g after -O3, so args = '-O3 -g --llvm-lto 1 etc.

kripken avatar Jun 07 '19 23:06 kripken

Okay, so I did that. Here's something interesting I found:

This is the new error I am getting:

Screen Shot 2019-06-08 at 13 04 34

When I click into it, I can see the following (Notice mention of FS):

Screen Shot 2019-06-08 at 13 05 33

When building project using python make.py, I get the following "undefined symbols" errors. Notice ($FS): Screen Shot 2019-06-08 at 13 02 55

I have had to fix a lot of these "undefined symbol" errors by tracking down which library the function mentioned in the symbol belongs to and including the correct library file (.o) file for that function in the make.py file. It was a very repetitive process and I am not sure it was the correct thing to do but I was able to eliminate each "undefined symbol" error one by one by including correct library.

Perhaps the error I am getting in console has to do with $FS being excluded somehow in a similar sense as other undefined symbols?

evandarcy avatar Jun 08 '19 12:06 evandarcy

Update: I set SYSCALLS_REQUIRE_FILESYSTEM equal to 0 in emscripten settings.js and rebuilt, i no longer get an error for $FS. When I try to run same example in browser I get this error instead:

Screen Shot 2019-06-08 at 13 26 19

evandarcy avatar Jun 08 '19 12:06 evandarcy

@kripken I am consistently running into errors to do with filesystem. Do I need to add a --preload-file somewhere in the make.py file to include files I want to use? Screen Shot 2019-06-09 at 19 31 52

evandarcy avatar Jun 09 '19 19:06 evandarcy

I tested latest emscripten incoming now, and the ammo tests pass for me. We did have some FS related bugs in the past, which emscripten version are you on? (Or did you add code in JS to use files somehow, like that error suggests?)

kripken avatar Jun 10 '19 17:06 kripken

Yes I was trying to load a .urdf file, I think I've figured out the FS stuff, no longer getting errors there. Now the problem lies in figuring out how to load a .urdf file in webGL.

evandarcy avatar Jun 10 '19 18:06 evandarcy

Wow @evandarcy you need to give us a Pull Request with your bullet3! edit Any problems you run into compiling with bullet3 or is it just drop it in?

beiller avatar Jul 25 '19 00:07 beiller