Profile image

FT turret stabilized code

15.2k SenSkysh  4.4 years ago

For cannons

Elevation

clamp((acos((cos(RollAngle) * (-sin(-PitchAngle)) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + sin(RollAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))) * sin((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(RollAngle) * cos(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))))) / (TargetDistance + rate(TargetDistance) * TargetDistance/Velocity)) - 90),negativeAngle,positiveAngle)

Heading

clamp(deltaangle(turretAngle,
atan((sin(RollAngle) * sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(RollAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))) * sin((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(-PitchAngle) * (-sin(RollAngle)) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))))) / (cos(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2)))))) + (((cos(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))))) < 0) ? (((sin(RollAngle) * sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(RollAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2))) * sin((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(-PitchAngle) * (-sin(RollAngle)) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos(((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity) + (asin((cos(TargetElevation + (rate(TargetElevation)) * TargetDistance/Velocity) * (TargetDistance + rate(TargetDistance)*TargetDistance/Velocity) * 9.81)/(Velocity * Velocity))/2)))))>0) ? 180 : -180) : 0)),negativeAngle,positiveAngle)

For guns

Elevation

clamp((acos((cos(RollAngle) * (-sin(-PitchAngle)) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + sin(RollAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)) * sin((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(RollAngle) * cos(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)))) / (TargetDistance + rate(TargetDistance) * TargetDistance/Velocity)) - 90),negativeAngle, positiveAngle)

Heading

clamp(deltaangle(turretAngle,
atan((sin(RollAngle) * sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(RollAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)) * sin((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(-PitchAngle) * (-sin(RollAngle)) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)))) / (cos(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity))))) + (((cos(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)))) < 0) ? (((sin(RollAngle) * sin(-PitchAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)) * cos((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(RollAngle) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * sin((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity)) * sin((TargetHeading - Heading + rate(TargetHeading) * TargetDistance/Velocity))) + cos(-PitchAngle) * (-sin(RollAngle)) * ((TargetDistance + rate(TargetDistance) * TargetDistance/Velocity) * cos((TargetElevation + 90 + rate(TargetElevation) * TargetDistance/Velocity))))>0) ? 180 : -180) : 0)),negativeAngle, positiveAngle)

example of a car with two turrets

Source

Elevation

clamp((acos((cos(RollAngle) * (-sin(-PitchAngle)) * (R * sin(O) * cos(F)) + sin(RollAngle) * (R * sin(O) * sin(F)) + cos(RollAngle) * cos(-PitchAngle) * (R * cos(O))) / R) - 90),negativeAngle,positiveAngle)

Heading

clamp(deltaangle(turretAngle,
atan((sin(RollAngle) * sin(-PitchAngle) * (R * sin(O) * cos(F)) + cos(RollAngle) * (R * sin(O) * sin(F)) + cos(-PitchAngle) * (-sin(RollAngle)) * (R * cos(O))) / (cos(-PitchAngle) * (R * sin(O) * cos(F)) + sin(-PitchAngle) * (R * cos(O)))) + (((cos(-PitchAngle) * (R * sin(O) * cos(F)) + sin(-PitchAngle) * (R * cos(O))) < 0) ? (((sin(RollAngle) * sin(-PitchAngle) * (R * sin(O) * cos(F)) + cos(RollAngle) * (R * sin(O) * sin(F)) + cos(-PitchAngle) * (-sin(RollAngle)) * (R * cos(O)))>0) ? 180 : -180) : 0)),negativeAngle,positiveAngle)

How it works?

