[OPEN-SOURCE] Machinery Modelling Toolkit

Hey, I have a question about the PID, how would you use it to control the pitch, roll, yaw of an aircraft. I tried to control the roll by plugging in the desired roll - current roll as error, then I used the output to control the aileron angle, it works but not for controlling pitch.

Good question. I’ve never done fly-by-wire for aircrafts. But I guess you need to build everything around “Horizont”. So when you move stick to pitch or roll, you are setting desired orientation in relation to Horizont in world space. It kind of like a directional arrow in world space. Then error is calculated in relation to that arrow not in relation to the position of the stick.
Not sure about this but I have impression that this is how WarThunder does mouse controls.

Or do you have something else in mind?

Sneak peek of things to come:

It’s an early prototype of laying track on the ground and obstacles. A bit junky and needs more work but overall principal is there - put track on the ground and various obstacles and then roll roadwheels over the track. It’s not physically accurate but an approximation which is still closer to reality than using only ray traced wheels. Nevertheless I’m not expecting this approach to work on 20+ tanks at the same time, the idea is to use this system only for “hero” tank or at very close range as the most detailed LOD level. For lower level of details, new system based on custom mesh sweeps is already in place and it’s way more stable than previous implementation that used physics constraints.

Nice!

Yes, I’m still alive… sorry for the long silence got some real world stuff to figure out.

@ : I am adding a reloading and firing mechanism. When I fire the maingun I want to apply a force to the hull in the opposite direction the gun is facing. Do you know how I can add that? I tried an addforce but cannot get it to work.

AddForceAt location is what you need and force vector should be in the world space. So it goes like this:

  1. This will be recoil vector in local space coordinates (-500000, 0, 0) meaning we want to push turret backwards by 500 000 N cm
  2. GetWorldTransform of your barrel or a turret. And do TransformDirection on Recoil vector using WorldTransform of the turret or a barrel
  3. Apply transformed recoil vector using AddForceAtLocation, provide world space coordinates of the barrel/turret to as a point where recoil should be applied

thanx, I will see if I can get that to work.

hmm… I think I’m doing something wrong… with vectors etc not being my strong point.

The force seems to come 90 degrees rotated from the direction the turret is facing. And it also depends on the world orientation of the tank… what am I missing? :smiley:

First of all your Location can’t be set to 0,0,0 as it means force is applied in the origin of the world.
Second thing to check is that your turret and barrel are oriented in X axis, not Y.

Recoil Vector can be made like this too: GunBarrel->GetForwardVector() * -RecoilPower

@ I never made the aircraft fly by wire to work. Controlling yaw is kind of confusing.

Can you explain how your sub stepping works, in numbers maybe. What are the things needed to be exposed to be able to create one in the BP, the minimum possible. BTW your substepping works great, it even works at 1fps lol.

Can I maybe create a component that has a custom tick event.

This article explains it quite well:
http://www.aclockworkberry.com/unreal-engine-substepping/
and yes you can add custom tick for physics sub-steps on component level instead of Actor/Pawn, that’s how it’s done in the article. I use Pawn to have a full control over when and in which order components are called.

For location I now use the hull location. Changed the recoil vector to what you suggested with a recoilpower variable.
But still can’t seem to control or understand where the force is comming from. It now seems to always come from the top pushing down on the tank. It’s probably because I’m such a noob with vecotrs in UE… don’t really understand a thing about them.
Probably If I can somewhere add a + rotate in 90 degree’s from the current vector I could get it to work… but don’t really know how to do that either.

I should be world space location of the barrel instead of a hull (technically it should be point where hydraulic recoil mechanism transfers some energy to turret). If it presses it down you might be using wrong vector direction. Could you post a screenshot of your barrel or turret or both as how they look like in editor? So axis in the corner is visible.

Fire recoil

@OldRaven

I’ve added example into MMT_Content, look for this tank and corresponding class name of the right:

but in case you can’t open or use it for some reason, this is the graph:

project input settings:

and this is how meshes are oriented during the import - both go along the red X axis:


I see my Turret and Barrel mesh are pointing in the Y direction. And yours is pointing in X. That should explain why my force seems to some from a different angle.

@ Hey, I get this error every tick in the output log when using your plugin on other projects(bp or c++) when using the EventPhysicsTick connected to any AddForce. No crashes and it’s working fine but the error message.

Is the plugin only allowed in the MMTContent project or do I need to change some settings to the project? I haven’t tested if the substepping works when getting this error.

LogPhysics:Error: PHYSX: (D:\Build++UE4+Release-4.13+Compile\Sync\Engine\Source\Runtime\Engine\Public\PhysXPublic.h 241) eINVALID_OPERATION : PxScene::lockWrite() detected after a PxScene::lockRead(), lock upgrading is not supported, behaviour will be undefined.
LogPhysics:Error: PHYSX: (…..\PhysX\src\NpScene.cpp 2946) eINVALID_OPERATION : PxScene::unlockWrite() called without matching call to PxScene::lockWrite(), behaviour will be undefined.

Are you using MMTAddForce or regular one? As they are different

Another thing is to make sure that you’ve enabled sub-stepping in the projects settings. Outside of that I’m not sure what else you would need to change. People used it in other than MMT project and I tested it in the plugin project itself couple of times.

I see, I didn’t enabled it on other projects.

BTW, I made my own aerodynamics system, I noticed yours uses torque for the pitching moment. Is using add force at location directly at the tail any different. Also I’ve been having a hard time finding the calculation for skin friction drag any idea how to estimate it?

Any force applied away from the center of mass will generate torque, so you can apply it as a force and not as torque, I don’t remember why I do like that :smiley:

I think skin friction drag is either already included into one of the “classical” empiric formulas of drag or it’s not as significant as other parts. Last time I’ve read literature on this is about 6 month ago, so it’s a bit blurry. To be honest, I was more occupied with the simulation of proper down-wash on wings, depended on their shape and speed. Haven’t really solved it, some good example that I’ve found where a bit too heavy on math for my skills.
I can check in the book but pure skin drag was something like a small percent of the total drag and unless you build real airplane doesn’t make sense to bother. I might be wrong and it was written about something else. Will try to check on that.