Jump to content

MAFman

Members
  • Posts

    312
  • Joined

  • Last visited

Posts posted by MAFman

  1. I created a quick ModuleManager configuration that copies the stock LES and scales it down by 50%, so I can have LES's on all my rockets, even Mk. 1 ones.

    +PART[LaunchEscapeSystem]
    {
      @name = Mk1LES
      @title = Mark 1 Launch Escape System
      @rescaleFactor = 0.5
      @cost /= 2
      @mass /= 2
      @bulkheadProfiles = size0
      @MODULE[ModuleEnginesFX]
      {
        // Tone down the thrust to deal with the decreased size
        @maxThrust /= 2
      }
      @RESOURCE[SolidFuel] {
        @amount /= 2
        @maxAmount /= 2
      }
    }

     

  2. 27 minutes ago, king of nowhere said:

    without mods, it's quite hard to make stuff sink. the best way is to put ore tanks inside a cargo bay. many ore tanks clipping into each other. this way the game does not model what's inside the bay as far as buoiancy is concerned, but it still does register the mass, which causes the rover to sink

    I'm guessing the tanks in the cargo bay should be full, right? Just to make them denser.

  3. I just rebuilt one with the Rhino engine as the second stage and two Pollux boosters, and it does make it into orbit theoretically, barely, with a 90 ton payload.

    6 minutes ago, MAFman said:

    I just rebuilt one with the Rhino engine as the second stage and two Pollux boosters, and it does make it into orbit theoretically, barely, with a 90 ton payload.

    ...or not

  4. 3 hours ago, Beamer said:

    If you build something that looks about the same in configuration and relative dimensions (everything in KSP is smaller of course, the S3 parts are only 3.75m in diameter) it will be able to lift about 95t to LKO.

    Ohhhh, so my payloads are just way too small. I was only trying to lift a 15-ton Orion spacecraft thing.

  5. Actually, I have a semi-working script already. Just, it hard-codes the kP value instead of finding it experimentally. How do I find the kP value in a PID?

    Here's my script:

    // Tune a quadcopter using electric motors
    function tuneQuad {
      clearscreen.
      core:doEvent("Open Terminal").
      print "Toggle AG1 to start tuning...".
    
      wait until ag1.
      print "Tuning...".
      sas on.
      wait 1.
    
      local kU is 6.
      local motors is list(
        ship:partsTagged("Front Left")[0]:getModule("ModuleRoboticServoRotor"),
        ship:partsTagged("Front Right")[0]:getModule("ModuleRoboticServoRotor"),
        ship:partsTagged("Rear Left")[0]:getModule("ModuleRoboticServoRotor"),
        ship:partsTagged("Rear Right")[0]:getModule("ModuleRoboticServoRotor")
      ).
    
      local pid is pidloop(kU, 0, 0, 0, 1).
      set pid:setpoint to 0.
      for m in motors {
        m:setField("RPM Limit", 460 * pid:update(time:seconds, verticalSpeed)).
      }
    
      wait until alt:radar > 500.
      local errorSign is -1.
      local flips is list().
    
      // Measure how many times the vertical speed bounces in 20 seconds
      local startTime is time:seconds.
      until time:seconds > startTime + 20 {
        if pid:error * errorSign < 0 {
          flips:add(time:seconds).
          set errorSign to -errorSign.
        }
        for m in motors {
          m:setField("RPM Limit", 460 * pid:update(time:seconds, verticalSpeed)).
        }
        wait 0.01.
      }
    
      // Calculate gains
      local total is 0.
      if flips:length > 0 for i in range(flips:length - 1, 1) {
        set total to total + (flips[i] - flips[i - 1]).
      }
    
      // Formulas taken from https://en.wikipedia.org/wiki/Ziegler%E2%80%93Nichols_method
    
      local pU is total / (flips:length - 1) * 2.
      local kP is kU * (1/3).
      local tI is 0.5 * pU.
      local tD is (1/3) * pU.
      local kI is ((2/3) * kU) / pU.
      local kD is (1/9) * kU * pU.
    
      set pid:kP to kP.
      set pid:kI to kI.
      set pid:kD to kD.
    
      print "Landing...".
      set pid:setpoint to -5.
      until alt:radar < 1 {
        for m in motors {
          m:setField("RPM Limit", 460 * pid:update(time:seconds, verticalSpeed)).
        }
      }
      for m in motors m:setField("RPM Limit", 0).
      wait 1.
      print "Exporting PID gains to file...".
      log "set kP to " + kP + ". set kI to " + kI + ". set kD to " + kD + "." to "0:/" + ship:name + "PidValues.ks".
    }
    
    // Tune a drone using jets or rockets for thrust
    function tuneJetDrone {
      clearscreen.
      core:doEvent("Open Terminal").
      print "Toggle AG1 to start tuning...".
    
      wait until ag1.
      print "Tuning...".
      sas on.
      stage.
      wait 1.
    
      local kU is 6.
    
      // Full throttle until 500 meters
      lock throttle to 1.
      wait until alt:radar > 500.
    
      local pid is pidloop(kU, 0, 0, 0, 1).
      set pid:setpoint to 0. // Target vertical speed of 0
      lock throttle to pid:update(time:seconds, verticalSpeed).
    
      // Wait for vertical speed to go negative
      wait until verticalSpeed < 0.
      local errorSign is -1.
      local flips is list().
      local err is 0.
    
      // Measure how many times the vertical speed bounces in 20 seconds
      local startTime is time:seconds.
      until time:seconds > startTime + 20 {
        set err to max(err, abs(ship:verticalSpeed)).
        if ship:verticalSpeed * errorSign < 0 {
          flips:add(time:seconds).
          set errorSign to -errorSign.
        }
        lock throttle to pid:update(time:seconds, verticalSpeed).
        wait 0.01.
      }
    
      // Calculate gains
      local total is 0.
      if flips:length > 0 for i in range(flips:length - 1, 1) {
        set total to total + (flips[i] - flips[i - 1]).
      }
    
      // Formulas taken from https://en.wikipedia.org/wiki/Ziegler%E2%80%93Nichols_method
    
      local pU is total / (flips:length - 1) * 2.
      local kP is kU * (1/3).
      local tI is 0.5 * pU.
      local tD is (1/3) * pU.
      local kI is ((2/3) * kU) / pU.
      local kD is (1/9) * kU * pU.
    
      set pid:kP to kP.
      set pid:kI to kI.
      set pid:kD to kD.
    
      print "Landing...".
      set pid:setpoint to -5.
      until alt:radar < 2 {
          lock throttle to pid:update(time:seconds, verticalSpeed).
          wait 0.01.
      }
      lock throttle to 0.
      wait 1.
      print "Exporting PID gains to file...".
      log "set kP to " + kP + ". set kI to " + kI + ". set kD to " + kD + "." to "0:/" + ship:name + "PidValues.ks".
    }
    
    local type is "".
    for p in ship:parts {
      if p:hasModule("ModuleRoboticServoRotor") set type to "quad".
      else if p:hasModule("ModuleEngine") set type to "jet".
    }
    if type = "quad" tuneQuad().
    else tuneJetDrone().

     

×
×
  • Create New...