Good day all!, I’m having an issue with calculating the acceleration of a part aka mimicking what an Accelerometer would do. I need to check the acceleration of a part more so a rocket or even a train to be able to then use this data for a PID Controller to control various useful systems.
PID stuff etc I have that all covered but calculating what should be simple is proving very flinky and Im finding the Vector3 values returned are rapidly changing with absurd numbers.
My issue is that I calculate the Acceleration with:
local lastVelocity = script.Part.AssemblyLinearVelocity
local RunService = game["Run Service"]
RunService.Stepped:Connect(function(_, delta)
local Acceleration = (script.Part.AssemblyLinearVelocity - lastVelocity) / delta
lastVelocity = script.Part.AssemblyLinearVelocity
end)
I get values that fluctuate extremely largely and seemingly inaccurate. I’m using a PID controller to then try to maintain a specfic Acceleration of which its applying force in said direction using a VectorForce constraint.
Mainly I’m just trying to figure out if there is any better or accurate ways of calculating acceleration like an Accelerometer would. Thanks!
@kckhem Is there anyway for us to get instantaneous Acceleration without all the noise that its exposed to rendering it useless when we use: Acceleration = (currentvelocity - lastvelocity) / deltatime
Having an Acceleration value like Velocity or some sorts that just shows the Acceleration is highly useful unless there is someone to accurately replicate an Accelerometer sensor to measure Acceleration.
Having an accurate Acceleration readout would help understand the physics of vehicles etc much better than current, one would be able to use the data to develop advanced systems like Vehicle autopilot etc and develop proper braking curves etc plus character development.
Example of noisy acceleration no matter the method of lerp, smoothdamp etc:
If the script is serverside, double check if the part you’re measuring is owned by the server or client. A difference in networkownership could be causing the fluctuations.
Yeah which is client side. Im not sure one can get rid of the noise so much regardless of client or server it just reduces a bit on the client vs server.
I see, might have to attempt that or shelve it for now till there is possibly a better way to accurately calculate it with much less noise as its really needed for a PID controller
At the moment we do not provide acceleration (or force and torque) data, but I can see how it would be useful. Thanks for this suggestion, we will think about ways to expose this information.
Yep, same issue for me I need the other Axis and a stable output in that for feeding some PID controllers to then control certain systems that counter things like Dutch rolling in an aircraft. But can’t calculate the Acceleration steady enough for other axis.
local tmp0 = scoped:Tween(FOV,TweenInfo.new(0))
scoped:Hydrate(Camera) {
FieldOfView = tmp0
}
local function ChangeCameraCFrame()
Camera.CFrame = CurrentCamera.CFrame
local Acceleration = (OldVelocity-CurrentCamera.AssemblyLinearVelocity).Magnitude
OldVelocity = CurrentCamera.AssemblyLinearVelocity
FOV:set(70 * (1+Acceleration/100))
end
Before the tween I also tried using a function apart to get acceleration and then adding it but both ways it still happens the same thing.
Yeah same here, ive even tried a Kalman filter as well as a EuroFilter and both either dampen the values too far behind what is needed for the PID controller. Having the Angular Acceleration and Linear Acceleration of parts would be massive.
I havent really figured it out yet, I will get back to the project in a few weeks after rotation, but I have seen a module that is really smooth;
I should try to check out that module with my system, therefore its my physics step,
I can also try using the player character for acceleration but no idea, I will see and notify the thread