It's hard to explain ... In short, a spherical coordinate system is converted to a cartesian one, multiplied by the rotation matrix and returned back
Before transfer to FT, it looked something like this

  • Log in to leave a comment
  • Profile image
    15.2k SenSkysh
    Pinned 3.3 years ago
  • Profile image
    15.2k SenSkysh

    even two
    Table two, xlsx

    Pinned 3.8 years ago
  • Profile image
    15.2k SenSkysh

    Hmm. Should have done it before - autocomplete table

    Pinned 4.2 years ago
  • Profile image
    15.2k SenSkysh

    Oh... &lt; it's <
    Sorry

    Pinned 4.3 years ago
  • Profile image

    what is turretAngle supposed to be? The difference between the vehicle heading and the way the turret is neutrally facing?

    7 months ago
  • Profile image
    3,105 Fujisan

    @ThomasRoderick

    Basically, what you guys are supposed to do with this is to make a copy of it yourselves and use it, since unlocking it for all to use exposes it to vandals and users with a lot of skill issue, myself included. Yep, that's a good solution

    1.2 years ago
  • Profile image

    @RichardScepton @SenSkysh

    Here is my personal backup of table 1.

    To make sure the table would not get damaged again through either accident or vandalism, the sheet is protected this time.

    1.3 years ago
  • Profile image
    3,105 Fujisan

    To anyone who wants to use this table:
    Unfortunately, for some unknown reason, most likely the spreadsheet itself being mangled by inexperienced users who didn't know what they were doing, the table itself was rendered offline, most likely for a long time in the future. Same applies for table 2, apparently, as it was set to read-only. However, I have found an archived copy of the second table on my PC last night as I was clearing it out, and so, I will put it below. It's all in Russian, AFAIK, but it should still suffice to fit your needs. Remember to use it properly this time or else imma have to deal with a migraine fixing it
    !link to my archived table

    @natemomog
    @SiBangsatYa

    +2 1.8 years ago
  • Profile image
    15.8k SiBangsatYa

    @SenSkysh I cant access

    2.0 years ago
  • Profile image
    29.2k natemomog

    @SenSkysh yo, I can't access the original table.

    2.5 years ago
  • Profile image
    180 EasyEight

    Thanks bruddah! Now I just need to manage how should it work with naval designs with LOTS of shooting stuff.

    2.7 years ago
  • Profile image

    This should come in handy, Thanks!

    3.1 years ago
  • Profile image
    36.6k Icey21

    I tried it. Didn't work. But probably because I had both a cannon and a machine guns.

    3.5 years ago
  • Profile image
    15.2k SenSkysh

    @OtakuNekoToT If I knew, I would post the appropriate code right away

    3.6 years ago
  • Profile image
    10.2k 416

    @SenSkysh So what should I do and how do I fix it?

    3.6 years ago
  • Profile image
    15.2k SenSkysh

    @OtakuNekoToT Maybe you're right

    3.6 years ago
  • Profile image
    10.2k 416

    @SenSkysh I forgot to tell you that this code is used for the auto targeting m102 howitzer mounted on ac-130 and the target is an aircraft carrier or any ground target that does not have fast travelling speed. Only the elevation code have this problem, which seems to be due to the bullet drop.

    3.6 years ago
  • Profile image
    15.2k SenSkysh

    @OtakuNekoToT during the flight of the projectile, the enemy has time to change the trajectory or speed. it cannot be fixed. Is it possible to increase the speed of the projectile

    3.6 years ago
  • Profile image
    10.2k 416

    @SenSkysh The elevation code for cannon works well on the ground but there's a problem. The higher altitudes and greater distance, the greater distance between hit point and target. How do I fix it?

    3.6 years ago
  • Profile image
    15.2k SenSkysh

    @Dysonchipss em?

    3.7 years ago
  • Profile image

    @SenSkysh how do we fix it then?

    3.7 years ago
  • Profile image
    15.2k SenSkysh

    @mitsuki the problem is probably in the settings of the rotator, it should rotate 1 ° for every 1 in input

    3.7 years ago
  • Profile image
    1,428 mitsuki

    I seem to have the same problem as DysonChipss, as the turret leads too much. For example: If I target a plane on my 12 o clock my turret rotates 180 degrees away from it

    3.7 years ago
  • Profile image
    15.2k SenSkysh

    @mitsuki yes, approximately

    3.7 years ago
  • Profile image
    1,428 mitsuki

    is turret x,y,z the coords of the rotator connected to the craft?

    3.7 years ago
  • Log in to see more comments